2 * GIT - The information manager from hell
4 * Copyright (C) Linus Torvalds, 2005
9 static const char *diff_files_usage =
10 "diff-files [-p] [-q] [-r] [-z] [paths...]";
12 static int generate_patch = 0;
13 static int line_termination = '\n';
14 static int silent = 0;
16 static int matches_pathspec(struct cache_entry *ce, char **spec, int cnt)
19 int namelen = ce_namelen(ce);
20 for (i = 0; i < cnt; i++) {
21 int speclen = strlen(spec[i]);
22 if (! strncmp(spec[i], ce->name, speclen) &&
24 (ce->name[speclen] == 0 ||
25 ce->name[speclen] == '/'))
31 static void show_unmerge(const char *path)
36 printf("U %s%c", path, line_termination);
39 static void show_file(int pfx, struct cache_entry *ce)
42 diff_addremove(pfx, ntohl(ce->ce_mode), ce->sha1,
45 printf("%c%06o\t%s\t%s\t%s%c",
46 pfx, ntohl(ce->ce_mode), "blob",
47 sha1_to_hex(ce->sha1), ce->name, line_termination);
50 static void show_modified(int oldmode, int mode,
51 const char *old_sha1, const char *sha1,
54 char old_sha1_hex[41];
55 strcpy(old_sha1_hex, sha1_to_hex(old_sha1));
58 diff_change(oldmode, mode, old_sha1, sha1, path, NULL);
60 printf("*%06o->%06o\tblob\t%s->%s\t%s%c",
61 oldmode, mode, old_sha1_hex, sha1_to_hex(sha1), path,
65 int main(int argc, char **argv)
67 static const char null_sha1[20] = { 0, };
68 int entries = read_cache();
71 while (1 < argc && argv[1][0] == '-') {
72 if (!strcmp(argv[1], "-p"))
74 else if (!strcmp(argv[1], "-q"))
76 else if (!strcmp(argv[1], "-r"))
78 else if (!strcmp(argv[1], "-s"))
80 else if (!strcmp(argv[1], "-z"))
83 usage(diff_files_usage);
87 /* At this point, if argc == 1, then we are doing everything.
88 * Otherwise argv[1] .. argv[argc-1] have the explicit paths.
95 for (i = 0; i < entries; i++) {
97 unsigned int oldmode, mode;
98 struct cache_entry *ce = active_cache[i];
102 ! matches_pathspec(ce, argv+1, argc-1))
106 show_unmerge(ce->name);
107 while (i < entries &&
108 !strcmp(ce->name, active_cache[i]->name))
110 i--; /* compensate for loop control increments */
114 if (stat(ce->name, &st) < 0) {
115 if (errno != ENOENT) {
124 changed = cache_match_stat(ce, &st);
128 oldmode = ntohl(ce->ce_mode);
129 mode = S_IFREG | ce_permissions(st.st_mode);
131 show_modified(oldmode, mode, ce->sha1, null_sha1,