]> git.ipfire.org Git - thirdparty/git.git/blame - builtin/diff.c
treewide: remove unnecessary cache.h inclusion from a few headers
[thirdparty/git.git] / builtin / diff.c
CommitLineData
65056021
JH
1/*
2 * Builtin "git diff"
3 *
4 * Copyright (c) 2006 Junio C Hamano
5 */
07047d68 6#define USE_THE_INDEX_VARIABLE
65056021 7#include "cache.h"
b2141fc1 8#include "config.h"
8bfcb3a6 9#include "ewah/ewok.h"
697cc8ef 10#include "lockfile.h"
6b2f2d98 11#include "color.h"
65056021
JH
12#include "commit.h"
13#include "blob.h"
14#include "tag.h"
15#include "diff.h"
3b6c17b5 16#include "diff-merges.h"
65056021
JH
17#include "diffcore.h"
18#include "revision.h"
19#include "log-tree.h"
20#include "builtin.h"
302ad7a9 21#include "submodule.h"
fe299ec5 22#include "oid-array.h"
65056021 23
470faf96
TG
24#define DIFF_NO_INDEX_EXPLICIT 1
25#define DIFF_NO_INDEX_IMPLICIT 2
26
65056021 27static const char builtin_diff_usage[] =
b7e10b2c 28"git diff [<options>] [<commit>] [--] [<path>...]\n"
eb448631
DL
29" or: git diff [<options>] --cached [--merge-base] [<commit>] [--] [<path>...]\n"
30" or: git diff [<options>] [--merge-base] <commit> [<commit>...] <commit> [--] [<path>...]\n"
74f3390d
SY
31" or: git diff [<options>] <commit>...<commit> [--] [<path>...]\n"
32" or: git diff [<options>] <blob> <blob>\n"
acf7828e
ÆAB
33" or: git diff [<options>] --no-index [--] <path> <path>"
34"\n"
b7e10b2c 35COMMON_DIFF_OPTIONS_HELP;
65056021 36
158b06ca
JK
37static const char *blob_path(struct object_array_entry *entry)
38{
39 return entry->path ? entry->path : entry->name;
40}
41
65056021
JH
42static void stuff_change(struct diff_options *opt,
43 unsigned old_mode, unsigned new_mode,
9c4b0f66 44 const struct object_id *old_oid,
45 const struct object_id *new_oid,
46 int old_oid_valid,
47 int new_oid_valid,
d04ec74b
JK
48 const char *old_path,
49 const char *new_path)
65056021
JH
50{
51 struct diff_filespec *one, *two;
52
9c4b0f66 53 if (!is_null_oid(old_oid) && !is_null_oid(new_oid) &&
4a7e27e9 54 oideq(old_oid, new_oid) && (old_mode == new_mode))
65056021
JH
55 return;
56
0d1e0e78 57 if (opt->flags.reverse_diff) {
35d803bc 58 SWAP(old_mode, new_mode);
9c4b0f66 59 SWAP(old_oid, new_oid);
d04ec74b 60 SWAP(old_path, new_path);
65056021 61 }
cd676a51
JH
62
63 if (opt->prefix &&
d04ec74b
JK
64 (strncmp(old_path, opt->prefix, opt->prefix_length) ||
65 strncmp(new_path, opt->prefix, opt->prefix_length)))
cd676a51
JH
66 return;
67
d04ec74b
JK
68 one = alloc_filespec(old_path);
69 two = alloc_filespec(new_path);
f9704c2d
BW
70 fill_filespec(one, old_oid, old_oid_valid, old_mode);
71 fill_filespec(two, new_oid, new_oid_valid, new_mode);
65056021 72
65056021
JH
73 diff_queue(&diff_queued_diff, one, two);
74}
75
76static int builtin_diff_b_f(struct rev_info *revs,
77 int argc, const char **argv,
42f5ba5b 78 struct object_array_entry **blob)
65056021
JH
79{
80 /* Blob vs file in the working tree*/
81 struct stat st;
887c6c18 82 const char *path;
65056021 83
a610786f
TH
84 if (argc > 1)
85 usage(builtin_diff_usage);
86
887c6c18
NTND
87 GUARD_PATHSPEC(&revs->prune_data, PATHSPEC_FROMTOP | PATHSPEC_LITERAL);
88 path = revs->prune_data.items[0].match;
89
65056021 90 if (lstat(path, &st))
54214529 91 die_errno(_("failed to stat '%s'"), path);
65056021 92 if (!(S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)))
54214529 93 die(_("'%s': not a regular file or symlink"), path);
01618a3a 94
a5a818ee
JH
95 diff_set_mnemonic_prefix(&revs->diffopt, "o/", "w/");
96
42f5ba5b
JK
97 if (blob[0]->mode == S_IFINVALID)
98 blob[0]->mode = canon_mode(st.st_mode);
01618a3a 99
65056021 100 stuff_change(&revs->diffopt,
42f5ba5b 101 blob[0]->mode, canon_mode(st.st_mode),
14228447 102 &blob[0]->item->oid, null_oid(),
e5450100 103 1, 0,
30d005c0
JK
104 blob[0]->path ? blob[0]->path : path,
105 path);
65056021
JH
106 diffcore_std(&revs->diffopt);
107 diff_flush(&revs->diffopt);
108 return 0;
109}
110
111static int builtin_diff_blobs(struct rev_info *revs,
112 int argc, const char **argv,
42f5ba5b 113 struct object_array_entry **blob)
65056021 114{
33de80b1 115 const unsigned mode = canon_mode(S_IFREG | 0644);
65056021 116
a610786f
TH
117 if (argc > 1)
118 usage(builtin_diff_usage);
119
42f5ba5b
JK
120 if (blob[0]->mode == S_IFINVALID)
121 blob[0]->mode = mode;
01618a3a 122
42f5ba5b
JK
123 if (blob[1]->mode == S_IFINVALID)
124 blob[1]->mode = mode;
01618a3a 125
65056021 126 stuff_change(&revs->diffopt,
42f5ba5b
JK
127 blob[0]->mode, blob[1]->mode,
128 &blob[0]->item->oid, &blob[1]->item->oid,
e5450100 129 1, 1,
158b06ca 130 blob_path(blob[0]), blob_path(blob[1]));
65056021
JH
131 diffcore_std(&revs->diffopt);
132 diff_flush(&revs->diffopt);
133 return 0;
134}
135
136static int builtin_diff_index(struct rev_info *revs,
137 int argc, const char **argv)
138{
4c3fe82e 139 unsigned int option = 0;
65056021
JH
140 while (1 < argc) {
141 const char *arg = argv[1];
2baf1850 142 if (!strcmp(arg, "--cached") || !strcmp(arg, "--staged"))
4c3fe82e 143 option |= DIFF_INDEX_CACHED;
0f5a1d44
DL
144 else if (!strcmp(arg, "--merge-base"))
145 option |= DIFF_INDEX_MERGE_BASE;
65056021
JH
146 else
147 usage(builtin_diff_usage);
148 argv++; argc--;
149 }
150 /*
151 * Make sure there is one revision (i.e. pending object),
152 * and there is no revision filtering parameters.
153 */
1f1e895f 154 if (revs->pending.nr != 1 ||
65056021
JH
155 revs->max_count != -1 || revs->min_age != -1 ||
156 revs->max_age != -1)
157 usage(builtin_diff_usage);
4c3fe82e 158 if (!(option & DIFF_INDEX_CACHED)) {
7349afd2 159 setup_work_tree();
07047d68
ÆAB
160 if (repo_read_index_preload(the_repository,
161 &revs->diffopt.pathspec, 0) < 0) {
162 perror("repo_read_index_preload");
7349afd2
KB
163 return -1;
164 }
07047d68
ÆAB
165 } else if (repo_read_index(the_repository) < 0) {
166 perror("repo_read_cache");
b4e1e4a7
JH
167 return -1;
168 }
4c3fe82e 169 return run_diff_index(revs, option);
65056021
JH
170}
171
172static int builtin_diff_tree(struct rev_info *revs,
173 int argc, const char **argv,
91de344d
MH
174 struct object_array_entry *ent0,
175 struct object_array_entry *ent1)
65056021 176{
9c4b0f66 177 const struct object_id *(oid[2]);
3d09c228
DL
178 struct object_id mb_oid;
179 int merge_base = 0;
a610786f 180
3d09c228
DL
181 while (1 < argc) {
182 const char *arg = argv[1];
183 if (!strcmp(arg, "--merge-base"))
184 merge_base = 1;
185 else
186 usage(builtin_diff_usage);
187 argv++; argc--;
188 }
0fe7c1de 189
3d09c228
DL
190 if (merge_base) {
191 diff_get_merge_base(revs, &mb_oid);
192 oid[0] = &mb_oid;
193 oid[1] = &revs->pending.objects[1].item->oid;
194 } else {
195 int swap = 0;
196
197 /*
198 * We saw two trees, ent0 and ent1. If ent1 is uninteresting,
199 * swap them.
200 */
201 if (ent1->item->flags & UNINTERESTING)
202 swap = 1;
203 oid[swap] = &ent0->item->oid;
204 oid[1 - swap] = &ent1->item->oid;
205 }
66f414f8 206 diff_tree_oid(oid[0], oid[1], "", &revs->diffopt);
65056021
JH
207 log_tree_diff_flush(revs);
208 return 0;
209}
210
0fe7c1de
JH
211static int builtin_diff_combined(struct rev_info *revs,
212 int argc, const char **argv,
1f1e895f 213 struct object_array_entry *ent,
a79c6b60 214 int ents, int first_non_parent)
0fe7c1de 215{
910650d2 216 struct oid_array parents = OID_ARRAY_INIT;
0fe7c1de
JH
217 int i;
218
a610786f
TH
219 if (argc > 1)
220 usage(builtin_diff_usage);
221
a79c6b60
RS
222 if (first_non_parent < 0)
223 die(_("no merge given, only parents."));
224 if (first_non_parent >= ents)
225 BUG("first_non_parent out of range: %d", first_non_parent);
226
3b6c17b5
SO
227 diff_merges_set_dense_combined_if_unset(revs);
228
a79c6b60
RS
229 for (i = 0; i < ents; i++) {
230 if (i != first_non_parent)
231 oid_array_append(&parents, &ent[i].item->oid);
232 }
233 diff_tree_combined(&ent[first_non_parent].item->oid, &parents, revs);
910650d2 234 oid_array_clear(&parents);
0fe7c1de
JH
235 return 0;
236}
237
aecbf914
JH
238static void refresh_index_quietly(void)
239{
837e34eb 240 struct lock_file lock_file = LOCK_INIT;
aecbf914
JH
241 int fd;
242
07047d68 243 fd = repo_hold_locked_index(the_repository, &lock_file, 0);
aecbf914
JH
244 if (fd < 0)
245 return;
07047d68
ÆAB
246 discard_index(&the_index);
247 repo_read_index(the_repository);
248 refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, NULL, NULL,
249 NULL);
1b0d968b 250 repo_update_index_if_able(the_repository, &lock_file);
aecbf914
JH
251}
252
0569e9b8
JH
253static int builtin_diff_files(struct rev_info *revs, int argc, const char **argv)
254{
0569e9b8
JH
255 unsigned int options = 0;
256
257 while (1 < argc && argv[1][0] == '-') {
258 if (!strcmp(argv[1], "--base"))
259 revs->max_count = 1;
260 else if (!strcmp(argv[1], "--ours"))
261 revs->max_count = 2;
262 else if (!strcmp(argv[1], "--theirs"))
263 revs->max_count = 3;
264 else if (!strcmp(argv[1], "-q"))
265 options |= DIFF_SILENT_ON_REMOVED;
1c370ea4
MM
266 else if (!strcmp(argv[1], "-h"))
267 usage(builtin_diff_usage);
0569e9b8 268 else
54214529 269 return error(_("invalid option: %s"), argv[1]);
0569e9b8
JH
270 argv++; argc--;
271 }
272
903e09a3
JH
273 /*
274 * "diff --base" should not combine merges because it was not
275 * asked to. "diff -c" should not densify (if the user wants
276 * dense one, --cc can be explicitly asked for, or just rely
277 * on the default).
278 */
3b6c17b5 279 if (revs->max_count == -1 &&
0569e9b8 280 (revs->diffopt.output_format & DIFF_FORMAT_PATCH))
3b6c17b5 281 diff_merges_set_dense_combined_if_unset(revs);
0569e9b8 282
4f38f6b5 283 setup_work_tree();
07047d68
ÆAB
284 if (repo_read_index_preload(the_repository, &revs->diffopt.pathspec,
285 0) < 0) {
286 perror("repo_read_index_preload");
0569e9b8
JH
287 return -1;
288 }
e7c3a59c 289 return run_diff_files(revs, options);
0569e9b8
JH
290}
291
8bfcb3a6
CT
292struct symdiff {
293 struct bitmap *skip;
294 int warn;
295 const char *base, *left, *right;
296};
297
298/*
299 * Check for symmetric-difference arguments, and if present, arrange
300 * everything we need to know to handle them correctly. As a bonus,
301 * weed out all bogus range-based revision specifications, e.g.,
302 * "git diff A..B C..D" or "git diff A..B C" get rejected.
303 *
304 * For an actual symmetric diff, *symdiff is set this way:
305 *
306 * - its skip is non-NULL and marks *all* rev->pending.objects[i]
307 * indices that the caller should ignore (extra merge bases, of
308 * which there might be many, and A in A...B). Note that the
309 * chosen merge base and right side are NOT marked.
310 * - warn is set if there are multiple merge bases.
311 * - base, left, and right point to the names to use in a
312 * warning about multiple merge bases.
313 *
314 * If there is no symmetric diff argument, sym->skip is NULL and
315 * sym->warn is cleared. The remaining fields are not set.
316 */
317static void symdiff_prepare(struct rev_info *rev, struct symdiff *sym)
318{
319 int i, is_symdiff = 0, basecount = 0, othercount = 0;
320 int lpos = -1, rpos = -1, basepos = -1;
321 struct bitmap *map = NULL;
322
323 /*
324 * Use the whence fields to find merge bases and left and
325 * right parts of symmetric difference, so that we do not
326 * depend on the order that revisions are parsed. If there
327 * are any revs that aren't from these sources, we have a
328 * "git diff C A...B" or "git diff A...B C" case. Or we
329 * could even get "git diff A...B C...E", for instance.
330 *
331 * If we don't have just one merge base, we pick one
332 * at random.
333 *
334 * NB: REV_CMD_LEFT, REV_CMD_RIGHT are also used for A..B,
335 * so we must check for SYMMETRIC_LEFT too. The two arrays
336 * rev->pending.objects and rev->cmdline.rev are parallel.
337 */
338 for (i = 0; i < rev->cmdline.nr; i++) {
339 struct object *obj = rev->pending.objects[i].item;
340 switch (rev->cmdline.rev[i].whence) {
341 case REV_CMD_MERGE_BASE:
342 if (basepos < 0)
343 basepos = i;
344 basecount++;
345 break; /* do mark all bases */
346 case REV_CMD_LEFT:
347 if (lpos >= 0)
348 usage(builtin_diff_usage);
349 lpos = i;
350 if (obj->flags & SYMMETRIC_LEFT) {
351 is_symdiff = 1;
352 break; /* do mark A */
353 }
354 continue;
355 case REV_CMD_RIGHT:
356 if (rpos >= 0)
357 usage(builtin_diff_usage);
358 rpos = i;
359 continue; /* don't mark B */
360 case REV_CMD_PARENTS_ONLY:
361 case REV_CMD_REF:
362 case REV_CMD_REV:
363 othercount++;
364 continue;
365 }
afe8a907 366 if (!map)
8bfcb3a6
CT
367 map = bitmap_new();
368 bitmap_set(map, i);
369 }
370
371 /*
372 * Forbid any additional revs for both A...B and A..B.
373 */
374 if (lpos >= 0 && othercount > 0)
375 usage(builtin_diff_usage);
376
377 if (!is_symdiff) {
378 bitmap_free(map);
379 sym->warn = 0;
380 sym->skip = NULL;
381 return;
382 }
383
384 sym->left = rev->pending.objects[lpos].name;
385 sym->right = rev->pending.objects[rpos].name;
8bfcb3a6
CT
386 if (basecount == 0)
387 die(_("%s...%s: no merge base"), sym->left, sym->right);
5f46e610 388 sym->base = rev->pending.objects[basepos].name;
8bfcb3a6
CT
389 bitmap_unset(map, basepos); /* unmark the base we want */
390 sym->warn = basecount > 1;
391 sym->skip = map;
392}
393
a633fca0 394int cmd_diff(int argc, const char **argv, const char *prefix)
65056021 395{
1f1e895f 396 int i;
65056021 397 struct rev_info rev;
33055fa8 398 struct object_array ent = OBJECT_ARRAY_INIT;
a79c6b60 399 int first_non_parent = -1;
33055fa8 400 int blobs = 0, paths = 0;
42f5ba5b 401 struct object_array_entry *blob[2];
470faf96 402 int nongit = 0, no_index = 0;
41bbf9d5 403 int result = 0;
8bfcb3a6 404 struct symdiff sdiff;
65056021
JH
405
406 /*
407 * We could get N tree-ish in the rev.pending_objects list.
a9d7689c
DL
408 * Also there could be M blobs there, and P pathspecs. --cached may
409 * also be present.
65056021
JH
410 *
411 * N=0, M=0:
a9d7689c
DL
412 * cache vs files (diff-files)
413 *
414 * N=0, M=0, --cached:
415 * HEAD vs cache (diff-index --cached)
416 *
65056021
JH
417 * N=0, M=2:
418 * compare two random blobs. P must be zero.
a9d7689c 419 *
65056021 420 * N=0, M=1, P=1:
a9d7689c 421 * compare a blob with a working tree file.
65056021
JH
422 *
423 * N=1, M=0:
a9d7689c 424 * tree vs files (diff-index)
65056021 425 *
a9d7689c 426 * N=1, M=0, --cached:
65056021
JH
427 * tree vs cache (diff-index --cached)
428 *
429 * N=2, M=0:
430 * tree vs tree (diff-tree)
431 *
0569e9b8
JH
432 * N=0, M=0, P=2:
433 * compare two filesystem entities (aka --no-index).
434 *
65056021
JH
435 * Other cases are errors.
436 */
230f544e 437
470faf96
TG
438 /* Were we asked to do --no-index explicitly? */
439 for (i = 1; i < argc; i++) {
440 if (!strcmp(argv[i], "--")) {
441 i++;
442 break;
443 }
444 if (!strcmp(argv[i], "--no-index"))
445 no_index = DIFF_NO_INDEX_EXPLICIT;
446 if (argv[i][0] != '-')
447 break;
448 }
449
28a4e580 450 prefix = setup_git_directory_gently(&nongit);
6df5762d 451
51ba65b5
LD
452 if (!nongit) {
453 prepare_repo_settings(the_repository);
454 the_repository->settings.command_requires_full_index = 0;
455 }
456
28a4e580 457 if (!no_index) {
475b362c
JK
458 /*
459 * Treat git diff with at least one path outside of the
460 * repo the same as if the command would have been executed
461 * outside of a git repository. In this case it behaves
462 * the same way as "git diff --no-index <a> <b>", which acts
463 * as a colourful "diff" replacement.
464 */
465 if (nongit || ((argc == i + 2) &&
466 (!path_inside_repo(prefix, argv[i]) ||
467 !path_inside_repo(prefix, argv[i + 1]))))
468 no_index = DIFF_NO_INDEX_IMPLICIT;
469 }
470faf96 470
5404c116 471 init_diff_ui_defaults();
ef90d6d4 472 git_config(git_diff_ui_config, NULL);
5c327502 473 prefix = precompose_argv_prefix(argc, argv, prefix);
6b2f2d98 474
2abf3503 475 repo_init_revisions(the_repository, &rev, prefix);
0569e9b8 476
287ab28b 477 /* Set up defaults that will apply to both no-index and regular diffs. */
af9fedc1 478 rev.diffopt.stat_width = -1;
df44483a 479 rev.diffopt.stat_graph_width = -1;
0d1e0e78
BW
480 rev.diffopt.flags.allow_external = 1;
481 rev.diffopt.flags.allow_textconv = 1;
61af494c 482
287ab28b
JK
483 /* If this is a no-index diff, just run it and exit there. */
484 if (no_index)
dcd6a8c0
JH
485 exit(diff_no_index(&rev, no_index == DIFF_NO_INDEX_IMPLICIT,
486 argc, argv));
487
287ab28b
JK
488
489 /*
490 * Otherwise, we are doing the usual "git" diff; set up any
491 * further defaults that apply to regular diffs.
492 */
493 rev.diffopt.skip_stat_unmatch = !!diff_auto_refresh_index;
494
0231ae71
NTND
495 /*
496 * Default to intent-to-add entries invisible in the
497 * index. This makes them show up as new files in diff-files
498 * and not at all in diff-cached.
499 */
500 rev.diffopt.ita_invisible_in_index = 1;
501
0569e9b8 502 if (nongit)
54214529 503 die(_("Not a git repository"));
0569e9b8 504 argc = setup_revisions(argc, argv, &rev, NULL);
047fbe90 505 if (!rev.diffopt.output_format) {
c9b5ef99 506 rev.diffopt.output_format = DIFF_FORMAT_PATCH;
28452655 507 diff_setup_done(&rev.diffopt);
047fbe90 508 }
61af494c 509
0d1e0e78 510 rev.diffopt.flags.recursive = 1;
1eb4136a 511 rev.diffopt.rotate_to_strict = 1;
c9b5ef99 512
1af3d977 513 setup_diff_pager(&rev.diffopt);
89d07f75 514
0569e9b8
JH
515 /*
516 * Do we have --cached and not have a pending object, then
65056021
JH
517 * default to HEAD by hand. Eek.
518 */
1f1e895f 519 if (!rev.pending.nr) {
65056021
JH
520 int i;
521 for (i = 1; i < argc; i++) {
522 const char *arg = argv[i];
523 if (!strcmp(arg, "--"))
524 break;
2baf1850
DS
525 else if (!strcmp(arg, "--cached") ||
526 !strcmp(arg, "--staged")) {
3384a2df 527 add_head_to_pending(&rev);
a2b7a3b3
NTND
528 if (!rev.pending.nr) {
529 struct tree *tree;
f86bcc7b
SB
530 tree = lookup_tree(the_repository,
531 the_repository->hash_algo->empty_tree);
a2b7a3b3
NTND
532 add_pending_object(&rev, &tree->object, "HEAD");
533 }
65056021
JH
534 break;
535 }
536 }
537 }
538
8bfcb3a6 539 symdiff_prepare(&rev, &sdiff);
1f1e895f 540 for (i = 0; i < rev.pending.nr; i++) {
026f09e7
MH
541 struct object_array_entry *entry = &rev.pending.objects[i];
542 struct object *obj = entry->item;
543 const char *name = entry->name;
65056021
JH
544 int flags = (obj->flags & UNINTERESTING);
545 if (!obj->parsed)
109cd76d 546 obj = parse_object(the_repository, &obj->oid);
a74093da 547 obj = deref_tag(the_repository, obj, NULL, 0);
65056021 548 if (!obj)
54214529 549 die(_("invalid object '%s' given."), name);
1974632c 550 if (obj->type == OBJ_COMMIT)
2e27bd77 551 obj = &get_commit_tree(((struct commit *)obj))->object;
5b1e14ea 552
1974632c 553 if (obj->type == OBJ_TREE) {
8bfcb3a6
CT
554 if (sdiff.skip && bitmap_get(sdiff.skip, i))
555 continue;
65056021 556 obj->flags |= flags;
33055fa8 557 add_object_array(obj, name, &ent);
a79c6b60
RS
558 if (first_non_parent < 0 &&
559 (i >= rev.cmdline.nr || /* HEAD by hand. */
560 rev.cmdline.rev[i].whence != REV_CMD_PARENTS_ONLY))
561 first_non_parent = ent.nr - 1;
5b1e14ea 562 } else if (obj->type == OBJ_BLOB) {
65056021 563 if (2 <= blobs)
54214529 564 die(_("more than two blobs given: '%s'"), name);
42f5ba5b 565 blob[blobs] = entry;
65056021 566 blobs++;
230f544e 567
5b1e14ea
MH
568 } else {
569 die(_("unhandled object '%s' given."), name);
65056021 570 }
65056021 571 }
887c6c18 572 if (rev.prune_data.nr)
afe069d1 573 paths += rev.prune_data.nr;
65056021
JH
574
575 /*
576 * Now, do the arguments look reasonable?
577 */
33055fa8 578 if (!ent.nr) {
65056021
JH
579 switch (blobs) {
580 case 0:
0569e9b8 581 result = builtin_diff_files(&rev, argc, argv);
65056021
JH
582 break;
583 case 1:
584 if (paths != 1)
585 usage(builtin_diff_usage);
887c6c18 586 result = builtin_diff_b_f(&rev, argc, argv, blob);
65056021
JH
587 break;
588 case 2:
0fe7c1de
JH
589 if (paths)
590 usage(builtin_diff_usage);
41bbf9d5 591 result = builtin_diff_blobs(&rev, argc, argv, blob);
65056021
JH
592 break;
593 default:
594 usage(builtin_diff_usage);
595 }
596 }
597 else if (blobs)
598 usage(builtin_diff_usage);
33055fa8 599 else if (ent.nr == 1)
41bbf9d5 600 result = builtin_diff_index(&rev, argc, argv);
8bfcb3a6
CT
601 else if (ent.nr == 2) {
602 if (sdiff.warn)
603 warning(_("%s...%s: multiple merge bases, using %s"),
604 sdiff.left, sdiff.right, sdiff.base);
33055fa8
MH
605 result = builtin_diff_tree(&rev, argc, argv,
606 &ent.objects[0], &ent.objects[1]);
c008c0ff 607 } else
41bbf9d5 608 result = builtin_diff_combined(&rev, argc, argv,
a79c6b60
RS
609 ent.objects, ent.nr,
610 first_non_parent);
da31b358 611 result = diff_result_code(&rev.diffopt, result);
aecbf914
JH
612 if (1 < rev.diffopt.skip_stat_unmatch)
613 refresh_index_quietly();
bf1b32d0 614 release_revisions(&rev);
ac95f5d3 615 object_array_clear(&ent);
886e1084 616 UNLEAK(blob);
41bbf9d5 617 return result;
65056021 618}