Show modified files in git-ls-files
PATCH 1/1 Show modified files in git-ls-files
Add -m/--modified to show files that have been modified wrt. the index.
M was already taken so the tag for modifified files is C (changed).
$ git-ls-files -m -t C Documentation/git-ls-files.txt C ls-files.c
---
Documentation/git-ls-files.txt | 4 ++++ ls-files.c | 20 +++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-)
Subject: [PATCH] Show modified files in git-ls-files
Add -m/--modified to show files that have been modified wrt. the index.
M was already taken so the tag for modifified files is C (changed).
$ git-ls-files -m -t C Documentation/git-ls-files.txt C ls-files.c
---
Documentation/git-ls-files.txt | 4 ++++ ls-files.c | 20 +++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-)
9de83ef7cce7ed5c1aa129cf2a81f8bce3aedb4f
Documentation/git-ls-files.txt +4 -0
@@ -33,6 +33,9 @@ OPTIONS -d|--deleted:: Show deleted files in the output +-m|--modified:: + Show modified files in the output + -o|--others:: Show other files in the output
@@ -71,6 +74,7 @@ OPTIONS H cached M unmerged R removed/deleted + C modifed (changed) K to be killed ? other
ls-files.c +15 -5
@@ -17,6 +17,7 @@ static int show_ignored = 0;static int show_stage =0 ;static int show_unmerged =0 ;static int show_killed =0 ; +static int show_modified =0 ;static int line_terminator ='\n' ;static int prefix_len =0 , prefix_offset =0 ;
@@ -26,6 +27,7 @@ static const char **pathspec = NULL;static const char *tag_cached ="" ;static const char *tag_unmerged ="" ;static const char *tag_removed ="" ; +static const char *tag_modified ="" ;static const char *tag_other ="" ;static const char *tag_killed ="" ;
@@ -443,15 +445,18 @@ static void show_files(void)show_ce_entry (ce_stage (ce) ? tag_unmerged : tag_cached, ce); } } -if (show_deleted) { +if (show_deleted | show_modified) {for (i =0 ; i < active_nr; i++) {struct cache_entry *ce = active_cache[i];struct stat st; +int err;if (excluded (ce->name) != show_ignored)continue ; -if (!lstat (ce->name, &st)) -continue ; -show_ce_entry (tag_removed, ce); + err =lstat (ce->name, &st); +if (show_deleted && err) +show_ce_entry (tag_removed, ce); +if (show_modified &&ce_match_stat (ce, &st)) +show_ce_entry (tag_modified, ce); } } }
@@ -547,6 +552,7 @@ int main(int argc, char **argv) tag_cached ="H " ; tag_unmerged ="M " ; tag_removed ="R " ; + tag_modified ="C " ; tag_other ="? " ; tag_killed ="K " ;continue ;
@@ -559,6 +565,10 @@ int main(int argc, char **argv) show_deleted =1 ;continue ; } +if (!strcmp (arg,"-m" ) || !strcmp (arg,"--modified" )) { + show_modified =1 ; +continue ; + }if (!strcmp (arg,"-o" ) || !strcmp (arg,"--others" )) { show_others =1 ;continue ;
@@ -630,7 +640,7 @@ int main(int argc, char **argv) }/* With no flags, we default to showing the cached files */ -if (!(show_stage | show_deleted | show_others | show_unmerged | show_killed)) +if (!(show_stage | show_deleted | show_others | show_unmerged | show_killed | show_modified)) show_cached =1 ;read_cache ();
Quoted 3 lines · Brian Gerst
Add -m/--modified to show files that have been modified wrt. the index.
M was already taken so the tag for modifified files is C (changed).
I think git-ls-files should be consistent with git-diff-cache where M means modified and U unmerged (but for the former, M is unmerged).
StGIT currently uses C to report a merge conflict but I will probably change this since it means copied in git-diff-cache.
Signature · 1 line
Catalin
Quoted 10 lines · Catalin Marinas
Quoted 3 lines · Brian Gerst
Add -m/--modified to show files that have been modified wrt. the index.
M was already taken so the tag for modifified files is C (changed).
I think git-ls-files should be consistent with git-diff-cache where M means modified and U unmerged (but for the former, M is unmerged).
StGIT currently uses C to report a merge conflict but I will probably change this since it means copied in git-diff-cache.
I think that is an excellent suggestion. It looks to me that the tag feature in ls-files needs serious renaming.
* an option is called --deleted and the variable to control the output is show_deleted; the tag variable and string is removed and "R". Probably the tag should be renamed to "D".
* before "modified", tag_cached was OK, but probably "known to git" would have been a better name. I'd vote for just a single space " " as the tag letter; if we want to use printing character, then a single dot ".". Most of the things are "known to git" anyway so these are visually less distracting.
* unmerged should be "U" as you say.
Quoted 23 lines · Junio C Hamano
Quoted 11 lines · Catalin Marinas
Quoted 3 lines · Brian Gerst
Add -m/--modified to show files that have been modified wrt. the index.
M was already taken so the tag for modifified files is C (changed).
I think git-ls-files should be consistent with git-diff-cache where M means modified and U unmerged (but for the former, M is unmerged).
StGIT currently uses C to report a merge conflict but I will probably change this since it means copied in git-diff-cache.
I think that is an excellent suggestion. It looks to me that the tag feature in ls-files needs serious renaming.
* an option is called --deleted and the variable to control the output is
show_deleted; the tag variable and string is removed and "R". Probably the tag should be renamed to "D".
Quoted 6 lines
* before "modified",
tag_cachedwas OK, but probably "known to git" would have been a better name. I'd vote for just a single space " " as the tag letter; if we want to use printing character, then a single dot ".". Most of the things are "known to git" anyway so these are visually less distracting.
It should have some character, so the output is parseable by other scripts.
Quoted 1 line
* unmerged should be "U" as you say.
I agree that the tags should be renamed. I just didn't want to break other scripts which depend on those tags.
--
Brian Gerst