List files with unstaged changes
See original GitHub issueI’m trying to figure out how to retrieve a list of files that have been modified, similar to the git status
command. My current approach uses git.listFiles
to get the list of all files known to the repository, and then calling git.status
on every single file. Although this works, it is very slow compared to the native git status
implementation, which returns the results much much faster. Plugging in my own file system implementation, I can see that for every git.status
call on a file, there is a readFile .git/index
, followed by lstat path/to/file/in/repo
followed by readFile path/to/file/in/repo
.
I think the bottleneck is that every file is read from the filesystem, not sure if that’s a bug, because I can see in the git.status
code that it should only read the file if the attributes returned by the lstat
command have changed.
Another bottleneck is that the index file is being read with every single git.status
request to a file, which could be avoided if the initial index was cached and re-used for subsequent git.status
calls.
Are there any plans to add an API for this feature, or any hints on how I can optimise my current routine?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top GitHub Comments
Is https://isomorphic-git.org/docs/en/faq#how-to-add-all-untracked-files-with-gitadd outdated now that there is https://isomorphic-git.org/docs/en/statusMatrix#q-what-files-have-unstaged-changes ?
See if the new statusMatrix command works for you. I included an example of how to solve for “What files have unstaged changes?” in the docs.