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] [-R] [-B] [-M] [-C] [--find-copies-harder] [-O<orderfile>] [-S<string>] [--pickaxe-all] [<path>...]";
12 static int diff_output_format = DIFF_FORMAT_HUMAN;
13 static int detect_rename = 0;
14 static int find_copies_harder = 0;
15 static int diff_setup_opt = 0;
16 static int diff_score_opt = 0;
17 static const char *pickaxe = NULL;
18 static int pickaxe_opts = 0;
19 static int diff_break_opt = -1;
20 static const char *orderfile = NULL;
21 static const char *diff_filter = NULL;
22 static int silent = 0;
24 static void show_unmerge(const char *path)
29 static void show_file(int pfx, struct cache_entry *ce)
31 diff_addremove(pfx, ntohl(ce->ce_mode), ce->sha1, ce->name, NULL);
34 static void show_modified(int oldmode, int mode,
35 const unsigned char *old_sha1, const unsigned char *sha1,
38 diff_change(oldmode, mode, old_sha1, sha1, path, NULL);
41 int main(int argc, const char **argv)
43 static const unsigned char null_sha1[20] = { 0, };
44 int entries = read_cache();
47 while (1 < argc && argv[1][0] == '-') {
48 if (!strcmp(argv[1], "-p") || !strcmp(argv[1], "-u"))
49 diff_output_format = DIFF_FORMAT_PATCH;
50 else if (!strcmp(argv[1], "-q"))
52 else if (!strcmp(argv[1], "-r"))
54 else if (!strcmp(argv[1], "-s"))
56 else if (!strcmp(argv[1], "-z"))
57 diff_output_format = DIFF_FORMAT_MACHINE;
58 else if (!strcmp(argv[1], "--name-only"))
59 diff_output_format = DIFF_FORMAT_NAME;
60 else if (!strcmp(argv[1], "--name-only-z"))
61 diff_output_format = DIFF_FORMAT_NAME_Z;
62 else if (!strcmp(argv[1], "-R"))
63 diff_setup_opt |= DIFF_SETUP_REVERSE;
64 else if (!strncmp(argv[1], "-S", 2))
65 pickaxe = argv[1] + 2;
66 else if (!strncmp(argv[1], "-O", 2))
67 orderfile = argv[1] + 2;
68 else if (!strncmp(argv[1], "--diff-filter=", 14))
69 diff_filter = argv[1] + 14;
70 else if (!strcmp(argv[1], "--pickaxe-all"))
71 pickaxe_opts = DIFF_PICKAXE_ALL;
72 else if (!strncmp(argv[1], "-B", 2)) {
74 diff_scoreopt_parse(argv[1])) == -1)
75 usage(diff_files_usage);
77 else if (!strncmp(argv[1], "-M", 2)) {
79 diff_scoreopt_parse(argv[1])) == -1)
80 usage(diff_files_usage);
81 detect_rename = DIFF_DETECT_RENAME;
83 else if (!strncmp(argv[1], "-C", 2)) {
85 diff_scoreopt_parse(argv[1])) == -1)
86 usage(diff_files_usage);
87 detect_rename = DIFF_DETECT_COPY;
89 else if (!strcmp(argv[1], "--find-copies-harder"))
90 find_copies_harder = 1;
92 usage(diff_files_usage);
96 if (find_copies_harder && detect_rename != DIFF_DETECT_COPY)
97 usage(diff_files_usage);
99 /* At this point, if argc == 1, then we are doing everything.
100 * Otherwise argv[1] .. argv[argc-1] have the explicit paths.
103 perror("read_cache");
107 diff_setup(diff_setup_opt);
109 for (i = 0; i < entries; i++) {
111 unsigned int oldmode;
112 struct cache_entry *ce = active_cache[i];
116 show_unmerge(ce->name);
117 while (i < entries &&
118 !strcmp(ce->name, active_cache[i]->name))
120 i--; /* compensate for loop control increments */
124 if (lstat(ce->name, &st) < 0) {
125 if (errno != ENOENT && errno != ENOTDIR) {
134 changed = ce_match_stat(ce, &st);
135 if (!changed && !find_copies_harder)
137 oldmode = ntohl(ce->ce_mode);
138 show_modified(oldmode, DIFF_FILE_CANON_MODE(st.st_mode),
139 ce->sha1, (changed ? null_sha1 : ce->sha1),
142 diffcore_std((1 < argc) ? argv + 1 : NULL,
143 detect_rename, diff_score_opt,
144 pickaxe, pickaxe_opts,
146 orderfile, diff_filter);
147 diff_flush(diff_output_format);