summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorLibravatar Xiaolong Ye <xiaolong.ye@intel.com>2016-04-26 15:51:23 +0800
committerLibravatar Junio C Hamano <gitster@pobox.com>2016-04-26 10:51:50 -0700
commit3de665175f3433ccd1dadd4d5d09fa9553948e55 (patch)
tree41b30294951a8a74f3aa46daed76ee1594b9feee /builtin
parentformat-patch: add '--base' option to record base tree info (diff)
downloadtgif-3de665175f3433ccd1dadd4d5d09fa9553948e55.tar.xz
format-patch: introduce --base=auto option
Introduce --base=auto to record the base commit info automatically, the base_commit will be the merge base of tip commit of the upstream branch and revision-range specified in cmdline. Helped-by: Junio C Hamano <gitster@pobox.com> Helped-by: Wu Fengguang <fengguang.wu@intel.com> Signed-off-by: Xiaolong Ye <xiaolong.ye@intel.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/log.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/builtin/log.c b/builtin/log.c
index c9ee333932..9033bc7c54 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -1199,9 +1199,33 @@ static struct commit *get_base_commit(const char *base_commit,
struct commit **rev;
int i = 0, rev_nr = 0;
- base = lookup_commit_reference_by_name(base_commit);
- if (!base)
- die(_("Unknown commit %s"), base_commit);
+ if (!strcmp(base_commit, "auto")) {
+ struct branch *curr_branch = branch_get(NULL);
+ const char *upstream = branch_get_upstream(curr_branch, NULL);
+ if (upstream) {
+ struct commit_list *base_list;
+ struct commit *commit;
+ unsigned char sha1[20];
+
+ if (get_sha1(upstream, sha1))
+ die(_("Failed to resolve '%s' as a valid ref."), upstream);
+ commit = lookup_commit_or_die(sha1, "upstream base");
+ base_list = get_merge_bases_many(commit, total, list);
+ /* There should be one and only one merge base. */
+ if (!base_list || base_list->next)
+ die(_("Could not find exact merge base."));
+ base = base_list->item;
+ free_commit_list(base_list);
+ } else {
+ die(_("Failed to get upstream, if you want to record base commit automatically,\n"
+ "please use git branch --set-upstream-to to track a remote branch.\n"
+ "Or you could specify base commit by --base=<base-commit-id> manually."));
+ }
+ } else {
+ base = lookup_commit_reference_by_name(base_commit);
+ if (!base)
+ die(_("Unknown commit %s"), base_commit);
+ }
ALLOC_ARRAY(rev, total);
for (i = 0; i < total; i++)