git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Add -u option to diff-cache to show UNCHANGED files

From
AGAndreas Gal <gal@uci.edu>
Date
Apr 24, 2005, 03:28 UTC
Message-ID
<Pine.LNX.4.58.0504232022180.4690@sam.ics.uci.edu>
In-Reply-To
<Pine.LNX.4.58.0504231906110.2344@ppc970.osdl.org>

With -u diff-cache shows unchanged files, instead of files that changed. This is useful to implement a "git clean" command that throws away all checked out files that have not changed (yes, I really would like to have that). One could also do show-files and then substract the diff-cache output from it, but thats slow and clumsy.

Signed-off-by: Andreas Gal <gal@uci.edu>

--- b407d753e520fa0b1523d770d98b3015af197275/diff-cache.c +++ diff-cache.c

@@ -2,6 +2,7 @@
 
 static int cached_only = 0;
 static int line_termination = '\n';
+static int show_unchanged = 0;
 
 /* A file entry went away or appeared */
 static void show_file(const char *prefix, struct cache_entry *ce)
@@ -32,7 +33,7 @@
 	}
 
 	oldmode = ntohl(old->ce_mode);
-	if (mode == oldmode && !memcmp(sha1, old->sha1, 20))
+	if ((mode == oldmode && !memcmp(sha1, old->sha1, 20)) != show_unchanged)
 		return 0;
 
 	strcpy(old_sha1_hex, sha1_to_hex(old->sha1));
@@ -85,7 +86,7 @@
 	}
 }
 
-static char *diff_cache_usage = "diff-cache [-r] [-z] [--cached] <tree sha1>";
+static char *diff_cache_usage = "diff-cache [-r] [-u] [-z] [--cached] <tree sha1>";
 
 int main(int argc, char **argv)
 {
@@ -102,6 +103,10 @@
 			/* We accept the -r flag just to look like diff-tree */
 			continue;
 		}
+		if (!strcmp(arg, "-u")) {
+			show_unchanged = 1;
+			continue;
+		}
 		if (!strcmp(arg, "-z")) {
 			line_termination = '\0';
 			continue;
Previous: Daniel BarkalowNext: Petr Baudis
Message 7 of 12 in “Better merge-base, alternative transport programs”
  1. 0/5 Better merge-base, alternative transport programsDaniel Barkalow, Apr 24, 2005
  2. 1/5 Add some functions for commit listsDaniel Barkalow, Apr 24, 2005
  3. Linus TorvaldsApr 24, 2005
  4. Linus TorvaldsApr 24, 2005
  5. Daniel BarkalowApr 24, 2005
  6. Allow multiple date-ordered listsDaniel Barkalow, Apr 24, 2005
  7. Add -u option to diff-cache to show UNCHANGED filesAndreas Gal, Apr 24, 2005
  8. Petr BaudisApr 24, 2005
  9. 2/5 Parse tree objects completelyDaniel Barkalow, Apr 24, 2005
  10. 3/5 Additional functions for the objects databaseDaniel Barkalow, Apr 24, 2005
  11. 4/5 Replace merge-base implementationDaniel Barkalow, Apr 24, 2005
  12. 5/5 Various transport programsDaniel Barkalow, Apr 24, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.