[PATCH] Add --pickaxe-all to diff-* brothers.
[git/git.git] / diff-files.c
CommitLineData
8bc9a0c7
LT
1/*
2 * GIT - The information manager from hell
3 *
4 * Copyright (C) Linus Torvalds, 2005
5 */
e83c5163 6#include "cache.h"
4a6bf9e1 7#include "diff.h"
c0fb976a 8
17710391 9static const char *diff_files_usage =
52e95789 10"git-diff-files [-p] [-q] [-r] [-z] [-M] [-C] [-R] [-S<string>] [paths...]";
b8f80925 11
81e50eab 12static int diff_output_format = DIFF_FORMAT_HUMAN;
5c97558c 13static int detect_rename = 0;
19feebc8 14static int diff_setup_opt = 0;
57fe64a4 15static int diff_score_opt = 0;
057c7d30 16static const char *pickaxe = NULL;
367cec1c 17static int pickaxe_opts = 0;
0a7668e9 18static int silent = 0;
0a7668e9 19
4a6bf9e1 20static void show_unmerge(const char *path)
0a7668e9 21{
57fe64a4 22 diff_unmerge(path);
4a6bf9e1
JH
23}
24
25static void show_file(int pfx, struct cache_entry *ce)
26{
57fe64a4 27 diff_addremove(pfx, ntohl(ce->ce_mode), ce->sha1, ce->name, NULL);
4a6bf9e1
JH
28}
29
30static void show_modified(int oldmode, int mode,
bf0f910d 31 const unsigned char *old_sha1, const unsigned char *sha1,
4a6bf9e1
JH
32 char *path)
33{
57fe64a4 34 diff_change(oldmode, mode, old_sha1, sha1, path, NULL);
0a7668e9
LT
35}
36
6b14d7fa 37int main(int argc, const char **argv)
e83c5163 38{
bf0f910d 39 static const unsigned char null_sha1[20] = { 0, };
e83c5163
LT
40 int entries = read_cache();
41 int i;
42
b8f80925 43 while (1 < argc && argv[1][0] == '-') {
d15aa430 44 if (!strcmp(argv[1], "-p"))
81e50eab 45 diff_output_format = DIFF_FORMAT_PATCH;
b8f80925 46 else if (!strcmp(argv[1], "-q"))
d15aa430 47 silent = 1;
0a7668e9 48 else if (!strcmp(argv[1], "-r"))
4a6bf9e1 49 ; /* no-op */
d15aa430
JH
50 else if (!strcmp(argv[1], "-s"))
51 ; /* no-op */
52 else if (!strcmp(argv[1], "-z"))
81e50eab 53 diff_output_format = DIFF_FORMAT_MACHINE;
57fe64a4 54 else if (!strcmp(argv[1], "-R"))
19feebc8 55 diff_setup_opt |= DIFF_SETUP_REVERSE;
52e95789
JH
56 else if (!strcmp(argv[1], "-S"))
57 pickaxe = argv[1] + 2;
367cec1c
JH
58 else if (!strcmp(argv[1], "--pickaxe-all"))
59 pickaxe_opts = DIFF_PICKAXE_ALL;
57fe64a4
JH
60 else if (!strncmp(argv[1], "-M", 2)) {
61 diff_score_opt = diff_scoreopt_parse(argv[1]);
6b14d7fa 62 detect_rename = DIFF_DETECT_RENAME;
5c97558c 63 }
427dcb4b
JH
64 else if (!strncmp(argv[1], "-C", 2)) {
65 diff_score_opt = diff_scoreopt_parse(argv[1]);
6b14d7fa 66 detect_rename = DIFF_DETECT_COPY;
427dcb4b 67 }
b8f80925 68 else
17710391 69 usage(diff_files_usage);
b8f80925 70 argv++; argc--;
e2e5e98a
PB
71 }
72
b8f80925
JH
73 /* At this point, if argc == 1, then we are doing everything.
74 * Otherwise argv[1] .. argv[argc-1] have the explicit paths.
75 */
e83c5163
LT
76 if (entries < 0) {
77 perror("read_cache");
78 exit(1);
79 }
be3cfa85 80
19feebc8 81 diff_setup(diff_setup_opt);
5c97558c 82
e83c5163
LT
83 for (i = 0; i < entries; i++) {
84 struct stat st;
0a7668e9 85 unsigned int oldmode, mode;
e83c5163 86 struct cache_entry *ce = active_cache[i];
d94c6128 87 int changed;
e83c5163 88
9fec8b26 89 if (ce_stage(ce)) {
4a6bf9e1 90 show_unmerge(ce->name);
9fec8b26
JH
91 while (i < entries &&
92 !strcmp(ce->name, active_cache[i]->name))
93 i++;
94 i--; /* compensate for loop control increments */
95 continue;
96 }
57fe64a4 97
ffbe1add 98 if (lstat(ce->name, &st) < 0) {
41174694 99 if (errno != ENOENT && errno != ENOTDIR) {
0a7668e9 100 perror(ce->name);
ca2a0798 101 continue;
57fe64a4 102 }
d15aa430 103 if (silent)
0a7668e9 104 continue;
4a6bf9e1 105 show_file('-', ce);
e83c5163
LT
106 continue;
107 }
5d728c84 108 changed = ce_match_stat(ce, &st);
6b14d7fa 109 if (!changed && detect_rename < DIFF_DETECT_COPY)
e83c5163 110 continue;
e2e5e98a 111
0a7668e9 112 oldmode = ntohl(ce->ce_mode);
95649d6c
JH
113 mode = (S_ISLNK(st.st_mode) ? S_IFLNK :
114 S_IFREG | ce_permissions(st.st_mode));
0a7668e9 115
4a6bf9e1
JH
116 show_modified(oldmode, mode, ce->sha1, null_sha1,
117 ce->name);
e83c5163 118 }
38c6f780 119 if (detect_rename)
6b14d7fa 120 diffcore_rename(detect_rename, diff_score_opt);
38c6f780 121 if (pickaxe)
367cec1c 122 diffcore_pickaxe(pickaxe, pickaxe_opts);
6b14d7fa
JH
123 if (1 < argc)
124 diffcore_pathspec(argv + 1);
b6d8f309 125 diff_flush(diff_output_format, 1);
e83c5163
LT
126 return 0;
127}