remote: convert functions to struct object_id
Convert several unsigned char arrays to use struct object_id instead, and change hard-coded 40-based constants to use GIT_SHA1_HEXSZ as well. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Jeff King <peff@peff.net>
brian m. carlson committed
Nov 10, 2015 at 02:22 UTC
fcd30b138759a2ab5ecb55758c3341f0d608df2b
1 file changed
+29
-29
remote.c
+29
-29
@@ -456,7 +456,7 @@ static void alias_all_urls(void)
456
static void read_config(void)
457
{
458
static int loaded;
459
- unsigned char sha1[20];
459
+ struct object_id oid;
460
const char *head_ref;
461
int flag;
462
@@ -465,7 +465,7 @@ static void read_config(void)
465
loaded = 1;
466
467
current_branch = NULL;
468
- head_ref = resolve_ref_unsafe("HEAD", 0, sha1, &flag);
468
+ head_ref = resolve_ref_unsafe("HEAD", 0, oid.hash, &flag);
469
if (head_ref && (flag & REF_ISSYMREF) &&
470
skip_prefix(head_ref, "refs/heads/", &head_ref)) {
471
current_branch = make_branch(head_ref, 0);
@@ -544,12 +544,12 @@ static struct refspec *parse_refspec_internal(int nr_refspec, const char **refsp
544
flags = REFNAME_ALLOW_ONELEVEL | (is_glob ? REFNAME_REFSPEC_PATTERN : 0);
545
546
if (fetch) {
547
- unsigned char unused[40];
547
+ struct object_id unused;
548
549
/* LHS */
550
if (!*rs[i].src)
551
; /* empty is ok; it means "HEAD" */
552
- else if (llen == 40 && !get_sha1_hex(rs[i].src, unused))
552
+ else if (llen == GIT_SHA1_HEXSZ && !get_oid_hex(rs[i].src, &unused))
553
rs[i].exact_sha1 = 1; /* ok */
554
else if (!check_refname_format(rs[i].src, flags))
555
; /* valid looking ref is ok */
@@ -1082,7 +1082,7 @@ static struct ref *alloc_delete_ref(void)
1082
static int try_explicit_object_name(const char *name,
1083
struct ref **match)
1084
{
1085
- unsigned char sha1[20];
1085
+ struct object_id oid;
1086
1087
if (!*name) {
1088
if (match)
@@ -1090,12 +1090,12 @@ static int try_explicit_object_name(const char *name,
1090
return 0;
1091
}
1092
1093
- if (get_sha1(name, sha1))
1093
+ if (get_sha1(name, oid.hash))
1094
return -1;
1095
1096
if (match) {
1097
*match = alloc_ref(name);
1098
- hashcpy((*match)->new_oid.hash, sha1);
1098
+ oidcpy(&(*match)->new_oid, &oid);
1099
}
1100
return 0;
1101
}
@@ -1110,10 +1110,10 @@ static struct ref *make_linked_ref(const char *name, struct ref ***tail)
1110
static char *guess_ref(const char *name, struct ref *peer)
1111
{
1112
struct strbuf buf = STRBUF_INIT;
1113
- unsigned char sha1[20];
1113
+ struct object_id oid;
1114
1115
const char *r = resolve_ref_unsafe(peer->name, RESOLVE_REF_READING,
1116
- sha1, NULL);
1116
+ oid.hash, NULL);
1117
if (!r)
1118
return NULL;
1119
@@ -1171,12 +1171,12 @@ static int match_explicit(struct ref *src, struct ref *dst,
1171
return -1;
1172
1173
if (!dst_value) {
1174
- unsigned char sha1[20];
1174
+ struct object_id oid;
1175
int flag;
1176
1177
dst_value = resolve_ref_unsafe(matched_src->name,
1178
RESOLVE_REF_READING,
1179
- sha1, &flag);
1179
+ oid.hash, &flag);
1180
if (!dst_value ||
1181
((flag & REF_ISSYMREF) &&
1182
!starts_with(dst_value, "refs/heads/")))
@@ -1292,13 +1292,13 @@ struct tips {
1292
int nr, alloc;
1293
};
1294
1295
-static void add_to_tips(struct tips *tips, const unsigned char *sha1)
1295
+static void add_to_tips(struct tips *tips, const struct object_id *oid)
1296
{
1297
struct commit *commit;
1298
1299
- if (is_null_sha1(sha1))
1299
+ if (is_null_oid(oid))
1300
return;
1301
- commit = lookup_commit_reference_gently(sha1, 1);
1301
+ commit = lookup_commit_reference_gently(oid->hash, 1);
1302
if (!commit || (commit->object.flags & TMP_MARK))
1303
return;
1304
commit->object.flags |= TMP_MARK;
@@ -1322,9 +1322,9 @@ static void add_missing_tags(struct ref *src, struct ref **dst, struct ref ***ds
1322
for (ref = *dst; ref; ref = ref->next) {
1323
if (ref->peer_ref &&
1324
!is_null_oid(&ref->peer_ref->new_oid))
1325
- add_to_tips(&sent_tips, ref->peer_ref->new_oid.hash);
1325
+ add_to_tips(&sent_tips, &ref->peer_ref->new_oid);
1326
else
1327
- add_to_tips(&sent_tips, ref->old_oid.hash);
1327
+ add_to_tips(&sent_tips, &ref->old_oid);
1328
if (starts_with(ref->name, "refs/tags/"))
1329
string_list_append(&dst_tag, ref->name);
1330
}
@@ -1609,7 +1609,7 @@ static void set_merge(struct branch *ret)
1609
{
1610
struct remote *remote;
1611
char *ref;
1612
- unsigned char sha1[20];
1612
+ struct object_id oid;
1613
int i;
1614
1615
if (!ret)
@@ -1635,7 +1635,7 @@ static void set_merge(struct branch *ret)
1635
strcmp(ret->remote_name, "."))
1636
continue;
1637
if (dwim_ref(ret->merge_name[i], strlen(ret->merge_name[i]),
1638
- sha1, &ref) == 1)
1638
+ oid.hash, &ref) == 1)
1639
ret->merge[i]->dst = ref;
1640
else
1641
ret->merge[i]->dst = xstrdup(ret->merge_name[i]);
@@ -1795,10 +1795,10 @@ const char *branch_get_push(struct branch *branch, struct strbuf *err)
1795
1796
static int ignore_symref_update(const char *refname)
1797
{
1798
- unsigned char sha1[20];
1798
+ struct object_id oid;
1799
int flag;
1800
1801
- if (!resolve_ref_unsafe(refname, 0, sha1, &flag))
1801
+ if (!resolve_ref_unsafe(refname, 0, oid.hash, &flag))
1802
return 0; /* non-existing refs are OK */
1803
return (flag & REF_ISSYMREF);
1804
}
@@ -1995,7 +1995,7 @@ int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid)
1995
int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
1996
const char **upstream_name)
1997
{
1998
- unsigned char sha1[20];
1998
+ struct object_id oid;
1999
struct commit *ours, *theirs;
2000
struct rev_info revs;
2001
const char *base;
@@ -2009,15 +2009,15 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
2009
return -1;
2010
2011
/* Cannot stat if what we used to build on no longer exists */
2012
- if (read_ref(base, sha1))
2012
+ if (read_ref(base, oid.hash))
2013
return -1;
2014
- theirs = lookup_commit_reference(sha1);
2014
+ theirs = lookup_commit_reference(oid.hash);
2015
if (!theirs)
2016
return -1;
2017
2018
- if (read_ref(branch->refname, sha1))
2018
+ if (read_ref(branch->refname, oid.hash))
2019
return -1;
2020
- ours = lookup_commit_reference(sha1);
2020
+ ours = lookup_commit_reference(oid.hash);
2021
if (!ours)
2022
return -1;
2023
@@ -2328,14 +2328,14 @@ int is_empty_cas(const struct push_cas_option *cas)
2328
* If we cannot do so, return negative to signal an error.
2329
*/
2330
static int remote_tracking(struct remote *remote, const char *refname,
2331
- unsigned char sha1[20])
2331
+ struct object_id *oid)
2332
{
2333
char *dst;
2334
2335
dst = apply_refspecs(remote->fetch, remote->fetch_refspec_nr, refname);
2336
if (!dst)
2337
return -1; /* no tracking ref for refname at remote */
2338
- if (read_ref(dst, sha1))
2338
+ if (read_ref(dst, oid->hash))
2339
return -1; /* we know what the tracking ref is but we cannot read it */
2340
return 0;
2341
}
@@ -2354,7 +2354,7 @@ static void apply_cas(struct push_cas_option *cas,
2354
ref->expect_old_sha1 = 1;
2355
if (!entry->use_tracking)
2356
hashcpy(ref->old_oid_expect.hash, cas->entry[i].expect);
2357
- else if (remote_tracking(remote, ref->name, ref->old_oid_expect.hash))
2357
+ else if (remote_tracking(remote, ref->name, &ref->old_oid_expect))
2358
ref->expect_old_no_trackback = 1;
2359
return;
2360
}
@@ -2364,7 +2364,7 @@ static void apply_cas(struct push_cas_option *cas,
2364
return;
2365
2366
ref->expect_old_sha1 = 1;
2367
- if (remote_tracking(remote, ref->name, ref->old_oid_expect.hash))
2367
+ if (remote_tracking(remote, ref->name, &ref->old_oid_expect))
2368
ref->expect_old_no_trackback = 1;
2369
}
2370