]>
Commit | Line | Data |
---|---|---|
e0965d83 | 1 | #include <ctype.h> |
9174026c | 2 | #include "cache.h" |
3ebfd4aa | 3 | #include "diff.h" |
e3bc7a3b | 4 | #include "commit.h" |
9174026c | 5 | |
dc26bd89 | 6 | static int show_root_diff = 0; |
cee99d22 | 7 | static int verbose_header = 0; |
e0965d83 | 8 | static int ignore_merges = 1; |
73134b6d | 9 | static int recursive = 0; |
4cae1a96 | 10 | static int show_tree_entry_in_recursive = 0; |
e0965d83 | 11 | static int read_stdin = 0; |
e68b6f15 LT |
12 | static int diff_output_format = DIFF_FORMAT_RAW; |
13 | static int diff_line_termination = '\n'; | |
5c97558c | 14 | static int detect_rename = 0; |
a7ca6540 | 15 | static int find_copies_harder = 0; |
19feebc8 | 16 | static int diff_setup_opt = 0; |
57fe64a4 | 17 | static int diff_score_opt = 0; |
057c7d30 | 18 | static const char *pickaxe = NULL; |
367cec1c | 19 | static int pickaxe_opts = 0; |
f345b0a0 | 20 | static int diff_break_opt = -1; |
af5323e0 | 21 | static const char *orderfile = NULL; |
f2ce9fde | 22 | static const char *diff_filter = NULL; |
f4f21ce3 | 23 | static const char *header = NULL; |
cee99d22 | 24 | static const char *header_prefix = ""; |
000182ea | 25 | static enum cmit_fmt commit_format = CMIT_FMT_RAW; |
9174026c | 26 | |
c5b42386 LT |
27 | // What paths are we interested in? |
28 | static int nr_paths = 0; | |
6b14d7fa | 29 | static const char **paths = NULL; |
c5b42386 LT |
30 | static int *pathlens = NULL; |
31 | ||
eeb79916 | 32 | static int diff_tree_sha1(const unsigned char *old, const unsigned char *new, const char *base); |
73134b6d LT |
33 | |
34 | static void update_tree_entry(void **bufp, unsigned long *sizep) | |
9174026c LT |
35 | { |
36 | void *buf = *bufp; | |
37 | unsigned long size = *sizep; | |
38 | int len = strlen(buf) + 1 + 20; | |
39 | ||
40 | if (size < len) | |
2de381f9 | 41 | die("corrupt tree file"); |
9174026c LT |
42 | *bufp = buf + len; |
43 | *sizep = size - len; | |
9174026c LT |
44 | } |
45 | ||
46 | static const unsigned char *extract(void *tree, unsigned long size, const char **pathp, unsigned int *modep) | |
47 | { | |
48 | int len = strlen(tree)+1; | |
49 | const unsigned char *sha1 = tree + len; | |
50 | const char *path = strchr(tree, ' '); | |
67574c40 | 51 | unsigned int mode; |
9174026c | 52 | |
67574c40 | 53 | if (!path || size < len + 20 || sscanf(tree, "%o", &mode) != 1) |
2de381f9 | 54 | die("corrupt tree file"); |
9174026c | 55 | *pathp = path+1; |
67574c40 | 56 | *modep = DIFF_FILE_CANON_MODE(mode); |
9174026c LT |
57 | return sha1; |
58 | } | |
59 | ||
262e82b4 LT |
60 | static char *malloc_base(const char *base, const char *path, int pathlen) |
61 | { | |
62 | int baselen = strlen(base); | |
812666c8 | 63 | char *newbase = xmalloc(baselen + pathlen + 2); |
262e82b4 LT |
64 | memcpy(newbase, base, baselen); |
65 | memcpy(newbase + baselen, path, pathlen); | |
66 | memcpy(newbase + baselen + pathlen, "/", 2); | |
67 | return newbase; | |
68 | } | |
69 | ||
70 | static void show_file(const char *prefix, void *tree, unsigned long size, const char *base); | |
ed1a368b | 71 | static void show_tree(const char *prefix, void *tree, unsigned long size, const char *base); |
262e82b4 LT |
72 | |
73 | /* A file entry went away or appeared */ | |
73134b6d | 74 | static void show_file(const char *prefix, void *tree, unsigned long size, const char *base) |
9174026c LT |
75 | { |
76 | unsigned mode; | |
77 | const char *path; | |
78 | const unsigned char *sha1 = extract(tree, size, &path, &mode); | |
262e82b4 LT |
79 | |
80 | if (recursive && S_ISDIR(mode)) { | |
81 | char type[20]; | |
82 | unsigned long size; | |
83 | char *newbase = malloc_base(base, path, strlen(path)); | |
84 | void *tree; | |
85 | ||
86 | tree = read_sha1_file(sha1, type, &size); | |
87 | if (!tree || strcmp(type, "tree")) | |
2de381f9 | 88 | die("corrupt tree sha %s", sha1_to_hex(sha1)); |
262e82b4 LT |
89 | |
90 | show_tree(prefix, tree, size, newbase); | |
57fe64a4 | 91 | |
262e82b4 LT |
92 | free(tree); |
93 | free(newbase); | |
94 | return; | |
95 | } | |
96 | ||
57fe64a4 | 97 | diff_addremove(prefix[0], mode, sha1, base, path); |
9174026c LT |
98 | } |
99 | ||
eeb79916 | 100 | static int compare_tree_entry(void *tree1, unsigned long size1, void *tree2, unsigned long size2, const char *base) |
9174026c LT |
101 | { |
102 | unsigned mode1, mode2; | |
103 | const char *path1, *path2; | |
104 | const unsigned char *sha1, *sha2; | |
73134b6d | 105 | int cmp, pathlen1, pathlen2; |
9174026c LT |
106 | |
107 | sha1 = extract(tree1, size1, &path1, &mode1); | |
108 | sha2 = extract(tree2, size2, &path2, &mode2); | |
109 | ||
73134b6d LT |
110 | pathlen1 = strlen(path1); |
111 | pathlen2 = strlen(path2); | |
e46091d5 | 112 | cmp = base_name_compare(path1, pathlen1, mode1, path2, pathlen2, mode2); |
9174026c | 113 | if (cmp < 0) { |
eeb79916 | 114 | show_file("-", tree1, size1, base); |
9174026c LT |
115 | return -1; |
116 | } | |
117 | if (cmp > 0) { | |
eeb79916 | 118 | show_file("+", tree2, size2, base); |
9174026c LT |
119 | return 1; |
120 | } | |
a7ca6540 | 121 | if (!find_copies_harder && !memcmp(sha1, sha2, 20) && mode1 == mode2) |
9174026c | 122 | return 0; |
262e82b4 LT |
123 | |
124 | /* | |
125 | * If the filemode has changed to/from a directory from/to a regular | |
aebb2679 | 126 | * file, we need to consider it a remove and an add. |
262e82b4 LT |
127 | */ |
128 | if (S_ISDIR(mode1) != S_ISDIR(mode2)) { | |
129 | show_file("-", tree1, size1, base); | |
130 | show_file("+", tree2, size2, base); | |
131 | return 0; | |
132 | } | |
133 | ||
134 | if (recursive && S_ISDIR(mode1)) { | |
eeb79916 | 135 | int retval; |
262e82b4 | 136 | char *newbase = malloc_base(base, path1, pathlen1); |
4cae1a96 JH |
137 | if (show_tree_entry_in_recursive) |
138 | diff_change(mode1, mode2, sha1, sha2, base, path1); | |
eeb79916 LT |
139 | retval = diff_tree_sha1(sha1, sha2, newbase); |
140 | free(newbase); | |
141 | return retval; | |
73134b6d LT |
142 | } |
143 | ||
57fe64a4 | 144 | diff_change(mode1, mode2, sha1, sha2, base, path1); |
9174026c LT |
145 | return 0; |
146 | } | |
147 | ||
c5b42386 LT |
148 | static int interesting(void *tree, unsigned long size, const char *base) |
149 | { | |
150 | const char *path; | |
151 | unsigned mode; | |
152 | int i; | |
153 | int baselen, pathlen; | |
154 | ||
155 | if (!nr_paths) | |
156 | return 1; | |
157 | ||
158 | (void)extract(tree, size, &path, &mode); | |
159 | ||
160 | pathlen = strlen(path); | |
161 | baselen = strlen(base); | |
162 | ||
163 | for (i=0; i < nr_paths; i++) { | |
164 | const char *match = paths[i]; | |
165 | int matchlen = pathlens[i]; | |
166 | ||
167 | if (baselen >= matchlen) { | |
168 | /* If it doesn't match, move along... */ | |
169 | if (strncmp(base, match, matchlen)) | |
170 | continue; | |
171 | ||
172 | /* The base is a subdirectory of a path which was specified. */ | |
173 | return 1; | |
174 | } | |
175 | ||
176 | /* Does the base match? */ | |
177 | if (strncmp(base, match, baselen)) | |
178 | continue; | |
179 | ||
180 | match += baselen; | |
181 | matchlen -= baselen; | |
182 | ||
183 | if (pathlen > matchlen) | |
184 | continue; | |
185 | ||
cb6c8ed2 LT |
186 | if (matchlen > pathlen) { |
187 | if (match[pathlen] != '/') | |
188 | continue; | |
850e82d8 LT |
189 | if (!S_ISDIR(mode)) |
190 | continue; | |
cb6c8ed2 LT |
191 | } |
192 | ||
c5b42386 LT |
193 | if (strncmp(path, match, pathlen)) |
194 | continue; | |
195 | ||
196 | return 1; | |
197 | } | |
198 | return 0; /* No matches */ | |
199 | } | |
200 | ||
ed1a368b LT |
201 | /* A whole sub-tree went away or appeared */ |
202 | static void show_tree(const char *prefix, void *tree, unsigned long size, const char *base) | |
203 | { | |
204 | while (size) { | |
4727f640 | 205 | if (interesting(tree, size, base)) |
ed1a368b LT |
206 | show_file(prefix, tree, size, base); |
207 | update_tree_entry(&tree, &size); | |
208 | } | |
209 | } | |
210 | ||
eeb79916 | 211 | static int diff_tree(void *tree1, unsigned long size1, void *tree2, unsigned long size2, const char *base) |
9174026c LT |
212 | { |
213 | while (size1 | size2) { | |
c5b42386 LT |
214 | if (nr_paths && size1 && !interesting(tree1, size1, base)) { |
215 | update_tree_entry(&tree1, &size1); | |
216 | continue; | |
217 | } | |
218 | if (nr_paths && size2 && !interesting(tree2, size2, base)) { | |
219 | update_tree_entry(&tree2, &size2); | |
220 | continue; | |
221 | } | |
9174026c | 222 | if (!size1) { |
eeb79916 | 223 | show_file("+", tree2, size2, base); |
9174026c LT |
224 | update_tree_entry(&tree2, &size2); |
225 | continue; | |
226 | } | |
227 | if (!size2) { | |
eeb79916 | 228 | show_file("-", tree1, size1, base); |
9174026c LT |
229 | update_tree_entry(&tree1, &size1); |
230 | continue; | |
231 | } | |
eeb79916 | 232 | switch (compare_tree_entry(tree1, size1, tree2, size2, base)) { |
9174026c LT |
233 | case -1: |
234 | update_tree_entry(&tree1, &size1); | |
235 | continue; | |
236 | case 0: | |
237 | update_tree_entry(&tree1, &size1); | |
238 | /* Fallthrough */ | |
239 | case 1: | |
240 | update_tree_entry(&tree2, &size2); | |
241 | continue; | |
242 | } | |
667bb59b | 243 | die("git-diff-tree: internal error"); |
9174026c LT |
244 | } |
245 | return 0; | |
246 | } | |
247 | ||
eeb79916 | 248 | static int diff_tree_sha1(const unsigned char *old, const unsigned char *new, const char *base) |
9174026c | 249 | { |
9174026c LT |
250 | void *tree1, *tree2; |
251 | unsigned long size1, size2; | |
73134b6d | 252 | int retval; |
9174026c | 253 | |
e99d59ff | 254 | tree1 = read_object_with_reference(old, "tree", &size1, NULL); |
c1fdf2a6 | 255 | if (!tree1) |
2de381f9 | 256 | die("unable to read source tree (%s)", sha1_to_hex(old)); |
e99d59ff | 257 | tree2 = read_object_with_reference(new, "tree", &size2, NULL); |
c1fdf2a6 | 258 | if (!tree2) |
2de381f9 | 259 | die("unable to read destination tree (%s)", sha1_to_hex(new)); |
eeb79916 | 260 | retval = diff_tree(tree1, size1, tree2, size2, base); |
73134b6d LT |
261 | free(tree1); |
262 | free(tree2); | |
263 | return retval; | |
264 | } | |
265 | ||
38c6f780 JH |
266 | static void call_diff_setup(void) |
267 | { | |
19feebc8 | 268 | diff_setup(diff_setup_opt); |
38c6f780 JH |
269 | } |
270 | ||
09d74b3b | 271 | static int call_diff_flush(void) |
38c6f780 | 272 | { |
4727f640 | 273 | diffcore_std(NULL, |
befe8639 | 274 | detect_rename, diff_score_opt, |
f345b0a0 | 275 | pickaxe, pickaxe_opts, |
af5323e0 | 276 | diff_break_opt, |
f2ce9fde JH |
277 | orderfile, |
278 | diff_filter); | |
9ab55bd2 | 279 | if (diff_queue_is_empty()) { |
e68b6f15 | 280 | diff_flush(DIFF_FORMAT_NO_OUTPUT, diff_line_termination); |
9ab55bd2 | 281 | return 0; |
6b14d7fa | 282 | } |
6b14d7fa | 283 | if (header) { |
e68b6f15 | 284 | printf("%s%c", header, diff_line_termination); |
6b14d7fa JH |
285 | header = NULL; |
286 | } | |
e68b6f15 | 287 | diff_flush(diff_output_format, diff_line_termination); |
6b14d7fa | 288 | return 1; |
38c6f780 JH |
289 | } |
290 | ||
5c97558c JH |
291 | static int diff_tree_sha1_top(const unsigned char *old, |
292 | const unsigned char *new, const char *base) | |
293 | { | |
294 | int ret; | |
57fe64a4 | 295 | |
38c6f780 | 296 | call_diff_setup(); |
5c97558c | 297 | ret = diff_tree_sha1(old, new, base); |
38c6f780 | 298 | call_diff_flush(); |
5c97558c JH |
299 | return ret; |
300 | } | |
301 | ||
dc26bd89 LT |
302 | static int diff_root_tree(const unsigned char *new, const char *base) |
303 | { | |
304 | int retval; | |
305 | void *tree; | |
306 | unsigned long size; | |
307 | ||
38c6f780 | 308 | call_diff_setup(); |
e99d59ff | 309 | tree = read_object_with_reference(new, "tree", &size, NULL); |
dc26bd89 LT |
310 | if (!tree) |
311 | die("unable to read root tree (%s)", sha1_to_hex(new)); | |
312 | retval = diff_tree("", 0, tree, size, base); | |
313 | free(tree); | |
38c6f780 | 314 | call_diff_flush(); |
dc26bd89 LT |
315 | return retval; |
316 | } | |
317 | ||
18092663 | 318 | static const char *generate_header(const char *commit, const char *parent, const char *msg, unsigned long len) |
cee99d22 | 319 | { |
3258c902 | 320 | static char this_header[16384]; |
cee99d22 LT |
321 | int offset; |
322 | ||
18092663 LT |
323 | if (!verbose_header) |
324 | return commit; | |
cee99d22 | 325 | |
18092663 LT |
326 | offset = sprintf(this_header, "%s%s (from %s)\n", header_prefix, commit, parent); |
327 | offset += pretty_print_commit(commit_format, msg, len, this_header + offset, sizeof(this_header) - offset); | |
cee99d22 LT |
328 | return this_header; |
329 | } | |
330 | ||
b11645be | 331 | static int diff_tree_commit(const unsigned char *commit, const char *name) |
e0965d83 | 332 | { |
e0965d83 | 333 | unsigned long size, offset; |
b11645be | 334 | char *buf = read_object_with_reference(commit, "commit", &size, NULL); |
e0965d83 | 335 | |
e0965d83 LT |
336 | if (!buf) |
337 | return -1; | |
338 | ||
73848892 LT |
339 | if (!name) { |
340 | static char commit_name[60]; | |
341 | strcpy(commit_name, sha1_to_hex(commit)); | |
342 | name = commit_name; | |
343 | } | |
344 | ||
dc26bd89 LT |
345 | /* Root commit? */ |
346 | if (show_root_diff && memcmp(buf + 46, "parent ", 7)) { | |
347 | header = generate_header(name, "root", buf, size); | |
348 | diff_root_tree(commit, ""); | |
349 | } | |
350 | ||
351 | /* More than one parent? */ | |
352 | if (ignore_merges) { | |
353 | if (!memcmp(buf + 46 + 48, "parent ", 7)) | |
354 | return 0; | |
355 | } | |
356 | ||
e0965d83 LT |
357 | offset = 46; |
358 | while (offset + 48 < size && !memcmp(buf + offset, "parent ", 7)) { | |
b11645be | 359 | unsigned char parent[20]; |
e0965d83 LT |
360 | if (get_sha1_hex(buf + offset + 7, parent)) |
361 | return -1; | |
b11645be | 362 | header = generate_header(name, sha1_to_hex(parent), buf, size); |
5c97558c | 363 | diff_tree_sha1_top(parent, commit, ""); |
d6db0107 | 364 | if (!header && verbose_header) { |
cee99d22 | 365 | header_prefix = "\ndiff-tree "; |
d6db0107 LT |
366 | /* |
367 | * Don't print multiple merge entries if we | |
368 | * don't print the diffs. | |
369 | */ | |
d6db0107 | 370 | } |
e0965d83 LT |
371 | offset += 48; |
372 | } | |
b11645be LT |
373 | return 0; |
374 | } | |
375 | ||
376 | static int diff_tree_stdin(char *line) | |
377 | { | |
378 | int len = strlen(line); | |
379 | unsigned char commit[20], parent[20]; | |
380 | static char this_header[1000]; | |
381 | ||
382 | if (!len || line[len-1] != '\n') | |
383 | return -1; | |
384 | line[len-1] = 0; | |
385 | if (get_sha1_hex(line, commit)) | |
386 | return -1; | |
387 | if (isspace(line[40]) && !get_sha1_hex(line+41, parent)) { | |
388 | line[40] = 0; | |
389 | line[81] = 0; | |
390 | sprintf(this_header, "%s (from %s)\n", line, line+41); | |
391 | header = this_header; | |
5c97558c | 392 | return diff_tree_sha1_top(parent, commit, ""); |
b11645be LT |
393 | } |
394 | line[40] = 0; | |
395 | return diff_tree_commit(commit, line); | |
e0965d83 LT |
396 | } |
397 | ||
d288a700 LT |
398 | static int count_paths(const char **paths) |
399 | { | |
400 | int i = 0; | |
401 | while (*paths++) | |
402 | i++; | |
403 | return i; | |
404 | } | |
405 | ||
4d1f1190 | 406 | static const char diff_tree_usage[] = |
dda2d79a JH |
407 | "git-diff-tree [--stdin] [-m] [-s] [-v] [--pretty] [-t] " |
408 | "[<common diff options>] <tree-ish> <tree-ish>" | |
409 | COMMON_DIFF_OPTIONS_HELP; | |
a8db165e | 410 | |
d288a700 | 411 | int main(int argc, char **argv) |
73134b6d | 412 | { |
0a8365a1 | 413 | int nr_sha1; |
e0965d83 | 414 | char line[1000]; |
0a8365a1 | 415 | unsigned char sha1[2][20]; |
d288a700 | 416 | const char *prefix = setup_git_directory(); |
73134b6d | 417 | |
0a8365a1 | 418 | nr_sha1 = 0; |
c5b42386 | 419 | for (;;) { |
6b14d7fa | 420 | const char *arg; |
c5b42386 | 421 | |
e0965d83 LT |
422 | argv++; |
423 | argc--; | |
424 | arg = *argv; | |
0a8365a1 | 425 | if (!arg) |
c5b42386 LT |
426 | break; |
427 | ||
0a8365a1 LT |
428 | if (*arg != '-') { |
429 | if (nr_sha1 < 2 && !get_sha1(arg, sha1[nr_sha1])) { | |
430 | nr_sha1++; | |
431 | continue; | |
432 | } | |
433 | break; | |
434 | } | |
435 | ||
436 | if (!strcmp(arg, "--")) { | |
e0965d83 LT |
437 | argv++; |
438 | argc--; | |
439 | break; | |
440 | } | |
bf16c71e | 441 | if (!strcmp(arg, "-r")) { |
73134b6d LT |
442 | recursive = 1; |
443 | continue; | |
444 | } | |
4cae1a96 JH |
445 | if (!strcmp(arg, "-t")) { |
446 | recursive = show_tree_entry_in_recursive = 1; | |
447 | continue; | |
448 | } | |
de809dbb | 449 | if (!strcmp(arg, "-R")) { |
19feebc8 | 450 | diff_setup_opt |= DIFF_SETUP_REVERSE; |
de809dbb LT |
451 | continue; |
452 | } | |
acb46f87 | 453 | if (!strcmp(arg, "-p") || !strcmp(arg, "-u")) { |
81e50eab JH |
454 | diff_output_format = DIFF_FORMAT_PATCH; |
455 | recursive = 1; | |
3ebfd4aa JH |
456 | continue; |
457 | } | |
52e95789 JH |
458 | if (!strncmp(arg, "-S", 2)) { |
459 | pickaxe = arg + 2; | |
460 | continue; | |
461 | } | |
af5323e0 JH |
462 | if (!strncmp(arg, "-O", 2)) { |
463 | orderfile = arg + 2; | |
464 | continue; | |
465 | } | |
f2ce9fde JH |
466 | if (!strncmp(arg, "--diff-filter=", 14)) { |
467 | diff_filter = arg + 14; | |
468 | continue; | |
469 | } | |
367cec1c JH |
470 | if (!strcmp(arg, "--pickaxe-all")) { |
471 | pickaxe_opts = DIFF_PICKAXE_ALL; | |
472 | continue; | |
473 | } | |
57fe64a4 | 474 | if (!strncmp(arg, "-M", 2)) { |
6b14d7fa | 475 | detect_rename = DIFF_DETECT_RENAME; |
0e3994fa JH |
476 | if ((diff_score_opt = diff_scoreopt_parse(arg)) == -1) |
477 | usage(diff_tree_usage); | |
427dcb4b JH |
478 | continue; |
479 | } | |
480 | if (!strncmp(arg, "-C", 2)) { | |
6b14d7fa | 481 | detect_rename = DIFF_DETECT_COPY; |
0e3994fa JH |
482 | if ((diff_score_opt = diff_scoreopt_parse(arg)) == -1) |
483 | usage(diff_tree_usage); | |
5c97558c JH |
484 | continue; |
485 | } | |
f345b0a0 | 486 | if (!strncmp(arg, "-B", 2)) { |
0e3994fa JH |
487 | if ((diff_break_opt = diff_scoreopt_parse(arg)) == -1) |
488 | usage(diff_tree_usage); | |
f345b0a0 JH |
489 | continue; |
490 | } | |
a7ca6540 JH |
491 | if (!strcmp(arg, "--find-copies-harder")) { |
492 | find_copies_harder = 1; | |
493 | continue; | |
494 | } | |
52f28529 JH |
495 | if (!strcmp(arg, "--name-only")) { |
496 | diff_output_format = DIFF_FORMAT_NAME; | |
497 | continue; | |
498 | } | |
6cbd72f8 | 499 | if (!strcmp(arg, "-z")) { |
e68b6f15 | 500 | diff_line_termination = 0; |
6cbd72f8 LT |
501 | continue; |
502 | } | |
e0965d83 LT |
503 | if (!strcmp(arg, "-m")) { |
504 | ignore_merges = 0; | |
505 | continue; | |
506 | } | |
f4f21ce3 | 507 | if (!strcmp(arg, "-s")) { |
d0309355 | 508 | diff_output_format = DIFF_FORMAT_NO_OUTPUT; |
f4f21ce3 LT |
509 | continue; |
510 | } | |
cee99d22 LT |
511 | if (!strcmp(arg, "-v")) { |
512 | verbose_header = 1; | |
513 | header_prefix = "diff-tree "; | |
514 | continue; | |
515 | } | |
a8db165e JH |
516 | if (!strncmp(arg, "--pretty", 8)) { |
517 | verbose_header = 1; | |
ba88e54b | 518 | header_prefix = "diff-tree "; |
a8db165e JH |
519 | commit_format = get_commit_format(arg+8); |
520 | continue; | |
521 | } | |
e0965d83 LT |
522 | if (!strcmp(arg, "--stdin")) { |
523 | read_stdin = 1; | |
524 | continue; | |
525 | } | |
dc26bd89 LT |
526 | if (!strcmp(arg, "--root")) { |
527 | show_root_diff = 1; | |
528 | continue; | |
529 | } | |
c5bac17a | 530 | usage(diff_tree_usage); |
73134b6d | 531 | } |
a7ca6540 JH |
532 | if (find_copies_harder && detect_rename != DIFF_DETECT_COPY) |
533 | usage(diff_tree_usage); | |
73134b6d | 534 | |
d288a700 LT |
535 | paths = get_pathspec(prefix, argv); |
536 | if (paths) { | |
c5b42386 LT |
537 | int i; |
538 | ||
d288a700 | 539 | nr_paths = count_paths(paths); |
812666c8 | 540 | pathlens = xmalloc(nr_paths * sizeof(int)); |
c5b42386 LT |
541 | for (i=0; i<nr_paths; i++) |
542 | pathlens[i] = strlen(paths[i]); | |
543 | } | |
544 | ||
0a8365a1 LT |
545 | switch (nr_sha1) { |
546 | case 0: | |
547 | if (!read_stdin) | |
548 | usage(diff_tree_usage); | |
549 | break; | |
550 | case 1: | |
73848892 | 551 | diff_tree_commit(sha1[0], NULL); |
0a8365a1 LT |
552 | break; |
553 | case 2: | |
5c97558c | 554 | diff_tree_sha1_top(sha1[0], sha1[1], ""); |
0a8365a1 LT |
555 | break; |
556 | } | |
557 | ||
e0965d83 | 558 | if (!read_stdin) |
0a8365a1 | 559 | return 0; |
e0965d83 | 560 | |
f0c6b2a2 JH |
561 | if (detect_rename) |
562 | diff_setup_opt |= (DIFF_SETUP_USE_SIZE_CACHE | | |
563 | DIFF_SETUP_USE_CACHE); | |
e0965d83 LT |
564 | while (fgets(line, sizeof(line), stdin)) |
565 | diff_tree_stdin(line); | |
566 | ||
567 | return 0; | |
9174026c | 568 | } |