X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=show-diff.c;h=1286dd1217582df17df629413f781010bc41f314;hb=aa1c48df8172f844455cc12f25aa49be8ffdd828;hp=9f82c05602b6a94218d50b62a2481cf8a4ece749;hpb=c0fb976aa779c508314305f309f240fa6bfc3128;p=git.git diff --git a/show-diff.c b/show-diff.c index 9f82c056..1286dd12 100644 --- a/show-diff.c +++ b/show-diff.c @@ -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]; @@ -31,9 +31,9 @@ static void show_diff_empty(struct cache_entry *ce) int c = 0; printf("--- %s\n", ce->name); - 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; @@ -57,9 +57,18 @@ static void show_diff_empty(struct cache_entry *ce) int main(int argc, char **argv) { + int silent = 0; int entries = read_cache(); int i; + while (argc-- > 1) { + if (!strcmp(argv[1], "-s")) { + silent = 1; + continue; + } + usage("show-diff [-s]"); + } + if (entries < 0) { perror("read_cache"); exit(1); @@ -74,7 +83,7 @@ int main(int argc, char **argv) if (stat(ce->name, &st) < 0) { printf("%s: %s\n", ce->name, strerror(errno)); - if (errno == ENOENT) + if (errno == ENOENT && !silent) show_diff_empty(ce); continue; } @@ -86,6 +95,9 @@ int main(int argc, char **argv) printf("%02x", ce->sha1[n]); printf("\n"); fflush(stdout); + if (silent) + continue; + new = read_sha1_file(ce->sha1, type, &size); show_differences(ce->name, new, size); free(new);