2 * GIT - The information manager from hell
4 * Copyright (C) Linus Torvalds, 2005
9 static const char *show_diff_usage = "show-diff [-q] [-s] [-z] [paths...]";
11 static int matches_pathspec(struct cache_entry *ce, char **spec, int cnt)
14 int namelen = ce_namelen(ce);
15 for (i = 0; i < cnt; i++) {
16 int speclen = strlen(spec[i]);
17 if (! strncmp(spec[i], ce->name, speclen) &&
19 (ce->name[speclen] == 0 ||
20 ce->name[speclen] == '/'))
26 int main(int argc, char **argv)
29 int silent_on_nonexisting_files = 0;
30 int machine_readable = 0;
32 int entries = read_cache();
35 while (1 < argc && argv[1][0] == '-') {
36 if (!strcmp(argv[1], "-R"))
38 else if (!strcmp(argv[1], "-s"))
39 silent_on_nonexisting_files = silent = 1;
40 else if (!strcmp(argv[1], "-q"))
41 silent_on_nonexisting_files = 1;
42 else if (!strcmp(argv[1], "-z"))
45 usage(show_diff_usage);
49 /* At this point, if argc == 1, then we are doing everything.
50 * Otherwise argv[1] .. argv[argc-1] have the explicit paths.
57 for (i = 0; i < entries; i++) {
59 struct cache_entry *ce = active_cache[i];
66 ! matches_pathspec(ce, argv+1, argc-1))
71 printf("U %s%c", ce->name, 0);
73 printf("%s: Unmerged\n",
76 !strcmp(ce->name, active_cache[i]->name))
78 i--; /* compensate for loop control increments */
82 if (stat(ce->name, &st) < 0) {
83 if (errno == ENOENT && silent_on_nonexisting_files)
86 printf("X %s%c", ce->name, 0);
88 printf("%s: %s\n", ce->name, strerror(errno));
90 show_diff_empty(ce->sha1, ce->name,
95 changed = cache_match_stat(ce, &st);
98 if (!machine_readable)
99 printf("%s: %s\n", ce->name, sha1_to_hex(ce->sha1));
101 printf("%s %s%c", sha1_to_hex(ce->sha1), ce->name, 0);
107 old = read_sha1_file(ce->sha1, type, &size);
109 error("unable to read blob object for %s (%s)",
110 ce->name, sha1_to_hex(ce->sha1));
112 show_differences(ce->name, ce->name, old, size,