builtin/diff-tree: learn --merge-base
The previous commit introduced ---merge-base a way to take the diff between the working tree or index and the merge base between an arbitrary commit and HEAD. It makes sense to extend this option to support the case where two commits are given too and behave in a manner identical to `git diff A...B`. Introduce the --merge-base flag as an alternative to triple-dot notation. Thus, we would be able to write the above as `git diff --merge-base A B`. Signed-off-by: Denton Liu <liu.denton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
0f5a1d449b
commit
3d09c22869
@ -26,7 +26,7 @@
|
||||
static const char builtin_diff_usage[] =
|
||||
"git diff [<options>] [<commit>] [--] [<path>...]\n"
|
||||
" or: git diff [<options>] --cached [<commit>] [--] [<path>...]\n"
|
||||
" or: git diff [<options>] <commit> [<commit>...] <commit> [--] [<path>...]\n"
|
||||
" or: git diff [<options>] <commit> [--merge-base] [<commit>...] <commit> [--] [<path>...]\n"
|
||||
" or: git diff [<options>] <commit>...<commit>] [--] [<path>...]\n"
|
||||
" or: git diff [<options>] <blob> <blob>]\n"
|
||||
" or: git diff [<options>] --no-index [--] <path> <path>]\n"
|
||||
@ -172,19 +172,34 @@ static int builtin_diff_tree(struct rev_info *revs,
|
||||
struct object_array_entry *ent1)
|
||||
{
|
||||
const struct object_id *(oid[2]);
|
||||
int swap = 0;
|
||||
struct object_id mb_oid;
|
||||
int merge_base = 0;
|
||||
|
||||
if (argc > 1)
|
||||
usage(builtin_diff_usage);
|
||||
while (1 < argc) {
|
||||
const char *arg = argv[1];
|
||||
if (!strcmp(arg, "--merge-base"))
|
||||
merge_base = 1;
|
||||
else
|
||||
usage(builtin_diff_usage);
|
||||
argv++; argc--;
|
||||
}
|
||||
|
||||
/*
|
||||
* We saw two trees, ent0 and ent1. If ent1 is uninteresting,
|
||||
* swap them.
|
||||
*/
|
||||
if (ent1->item->flags & UNINTERESTING)
|
||||
swap = 1;
|
||||
oid[swap] = &ent0->item->oid;
|
||||
oid[1 - swap] = &ent1->item->oid;
|
||||
if (merge_base) {
|
||||
diff_get_merge_base(revs, &mb_oid);
|
||||
oid[0] = &mb_oid;
|
||||
oid[1] = &revs->pending.objects[1].item->oid;
|
||||
} else {
|
||||
int swap = 0;
|
||||
|
||||
/*
|
||||
* We saw two trees, ent0 and ent1. If ent1 is uninteresting,
|
||||
* swap them.
|
||||
*/
|
||||
if (ent1->item->flags & UNINTERESTING)
|
||||
swap = 1;
|
||||
oid[swap] = &ent0->item->oid;
|
||||
oid[1 - swap] = &ent1->item->oid;
|
||||
}
|
||||
diff_tree_oid(oid[0], oid[1], "", &revs->diffopt);
|
||||
log_tree_diff_flush(revs);
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user