]> git.ipfire.org Git - thirdparty/git.git/blame - diff-files.c
[PATCH] git-merge-one-file-script: do not misinterpret rm failure.
[thirdparty/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 =
4727f640 10"git-diff-files [-p] [-q] [-r] [-z] [-R] [-B] [-M] [-C] [--find-copies-harder] [-O<orderfile>] [-S<string>] [--pickaxe-all] [<path>...]";
b8f80925 11
81e50eab 12static int diff_output_format = DIFF_FORMAT_HUMAN;
5c97558c 13static int detect_rename = 0;
4727f640 14static int find_copies_harder = 0;
19feebc8 15static int diff_setup_opt = 0;
57fe64a4 16static int diff_score_opt = 0;
057c7d30 17static const char *pickaxe = NULL;
367cec1c 18static int pickaxe_opts = 0;
f345b0a0 19static int diff_break_opt = -1;
af5323e0 20static const char *orderfile = NULL;
f2ce9fde 21static const char *diff_filter = NULL;
0a7668e9 22static int silent = 0;
0a7668e9 23
4a6bf9e1 24static void show_unmerge(const char *path)
0a7668e9 25{
57fe64a4 26 diff_unmerge(path);
4a6bf9e1
JH
27}
28
29static void show_file(int pfx, struct cache_entry *ce)
30{
57fe64a4 31 diff_addremove(pfx, ntohl(ce->ce_mode), ce->sha1, ce->name, NULL);
4a6bf9e1
JH
32}
33
34static void show_modified(int oldmode, int mode,
bf0f910d 35 const unsigned char *old_sha1, const unsigned char *sha1,
4a6bf9e1
JH
36 char *path)
37{
57fe64a4 38 diff_change(oldmode, mode, old_sha1, sha1, path, NULL);
0a7668e9
LT
39}
40
6b14d7fa 41int main(int argc, const char **argv)
e83c5163 42{
bf0f910d 43 static const unsigned char null_sha1[20] = { 0, };
e83c5163
LT
44 int entries = read_cache();
45 int i;
46
b8f80925 47 while (1 < argc && argv[1][0] == '-') {
d15aa430 48 if (!strcmp(argv[1], "-p"))
81e50eab 49 diff_output_format = DIFF_FORMAT_PATCH;
b8f80925 50 else if (!strcmp(argv[1], "-q"))
d15aa430 51 silent = 1;
0a7668e9 52 else if (!strcmp(argv[1], "-r"))
4a6bf9e1 53 ; /* no-op */
d15aa430
JH
54 else if (!strcmp(argv[1], "-s"))
55 ; /* no-op */
56 else if (!strcmp(argv[1], "-z"))
81e50eab 57 diff_output_format = DIFF_FORMAT_MACHINE;
57fe64a4 58 else if (!strcmp(argv[1], "-R"))
19feebc8 59 diff_setup_opt |= DIFF_SETUP_REVERSE;
e25de756 60 else if (!strncmp(argv[1], "-S", 2))
52e95789 61 pickaxe = argv[1] + 2;
af5323e0
JH
62 else if (!strncmp(argv[1], "-O", 2))
63 orderfile = argv[1] + 2;
f2ce9fde
JH
64 else if (!strncmp(argv[1], "--diff-filter=", 14))
65 diff_filter = argv[1] + 14;
367cec1c
JH
66 else if (!strcmp(argv[1], "--pickaxe-all"))
67 pickaxe_opts = DIFF_PICKAXE_ALL;
0e3994fa
JH
68 else if (!strncmp(argv[1], "-B", 2)) {
69 if ((diff_break_opt =
70 diff_scoreopt_parse(argv[1])) == -1)
71 usage(diff_files_usage);
72 }
57fe64a4 73 else if (!strncmp(argv[1], "-M", 2)) {
0e3994fa
JH
74 if ((diff_score_opt =
75 diff_scoreopt_parse(argv[1])) == -1)
76 usage(diff_files_usage);
6b14d7fa 77 detect_rename = DIFF_DETECT_RENAME;
5c97558c 78 }
427dcb4b 79 else if (!strncmp(argv[1], "-C", 2)) {
0e3994fa
JH
80 if ((diff_score_opt =
81 diff_scoreopt_parse(argv[1])) == -1)
82 usage(diff_files_usage);
6b14d7fa 83 detect_rename = DIFF_DETECT_COPY;
427dcb4b 84 }
4727f640
JH
85 else if (!strcmp(argv[1], "--find-copies-harder"))
86 find_copies_harder = 1;
b8f80925 87 else
17710391 88 usage(diff_files_usage);
b8f80925 89 argv++; argc--;
e2e5e98a
PB
90 }
91
4727f640
JH
92 if (find_copies_harder && detect_rename != DIFF_DETECT_COPY)
93 usage(diff_files_usage);
94
b8f80925
JH
95 /* At this point, if argc == 1, then we are doing everything.
96 * Otherwise argv[1] .. argv[argc-1] have the explicit paths.
97 */
e83c5163
LT
98 if (entries < 0) {
99 perror("read_cache");
100 exit(1);
101 }
be3cfa85 102
19feebc8 103 diff_setup(diff_setup_opt);
5c97558c 104
e83c5163
LT
105 for (i = 0; i < entries; i++) {
106 struct stat st;
67574c40 107 unsigned int oldmode;
e83c5163 108 struct cache_entry *ce = active_cache[i];
d94c6128 109 int changed;
e83c5163 110
9fec8b26 111 if (ce_stage(ce)) {
4a6bf9e1 112 show_unmerge(ce->name);
9fec8b26
JH
113 while (i < entries &&
114 !strcmp(ce->name, active_cache[i]->name))
115 i++;
116 i--; /* compensate for loop control increments */
117 continue;
118 }
57fe64a4 119
ffbe1add 120 if (lstat(ce->name, &st) < 0) {
41174694 121 if (errno != ENOENT && errno != ENOTDIR) {
0a7668e9 122 perror(ce->name);
ca2a0798 123 continue;
57fe64a4 124 }
d15aa430 125 if (silent)
0a7668e9 126 continue;
4a6bf9e1 127 show_file('-', ce);
e83c5163
LT
128 continue;
129 }
5d728c84 130 changed = ce_match_stat(ce, &st);
4727f640 131 if (!changed && !find_copies_harder)
e83c5163 132 continue;
0a7668e9 133 oldmode = ntohl(ce->ce_mode);
67574c40 134 show_modified(oldmode, DIFF_FILE_CANON_MODE(st.st_mode),
4727f640 135 ce->sha1, (changed ? null_sha1 : ce->sha1),
4a6bf9e1 136 ce->name);
e83c5163 137 }
f345b0a0 138 diffcore_std((1 < argc) ? argv + 1 : NULL,
befe8639 139 detect_rename, diff_score_opt,
f345b0a0 140 pickaxe, pickaxe_opts,
af5323e0 141 diff_break_opt,
f2ce9fde
JH
142 orderfile, diff_filter);
143 diff_flush(diff_output_format);
e83c5163
LT
144 return 0;
145}