---
# System prepended metadata

title: gix status

---

# gix status


## Resources


* https://github.blog/2022-06-29-improve-git-monorepo-performance-with-a-file-system-monitor/
   - a good primer
* https://github.com/romkatv/gitstatus#single-threaded-scan
   - how to make git status 10x faster
* https://github.com/BurntSushi/walkdir/issues/23
   - `openat` for `Walkdir` isn't straightforward, but possible
* https://github.com/BurntSushi/walkdir/issues/120
   - `WalkDir` - can it use `openat`?


## Notes

* relevant for cargo integration (`cargo publish` detects dirty files)

* git procedure
    * find changes on disk by comparing disk => index
    * find changes between index and HEAD with tree diff (fast)


* standard optimizations: use mtime
    * should be optional (mtime can be unreliable in VM), but enabled by default (since git 2.1)
    * saves mtime in index => doesn't work for untracked files
    * improvment: untracked cache
        * we must scan untracked files anyway
        * compare mtime of directories before transversal to avoid scanning them

* untracked cache is VERY interesting for helix in general
    * file transversal for global search and file picker are frequent => always use the untracked cache + index
    * potentially save index withotu a repo?
* would be nice to make the status functionality pluggable so we can show changed but unsaved buffers as modified
* most advanced option: fsmonitor
    * use watchmen (great implementation very hard to beat) has good/offical rust integration
    * probably reserve for future work
    * very optional (requires external deamon to be running in background)
    * potentially good option for helix in the distant future as we want watchmen integration anyway

* usability features:
    * move detection (compute diff if more then 50% of a removed and added file are identical it's a move)


## Stages

* **determine unstaged changes**
   - changes between worktree and index
   - needs one stat call per file one way or another.
   - *Question*: what's faster: `walkdir` or `symlink_metadata` per index entry? Note that `walkdir` doesn't use ``
* **determine staged changes**
  - compare tree entries with index entries
  - *Question*: is there a way to avoid having to traverse a tree recursively? Yes, use the `TREE` extension to know the dir ids of all entries, which allows to reproduce the trees and see if they changed, and only if so we lookup the tree itself.
* **find untracked files**
  - can use `untracked-cache` to be faster. Could be coming 'for free' if walkdir would be used