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 <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Jun 24, 2016 at 23:09 UTC
4e8161a82e5449976392517968b2d1bb56109b29
3 files changed
+20
-20
builtin/merge-recursive.c
+10
-10
@@ -9,10 +9,10 @@ static const char builtin_merge_recursive_usage[] =
9
10
static const char *better_branch_name(const char *branch)
11
{
12
- static char githead_env[8 + 40 + 1];
12
+ static char githead_env[8 + GIT_SHA1_HEXSZ + 1];
13
char *name;
14
15
- if (strlen(branch) != 40)
15
+ if (strlen(branch) != GIT_SHA1_HEXSZ)
16
return branch;
17
xsnprintf(githead_env, sizeof(githead_env), "GITHEAD_%s", branch);
18
name = getenv(githead_env);
@@ -21,10 +21,10 @@ static const char *better_branch_name(const char *branch)
21
22
int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
23
{
24
- const unsigned char *bases[21];
24
+ const struct object_id *bases[21];
25
unsigned bases_count = 0;
26
int i, failed;
27
- unsigned char h1[20], h2[20];
27
+ struct object_id h1, h2;
28
struct merge_options o;
29
struct commit *result;
30
@@ -46,10 +46,10 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
46
continue;
47
}
48
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))
51
die("Could not parse object '%s'", argv[i]);
52
- bases[bases_count++] = sha;
52
+ bases[bases_count++] = oid;
53
}
54
else
55
warning("Cannot handle more than %d bases. "
@@ -62,9 +62,9 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
62
o.branch1 = argv[++i];
63
o.branch2 = argv[++i];
64
65
- if (get_sha1(o.branch1, h1))
65
+ if (get_oid(o.branch1, &h1))
66
die("Could not resolve ref '%s'", o.branch1);
67
- if (get_sha1(o.branch2, h2))
67
+ if (get_oid(o.branch2, &h2))
68
die("Could not resolve ref '%s'", o.branch2);
69
70
o.branch1 = better_branch_name(o.branch1);
@@ -73,7 +73,7 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
73
if (o.verbosity >= 3)
74
printf("Merging %s with %s\n", o.branch1, o.branch2);
75
76
- failed = merge_recursive_generic(&o, h1, h2, bases_count, bases, &result);
76
+ failed = merge_recursive_generic(&o, &h1, &h2, bases_count, bases, &result);
77
if (failed < 0)
78
return 128; /* die() error code */
79
return failed;
merge-recursive.c
+7
-7
@@ -1982,11 +1982,11 @@ int merge_recursive(struct merge_options *o,
1982
return clean;
1983
}
1984
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)
1986
{
1987
struct object *object;
1988
1989
- object = deref_tag(parse_object(sha1), name, strlen(name));
1989
+ object = deref_tag(parse_object(oid->hash), name, strlen(name));
1990
if (!object)
1991
return NULL;
1992
if (object->type == OBJ_TREE)
@@ -1999,10 +1999,10 @@ static struct commit *get_ref(const unsigned char *sha1, const char *name)
1999
}
2000
2001
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,
2004
int num_base_list,
2005
- const unsigned char **base_list,
2005
+ const struct object_id **base_list,
2006
struct commit **result)
2007
{
2008
int clean;
@@ -2015,9 +2015,9 @@ int merge_recursive_generic(struct merge_options *o,
2015
int i;
2016
for (i = 0; i < num_base_list; ++i) {
2017
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]))))
2019
return error(_("Could not parse object '%s'"),
2020
- sha1_to_hex(base_list[i]));
2020
+ oid_to_hex(base_list[i]));
2021
commit_list_insert(base, &ca);
2022
}
2023
}
merge-recursive.h
+3
-3
@@ -49,10 +49,10 @@ int merge_trees(struct merge_options *o,
49
* virtual commits and call merge_recursive() proper.
50
*/
51
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,
54
int num_ca,
55
- const unsigned char **ca,
55
+ const struct object_id **ca,
56
struct commit **result);
57
58
void init_merge_options(struct merge_options *o);