Skip to content

Commit 4e8161a

Browse files
bk2204gitster
authored andcommitted
merge-recursive: convert merge_recursive_generic() to object_id
Convert this function and the git merge-recursive subcommand to use struct object_id. Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b4da9d6 commit 4e8161a

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

builtin/merge-recursive.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ static const char builtin_merge_recursive_usage[] =
99

1010
static const char *better_branch_name(const char *branch)
1111
{
12-
static char githead_env[8 + 40 + 1];
12+
static char githead_env[8 + GIT_SHA1_HEXSZ + 1];
1313
char *name;
1414

15-
if (strlen(branch) != 40)
15+
if (strlen(branch) != GIT_SHA1_HEXSZ)
1616
return branch;
1717
xsnprintf(githead_env, sizeof(githead_env), "GITHEAD_%s", branch);
1818
name = getenv(githead_env);
@@ -21,10 +21,10 @@ static const char *better_branch_name(const char *branch)
2121

2222
int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
2323
{
24-
const unsigned char *bases[21];
24+
const struct object_id *bases[21];
2525
unsigned bases_count = 0;
2626
int i, failed;
27-
unsigned char h1[20], h2[20];
27+
struct object_id h1, h2;
2828
struct merge_options o;
2929
struct commit *result;
3030

@@ -46,10 +46,10 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
4646
continue;
4747
}
4848
if (bases_count < ARRAY_SIZE(bases)-1) {
49-
unsigned char *sha = xmalloc(20);
50-
if (get_sha1(argv[i], sha))
49+
struct object_id *oid = xmalloc(sizeof(struct object_id));
50+
if (get_oid(argv[i], oid))
5151
die("Could not parse object '%s'", argv[i]);
52-
bases[bases_count++] = sha;
52+
bases[bases_count++] = oid;
5353
}
5454
else
5555
warning("Cannot handle more than %d bases. "
@@ -62,9 +62,9 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
6262
o.branch1 = argv[++i];
6363
o.branch2 = argv[++i];
6464

65-
if (get_sha1(o.branch1, h1))
65+
if (get_oid(o.branch1, &h1))
6666
die("Could not resolve ref '%s'", o.branch1);
67-
if (get_sha1(o.branch2, h2))
67+
if (get_oid(o.branch2, &h2))
6868
die("Could not resolve ref '%s'", o.branch2);
6969

7070
o.branch1 = better_branch_name(o.branch1);
@@ -73,7 +73,7 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
7373
if (o.verbosity >= 3)
7474
printf("Merging %s with %s\n", o.branch1, o.branch2);
7575

76-
failed = merge_recursive_generic(&o, h1, h2, bases_count, bases, &result);
76+
failed = merge_recursive_generic(&o, &h1, &h2, bases_count, bases, &result);
7777
if (failed < 0)
7878
return 128; /* die() error code */
7979
return failed;

merge-recursive.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,11 +1982,11 @@ int merge_recursive(struct merge_options *o,
19821982
return clean;
19831983
}
19841984

1985-
static struct commit *get_ref(const unsigned char *sha1, const char *name)
1985+
static struct commit *get_ref(const struct object_id *oid, const char *name)
19861986
{
19871987
struct object *object;
19881988

1989-
object = deref_tag(parse_object(sha1), name, strlen(name));
1989+
object = deref_tag(parse_object(oid->hash), name, strlen(name));
19901990
if (!object)
19911991
return NULL;
19921992
if (object->type == OBJ_TREE)
@@ -1999,10 +1999,10 @@ static struct commit *get_ref(const unsigned char *sha1, const char *name)
19991999
}
20002000

20012001
int merge_recursive_generic(struct merge_options *o,
2002-
const unsigned char *head,
2003-
const unsigned char *merge,
2002+
const struct object_id *head,
2003+
const struct object_id *merge,
20042004
int num_base_list,
2005-
const unsigned char **base_list,
2005+
const struct object_id **base_list,
20062006
struct commit **result)
20072007
{
20082008
int clean;
@@ -2015,9 +2015,9 @@ int merge_recursive_generic(struct merge_options *o,
20152015
int i;
20162016
for (i = 0; i < num_base_list; ++i) {
20172017
struct commit *base;
2018-
if (!(base = get_ref(base_list[i], sha1_to_hex(base_list[i]))))
2018+
if (!(base = get_ref(base_list[i], oid_to_hex(base_list[i]))))
20192019
return error(_("Could not parse object '%s'"),
2020-
sha1_to_hex(base_list[i]));
2020+
oid_to_hex(base_list[i]));
20212021
commit_list_insert(base, &ca);
20222022
}
20232023
}

merge-recursive.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ int merge_trees(struct merge_options *o,
4949
* virtual commits and call merge_recursive() proper.
5050
*/
5151
int merge_recursive_generic(struct merge_options *o,
52-
const unsigned char *head,
53-
const unsigned char *merge,
52+
const struct object_id *head,
53+
const struct object_id *merge,
5454
int num_ca,
55-
const unsigned char **ca,
55+
const struct object_id **ca,
5656
struct commit **result);
5757

5858
void init_merge_options(struct merge_options *o);

0 commit comments

Comments
 (0)