diff options
Diffstat (limited to 'builtin/merge-base.c')
-rw-r--r-- | builtin/merge-base.c | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/builtin/merge-base.c b/builtin/merge-base.c index 08a8217890..cfe2a796f8 100644 --- a/builtin/merge-base.c +++ b/builtin/merge-base.c @@ -16,7 +16,7 @@ static int show_merge_base(struct commit **rev, int rev_nr, int show_all) return 1; while (result) { - printf("%s\n", sha1_to_hex(result->item->object.sha1)); + printf("%s\n", oid_to_hex(&result->item->object.oid)); if (!show_all) return 0; result = result->next; @@ -36,12 +36,12 @@ static const char * const merge_base_usage[] = { static struct commit *get_commit_reference(const char *arg) { - unsigned char revkey[20]; + struct object_id revkey; struct commit *r; - if (get_sha1(arg, revkey)) + if (get_oid(arg, &revkey)) die("Not a valid object name %s", arg); - r = lookup_commit_reference(revkey); + r = lookup_commit_reference(revkey.hash); if (!r) die("Not a valid commit name %s", arg); @@ -62,7 +62,7 @@ static int handle_independent(int count, const char **args) return 1; while (result) { - printf("%s\n", sha1_to_hex(result->item->object.sha1)); + printf("%s\n", oid_to_hex(&result->item->object.oid)); result = result->next; } return 0; @@ -83,7 +83,7 @@ static int handle_octopus(int count, const char **args, int show_all) return 1; while (result) { - printf("%s\n", sha1_to_hex(result->item->object.sha1)); + printf("%s\n", oid_to_hex(&result->item->object.oid)); if (!show_all) return 0; result = result->next; @@ -113,14 +113,14 @@ struct rev_collect { unsigned int initial : 1; }; -static void add_one_commit(unsigned char *sha1, struct rev_collect *revs) +static void add_one_commit(struct object_id *oid, struct rev_collect *revs) { struct commit *commit; - if (is_null_sha1(sha1)) + if (is_null_oid(oid)) return; - commit = lookup_commit(sha1); + commit = lookup_commit(oid->hash); if (!commit || (commit->object.flags & TMP_MARK) || parse_commit(commit)) @@ -131,7 +131,7 @@ static void add_one_commit(unsigned char *sha1, struct rev_collect *revs) commit->object.flags |= TMP_MARK; } -static int collect_one_reflog_ent(unsigned char *osha1, unsigned char *nsha1, +static int collect_one_reflog_ent(struct object_id *ooid, struct object_id *noid, const char *ident, unsigned long timestamp, int tz, const char *message, void *cbdata) { @@ -139,15 +139,15 @@ static int collect_one_reflog_ent(unsigned char *osha1, unsigned char *nsha1, if (revs->initial) { revs->initial = 0; - add_one_commit(osha1, revs); + add_one_commit(ooid, revs); } - add_one_commit(nsha1, revs); + add_one_commit(noid, revs); return 0; } static int handle_fork_point(int argc, const char **argv) { - unsigned char sha1[20]; + struct object_id oid; char *refname; const char *commitname; struct rev_collect revs; @@ -155,7 +155,7 @@ static int handle_fork_point(int argc, const char **argv) struct commit_list *bases; int i, ret = 0; - switch (dwim_ref(argv[0], strlen(argv[0]), sha1, &refname)) { + switch (dwim_ref(argv[0], strlen(argv[0]), oid.hash, &refname)) { case 0: die("No such ref: '%s'", argv[0]); case 1: @@ -165,14 +165,17 @@ static int handle_fork_point(int argc, const char **argv) } commitname = (argc == 2) ? argv[1] : "HEAD"; - if (get_sha1(commitname, sha1)) + if (get_oid(commitname, &oid)) die("Not a valid object name: '%s'", commitname); - derived = lookup_commit_reference(sha1); + derived = lookup_commit_reference(oid.hash); memset(&revs, 0, sizeof(revs)); revs.initial = 1; for_each_reflog_ent(refname, collect_one_reflog_ent, &revs); + if (!revs.nr && !get_oid(refname, &oid)) + add_one_commit(&oid, &revs); + for (i = 0; i < revs.nr; i++) revs.commit[i]->object.flags &= ~TMP_MARK; @@ -196,7 +199,7 @@ static int handle_fork_point(int argc, const char **argv) goto cleanup_return; } - printf("%s\n", sha1_to_hex(bases->item->object.sha1)); + printf("%s\n", oid_to_hex(&bases->item->object.oid)); cleanup_return: free_commit_list(bases); @@ -252,7 +255,7 @@ int cmd_merge_base(int argc, const char **argv, const char *prefix) if (argc < 2) usage_with_options(merge_base_usage, options); - rev = xmalloc(argc * sizeof(*rev)); + ALLOC_ARRAY(rev, argc); while (argc-- > 0) rev[rev_nr++] = get_commit_reference(*argv++); return show_merge_base(rev, rev_nr, show_all); |