summaryrefslogtreecommitdiff
path: root/sha1_name.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2010-01-13 20:31:13 (GMT)
committerJunio C Hamano <gitster@pobox.com>2010-01-13 20:31:13 (GMT)
commit1f73566af5bec28cd8489c6139a9ede95817349c (patch)
treeb1deca9888bc171d09420d927bbe694795cf5d83 /sha1_name.c
parent5b9c0a699bdf9727d25eceb7b980dbede96bfd8e (diff)
parent230a4566382860fc26a3f8d578a41c6504cf865f (diff)
downloadgit-1f73566af5bec28cd8489c6139a9ede95817349c.zip
git-1f73566af5bec28cd8489c6139a9ede95817349c.tar.gz
git-1f73566af5bec28cd8489c6139a9ede95817349c.tar.bz2
Merge branch 'jc/checkout-merge-base'
* jc/checkout-merge-base: rebase -i: teach --onto A...B syntax rebase: fix --onto A...B parsing and add tests "rebase --onto A...B" replays history on the merge base between A and B "checkout A...B" switches to the merge base between A and B
Diffstat (limited to 'sha1_name.c')
-rw-r--r--sha1_name.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/sha1_name.c b/sha1_name.c
index ca8f9db..1739e9e 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -794,6 +794,48 @@ release_return:
return retval;
}
+int get_sha1_mb(const char *name, unsigned char *sha1)
+{
+ struct commit *one, *two;
+ struct commit_list *mbs;
+ unsigned char sha1_tmp[20];
+ const char *dots;
+ int st;
+
+ dots = strstr(name, "...");
+ if (!dots)
+ return get_sha1(name, sha1);
+ if (dots == name)
+ st = get_sha1("HEAD", sha1_tmp);
+ else {
+ struct strbuf sb;
+ strbuf_init(&sb, dots - name);
+ strbuf_add(&sb, name, dots - name);
+ st = get_sha1(sb.buf, sha1_tmp);
+ strbuf_release(&sb);
+ }
+ if (st)
+ return st;
+ one = lookup_commit_reference_gently(sha1_tmp, 0);
+ if (!one)
+ return -1;
+
+ if (get_sha1(dots[3] ? (dots + 3) : "HEAD", sha1_tmp))
+ return -1;
+ two = lookup_commit_reference_gently(sha1_tmp, 0);
+ if (!two)
+ return -1;
+ mbs = get_merge_bases(one, two, 1);
+ if (!mbs || mbs->next)
+ st = -1;
+ else {
+ st = 0;
+ hashcpy(sha1, mbs->item->object.sha1);
+ }
+ free_commit_list(mbs);
+ return st;
+}
+
/*
* This is like "get_sha1_basic()", except it allows "sha1 expressions",
* notably "xyz^" for "parent of xyz"