From: Andreas Gal Date: Sun, 24 Apr 2005 03:28:17 GMT Subject: [PATCH] Add -u option to diff-cache to show UNCHANGED files Message-ID: In-Reply-To: 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 --- 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] "; +static char *diff_cache_usage = "diff-cache [-r] [-u] [-z] [--cached] "; 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;