threads / patch / 1711

patchShow modified files in git-ls-files

Subject: [PATCH] Show modified files in git-ls-files

## tl;dr

4 messages between Sep 2, 2005 and Sep 2, 2005. Diffs are folded; open one to read it.

replies: 3people: 3as markdown or json

Brian Gerst· Sep 2, 2005, 00:35 UTC · lore
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

Signed-off-by: Brian Gerst <bgerst@didntduck.org>
---
  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

Signed-off-by: Brian Gerst <bgerst@didntduck.org>
---
 Documentation/git-ls-files.txt |    4 ++++
 ls-files.c                     |   20 +++++++++++++++-----
 2 files changed, 19 insertions(+), 5 deletions(-)
9de83ef7cce7ed5c1aa129cf2a81f8bce3aedb4f
Show changes to 2 files +19 −5

Documentation/git-ls-files.txt, ls-files.c

diff --git a/Documentation/git-ls-files.txt b/Documentation/git-ls-files.txt
--- a/Documentation/git-ls-files.txt
+++ b/Documentation/git-ls-files.txt
@@ -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
 
diff --git a/ls-files.c b/ls-files.c
--- a/ls-files.c
+++ b/ls-files.c
@@ -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();
Catalin Marinas· Sep 2, 2005, 09:04 UTC · re: Brian Gerst · lore

Re: [PATCH] Show modified files in git-ls-files

Brian Gerst <bgerst@didntduck.org> wrote:
> 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.

-- 
Catalin
Junio C Hamano· Sep 2, 2005, 09:28 UTC · re: Catalin Marinas · lore

Re: [PATCH] Show modified files in git-ls-files

Catalin Marinas <catalin.marinas@gmail.com> writes:
Show 10 quoted lines
> Brian Gerst <bgerst@didntduck.org> wrote:
>> 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.
Brian Gerst· Sep 2, 2005, 12:17 UTC · re: Junio C Hamano · lore

Re: [PATCH] Show modified files in git-ls-files

Junio C Hamano wrote:
Show 29 quoted lines
> Catalin Marinas <catalin.marinas@gmail.com> writes:
> 
> 
>>Brian Gerst <bgerst@didntduck.org> wrote:
>>
>>>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.
It should have some character, so the output is parseable by other scripts.
>  * 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

← back to recent threads