2 * GIT - The information manager from hell
4 * Copyright (C) Linus Torvalds, 2005
8 static void show_differences(char *name
,
9 void *old_contents
, unsigned long long old_size
)
11 static char cmd
[1000];
14 snprintf(cmd
, sizeof(cmd
), "diff -L %s -u -N - %s", name
, name
);
17 fwrite(old_contents
, old_size
, 1, f
);
21 static void show_diff_empty(struct cache_entry
*ce
)
24 unsigned long int size
;
26 unsigned char type
[20], *p
, *end
;
28 old
= read_sha1_file(ce
->sha1
, type
, &size
);
33 printf("--- %s\n", ce
->name
);
34 printf("+++ /dev/null\n");
40 printf("@@ -1,%d +0,0 @@\n", lines
);
58 int main(int argc
, char **argv
)
61 int silent_on_nonexisting_files
= 0;
62 int entries
= read_cache();
65 for (i
= 1; i
< argc
; i
++) {
66 if (!strcmp(argv
[i
], "-s")) {
67 silent_on_nonexisting_files
= silent
= 1;
70 if (!strcmp(argv
[i
], "-q")) {
71 silent_on_nonexisting_files
= 1;
74 usage("show-diff [-s] [-q]");
81 for (i
= 0; i
< entries
; i
++) {
83 struct cache_entry
*ce
= active_cache
[i
];
89 if (stat(ce
->name
, &st
) < 0) {
90 if (errno
== ENOENT
&& silent_on_nonexisting_files
)
92 printf("%s: %s\n", ce
->name
, strerror(errno
));
97 changed
= cache_match_stat(ce
, &st
);
100 printf("%.*s: ", ce_namelen(ce
), ce
->name
);
101 for (n
= 0; n
< 20; n
++)
102 printf("%02x", ce
->sha1
[n
]);
108 new = read_sha1_file(ce
->sha1
, type
, &size
);
109 show_differences(ce
->name
, new, size
);