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 diff_setup_opt = 0;
15 static int diff_score_opt = 0;
16 static const char *pickaxe = NULL;
17 static int pickaxe_opts = 0;
18 static int diff_break_opt = -1;
19 static const char *orderfile = NULL;
20 static int silent = 0;
22 static void show_unmerge(const char *path)
27 static void show_file(int pfx, struct cache_entry *ce)
29 diff_addremove(pfx, ntohl(ce->ce_mode), ce->sha1, ce->name, NULL);
32 static void show_modified(int oldmode, int mode,
33 const unsigned char *old_sha1, const unsigned char *sha1,
36 diff_change(oldmode, mode, old_sha1, sha1, path, NULL);
39 int main(int argc, const char **argv)
41 static const unsigned char null_sha1[20] = { 0, };
42 int entries = read_cache();
45 while (1 < argc && argv[1][0] == '-') {
46 if (!strcmp(argv[1], "-p"))
47 diff_output_format = DIFF_FORMAT_PATCH;
48 else if (!strcmp(argv[1], "-q"))
50 else if (!strcmp(argv[1], "-r"))
52 else if (!strcmp(argv[1], "-s"))
54 else if (!strcmp(argv[1], "-z"))
55 diff_output_format = DIFF_FORMAT_MACHINE;
56 else if (!strcmp(argv[1], "-R"))
57 diff_setup_opt |= DIFF_SETUP_REVERSE;
58 else if (!strncmp(argv[1], "-S", 2))
59 pickaxe = argv[1] + 2;
60 else if (!strncmp(argv[1], "-O", 2))
61 orderfile = argv[1] + 2;
62 else if (!strcmp(argv[1], "--pickaxe-all"))
63 pickaxe_opts = DIFF_PICKAXE_ALL;
64 else if (!strncmp(argv[1], "-B", 2))
65 diff_break_opt = diff_scoreopt_parse(argv[1]);
66 else if (!strncmp(argv[1], "-M", 2)) {
67 diff_score_opt = diff_scoreopt_parse(argv[1]);
68 detect_rename = DIFF_DETECT_RENAME;
70 else if (!strncmp(argv[1], "-C", 2)) {
71 diff_score_opt = diff_scoreopt_parse(argv[1]);
72 detect_rename = DIFF_DETECT_COPY;
75 usage(diff_files_usage);
79 /* At this point, if argc == 1, then we are doing everything.
80 * Otherwise argv[1] .. argv[argc-1] have the explicit paths.
87 diff_setup(diff_setup_opt);
89 for (i = 0; i < entries; i++) {
91 unsigned int oldmode, mode;
92 struct cache_entry *ce = active_cache[i];
96 show_unmerge(ce->name);
98 !strcmp(ce->name, active_cache[i]->name))
100 i--; /* compensate for loop control increments */
104 if (lstat(ce->name, &st) < 0) {
105 if (errno != ENOENT && errno != ENOTDIR) {
114 changed = ce_match_stat(ce, &st);
115 if (!changed && detect_rename < DIFF_DETECT_COPY)
118 oldmode = ntohl(ce->ce_mode);
119 mode = (S_ISLNK(st.st_mode) ? S_IFLNK :
120 S_IFREG | ce_permissions(st.st_mode));
122 show_modified(oldmode, mode, ce->sha1, null_sha1,
125 diffcore_std((1 < argc) ? argv + 1 : NULL,
126 detect_rename, diff_score_opt,
127 pickaxe, pickaxe_opts,
130 diff_flush(diff_output_format, 1);