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];
63 ! matches_pathspec(ce, argv+1, argc-1))
68 printf("U %s%c", ce->name, 0);
70 printf("%s: Unmerged\n",
73 !strcmp(ce->name, active_cache[i]->name))
75 i--; /* compensate for loop control increments */
79 if (stat(ce->name, &st) < 0) {
80 if (errno == ENOENT && silent_on_nonexisting_files)
83 printf("X %s%c", ce->name, 0);
85 printf("%s: %s\n", ce->name, strerror(errno));
87 show_diff_empty(ce, reverse);
91 changed = cache_match_stat(ce, &st);
94 if (!machine_readable)
95 printf("%s: %s\n", ce->name, sha1_to_hex(ce->sha1));
97 printf("%s %s%c", sha1_to_hex(ce->sha1), ce->name, 0);
103 show_differences(ce, reverse);