summaryrefslogtreecommitdiff
path: root/builtin/diff-tree.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2020-11-02 21:17:39 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-11-02 21:17:39 (GMT)
commitb6fb70c985a6fc113e971a6696f328abf8315dce (patch)
tree4b9e3bfc3f87b29bcf0d64382fae38762d1202ab /builtin/diff-tree.c
parent761a4e9ab1950fc7b868629ebe478bb41235db45 (diff)
parentcce7d6ecfc45f0d74a95c6ca6447d6e327791348 (diff)
downloadgit-b6fb70c985a6fc113e971a6696f328abf8315dce.zip
git-b6fb70c985a6fc113e971a6696f328abf8315dce.tar.gz
git-b6fb70c985a6fc113e971a6696f328abf8315dce.tar.bz2
Merge branch 'dl/diff-merge-base'
"git diff A...B" learned "git diff --merge-base A B", which is a longer short-hand to say the same thing. * dl/diff-merge-base: contrib/completion: complete `git diff --merge-base` builtin/diff-tree: learn --merge-base builtin/diff-index: learn --merge-base t4068: add --merge-base tests diff-lib: define diff_get_merge_base() diff-lib: accept option flags in run_diff_index() contrib/completion: extract common diff/difftool options git-diff.txt: backtick quote command text git-diff-index.txt: make --cached description a proper sentence t4068: remove unnecessary >tmp
Diffstat (limited to 'builtin/diff-tree.c')
-rw-r--r--builtin/diff-tree.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c
index 802363d..9fc95e9 100644
--- a/builtin/diff-tree.c
+++ b/builtin/diff-tree.c
@@ -111,6 +111,7 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
struct setup_revision_opt s_r_opt;
struct userformat_want w;
int read_stdin = 0;
+ int merge_base = 0;
if (argc == 2 && !strcmp(argv[1], "-h"))
usage(diff_tree_usage);
@@ -143,9 +144,18 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
read_stdin = 1;
continue;
}
+ if (!strcmp(arg, "--merge-base")) {
+ merge_base = 1;
+ continue;
+ }
usage(diff_tree_usage);
}
+ if (read_stdin && merge_base)
+ die(_("--stdin and --merge-base are mutually exclusive"));
+ if (merge_base && opt->pending.nr != 2)
+ die(_("--merge-base only works with two commits"));
+
/*
* NOTE! We expect "a..b" to expand to "^a b" but it is
* perfectly valid for revision range parser to yield "b ^a",
@@ -165,7 +175,12 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
case 2:
tree1 = opt->pending.objects[0].item;
tree2 = opt->pending.objects[1].item;
- if (tree2->flags & UNINTERESTING) {
+ if (merge_base) {
+ struct object_id oid;
+
+ diff_get_merge_base(opt, &oid);
+ tree1 = lookup_object(the_repository, &oid);
+ } else if (tree2->flags & UNINTERESTING) {
SWAP(tree2, tree1);
}
diff_tree_oid(&tree1->oid, &tree2->oid, "", &opt->diffopt);