2 * GIT - The information manager from hell
4 * Copyright (C) Linus Torvalds, 2005
9 static const char *diff_files_usage =
10 "git-diff-files [-p] [-q] [-r] [-z] [-M] [-C] [-R] [-S<string>] [paths...]";
12 static int diff_output_format = DIFF_FORMAT_HUMAN;
13 static int detect_rename = 0;
14 static int reverse_diff = 0;
15 static int diff_score_opt = 0;
16 static const char *pickaxe = NULL;
17 static int silent = 0;
19 static int matches_pathspec(struct cache_entry *ce, char **spec, int cnt)
22 int namelen = ce_namelen(ce);
23 for (i = 0; i < cnt; i++) {
24 int speclen = strlen(spec[i]);
25 if (! strncmp(spec[i], ce->name, speclen) &&
27 (ce->name[speclen] == 0 ||
28 ce->name[speclen] == '/'))
34 static void show_unmerge(const char *path)
39 static void show_file(int pfx, struct cache_entry *ce)
41 diff_addremove(pfx, ntohl(ce->ce_mode), ce->sha1, ce->name, NULL);
44 static void show_modified(int oldmode, int mode,
45 const unsigned char *old_sha1, const unsigned char *sha1,
48 diff_change(oldmode, mode, old_sha1, sha1, path, NULL);
51 int main(int argc, char **argv)
53 static const unsigned char null_sha1[20] = { 0, };
54 int entries = read_cache();
57 while (1 < argc && argv[1][0] == '-') {
58 if (!strcmp(argv[1], "-p"))
59 diff_output_format = DIFF_FORMAT_PATCH;
60 else if (!strcmp(argv[1], "-q"))
62 else if (!strcmp(argv[1], "-r"))
64 else if (!strcmp(argv[1], "-s"))
66 else if (!strcmp(argv[1], "-z"))
67 diff_output_format = DIFF_FORMAT_MACHINE;
68 else if (!strcmp(argv[1], "-R"))
70 else if (!strcmp(argv[1], "-S"))
71 pickaxe = argv[1] + 2;
72 else if (!strncmp(argv[1], "-M", 2)) {
73 diff_score_opt = diff_scoreopt_parse(argv[1]);
76 else if (!strncmp(argv[1], "-C", 2)) {
77 diff_score_opt = diff_scoreopt_parse(argv[1]);
81 usage(diff_files_usage);
85 /* At this point, if argc == 1, then we are doing everything.
86 * Otherwise argv[1] .. argv[argc-1] have the explicit paths.
93 diff_setup(reverse_diff, diff_output_format);
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 (lstat(ce->name, &st) < 0) {
115 if (errno != ENOENT && errno != ENOTDIR) {
124 changed = ce_match_stat(ce, &st);
125 if (!changed && detect_rename < 2)
128 oldmode = ntohl(ce->ce_mode);
129 mode = (S_ISLNK(st.st_mode) ? S_IFLNK :
130 S_IFREG | ce_permissions(st.st_mode));
132 show_modified(oldmode, mode, ce->sha1, null_sha1,
136 diff_detect_rename(detect_rename, diff_score_opt);
138 diff_pickaxe(pickaxe);