[PATCH] Un unoptimize ls-tree behaviour
[git.git] / show-diff.c
index 21c9045..6f343c5 100644 (file)
@@ -5,7 +5,7 @@
  */
 #include "cache.h"
 
-static void show_differences(char *name, 
+static void show_differences(char *name,
        void *old_contents, unsigned long long old_size)
 {
        static char cmd[1000];
@@ -33,7 +33,7 @@ static void show_diff_empty(struct cache_entry *ce)
                printf("--- %s\n", ce->name);
                printf("+++ /dev/null\n");
                p = old;
-               end = old + size; 
+               end = old + size;
                while (p < end)
                        if (*p++ == '\n')
                                lines ++;
@@ -44,7 +44,7 @@ static void show_diff_empty(struct cache_entry *ce)
                        if (startline) {
                                putchar('-');
                                startline = 0;
-                       } 
+                       }
                        putchar(c);
                        if (c == '\n')
                                startline = 1;
@@ -58,15 +58,20 @@ static void show_diff_empty(struct cache_entry *ce)
 int main(int argc, char **argv)
 {
        int silent = 0;
+       int silent_on_nonexisting_files = 0;
        int entries = read_cache();
        int i;
 
-       while (argc-- > 1) {
-               if (!strcmp(argv[1], "-s")) {
-                       silent = 1;
+       for (i = 1; i < argc; i++) {
+               if (!strcmp(argv[i], "-s")) {
+                       silent_on_nonexisting_files = silent = 1;
                        continue;
                }
-               usage("show-diff [-s]");
+               if (!strcmp(argv[i], "-q")) {
+                       silent_on_nonexisting_files = 1;
+                       continue;
+               }
+               usage("show-diff [-s] [-q]");
        }
 
        if (entries < 0) {
@@ -82,15 +87,17 @@ int main(int argc, char **argv)
                void *new;
 
                if (stat(ce->name, &st) < 0) {
+                       if (errno == ENOENT && silent_on_nonexisting_files)
+                               continue;
                        printf("%s: %s\n", ce->name, strerror(errno));
-                       if (errno == ENOENT && !silent)
+                       if (errno == ENOENT)
                                show_diff_empty(ce);
                        continue;
                }
                changed = cache_match_stat(ce, &st);
                if (!changed)
                        continue;
-               printf("%.*s:  ", ce->namelen, ce->name);
+               printf("%s:  ", ce->name);
                for (n = 0; n < 20; n++)
                        printf("%02x", ce->sha1[n]);
                printf("\n");