Skip to content

Commit fcd30b1

Browse files
bk2204peff
authored andcommitted
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 <[email protected]> Signed-off-by: Jeff King <[email protected]>
1 parent ed1c997 commit fcd30b1

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

remote.c

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ static void alias_all_urls(void)
456456
static void read_config(void)
457457
{
458458
static int loaded;
459-
unsigned char sha1[20];
459+
struct object_id oid;
460460
const char *head_ref;
461461
int flag;
462462

@@ -465,7 +465,7 @@ static void read_config(void)
465465
loaded = 1;
466466

467467
current_branch = NULL;
468-
head_ref = resolve_ref_unsafe("HEAD", 0, sha1, &flag);
468+
head_ref = resolve_ref_unsafe("HEAD", 0, oid.hash, &flag);
469469
if (head_ref && (flag & REF_ISSYMREF) &&
470470
skip_prefix(head_ref, "refs/heads/", &head_ref)) {
471471
current_branch = make_branch(head_ref, 0);
@@ -544,12 +544,12 @@ static struct refspec *parse_refspec_internal(int nr_refspec, const char **refsp
544544
flags = REFNAME_ALLOW_ONELEVEL | (is_glob ? REFNAME_REFSPEC_PATTERN : 0);
545545

546546
if (fetch) {
547-
unsigned char unused[40];
547+
struct object_id unused;
548548

549549
/* LHS */
550550
if (!*rs[i].src)
551551
; /* 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))
553553
rs[i].exact_sha1 = 1; /* ok */
554554
else if (!check_refname_format(rs[i].src, flags))
555555
; /* valid looking ref is ok */
@@ -1082,20 +1082,20 @@ static struct ref *alloc_delete_ref(void)
10821082
static int try_explicit_object_name(const char *name,
10831083
struct ref **match)
10841084
{
1085-
unsigned char sha1[20];
1085+
struct object_id oid;
10861086

10871087
if (!*name) {
10881088
if (match)
10891089
*match = alloc_delete_ref();
10901090
return 0;
10911091
}
10921092

1093-
if (get_sha1(name, sha1))
1093+
if (get_sha1(name, oid.hash))
10941094
return -1;
10951095

10961096
if (match) {
10971097
*match = alloc_ref(name);
1098-
hashcpy((*match)->new_oid.hash, sha1);
1098+
oidcpy(&(*match)->new_oid, &oid);
10991099
}
11001100
return 0;
11011101
}
@@ -1110,10 +1110,10 @@ static struct ref *make_linked_ref(const char *name, struct ref ***tail)
11101110
static char *guess_ref(const char *name, struct ref *peer)
11111111
{
11121112
struct strbuf buf = STRBUF_INIT;
1113-
unsigned char sha1[20];
1113+
struct object_id oid;
11141114

11151115
const char *r = resolve_ref_unsafe(peer->name, RESOLVE_REF_READING,
1116-
sha1, NULL);
1116+
oid.hash, NULL);
11171117
if (!r)
11181118
return NULL;
11191119

@@ -1171,12 +1171,12 @@ static int match_explicit(struct ref *src, struct ref *dst,
11711171
return -1;
11721172

11731173
if (!dst_value) {
1174-
unsigned char sha1[20];
1174+
struct object_id oid;
11751175
int flag;
11761176

11771177
dst_value = resolve_ref_unsafe(matched_src->name,
11781178
RESOLVE_REF_READING,
1179-
sha1, &flag);
1179+
oid.hash, &flag);
11801180
if (!dst_value ||
11811181
((flag & REF_ISSYMREF) &&
11821182
!starts_with(dst_value, "refs/heads/")))
@@ -1292,13 +1292,13 @@ struct tips {
12921292
int nr, alloc;
12931293
};
12941294

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)
12961296
{
12971297
struct commit *commit;
12981298

1299-
if (is_null_sha1(sha1))
1299+
if (is_null_oid(oid))
13001300
return;
1301-
commit = lookup_commit_reference_gently(sha1, 1);
1301+
commit = lookup_commit_reference_gently(oid->hash, 1);
13021302
if (!commit || (commit->object.flags & TMP_MARK))
13031303
return;
13041304
commit->object.flags |= TMP_MARK;
@@ -1322,9 +1322,9 @@ static void add_missing_tags(struct ref *src, struct ref **dst, struct ref ***ds
13221322
for (ref = *dst; ref; ref = ref->next) {
13231323
if (ref->peer_ref &&
13241324
!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);
13261326
else
1327-
add_to_tips(&sent_tips, ref->old_oid.hash);
1327+
add_to_tips(&sent_tips, &ref->old_oid);
13281328
if (starts_with(ref->name, "refs/tags/"))
13291329
string_list_append(&dst_tag, ref->name);
13301330
}
@@ -1609,7 +1609,7 @@ static void set_merge(struct branch *ret)
16091609
{
16101610
struct remote *remote;
16111611
char *ref;
1612-
unsigned char sha1[20];
1612+
struct object_id oid;
16131613
int i;
16141614

16151615
if (!ret)
@@ -1635,7 +1635,7 @@ static void set_merge(struct branch *ret)
16351635
strcmp(ret->remote_name, "."))
16361636
continue;
16371637
if (dwim_ref(ret->merge_name[i], strlen(ret->merge_name[i]),
1638-
sha1, &ref) == 1)
1638+
oid.hash, &ref) == 1)
16391639
ret->merge[i]->dst = ref;
16401640
else
16411641
ret->merge[i]->dst = xstrdup(ret->merge_name[i]);
@@ -1795,10 +1795,10 @@ const char *branch_get_push(struct branch *branch, struct strbuf *err)
17951795

17961796
static int ignore_symref_update(const char *refname)
17971797
{
1798-
unsigned char sha1[20];
1798+
struct object_id oid;
17991799
int flag;
18001800

1801-
if (!resolve_ref_unsafe(refname, 0, sha1, &flag))
1801+
if (!resolve_ref_unsafe(refname, 0, oid.hash, &flag))
18021802
return 0; /* non-existing refs are OK */
18031803
return (flag & REF_ISSYMREF);
18041804
}
@@ -1995,7 +1995,7 @@ int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid)
19951995
int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
19961996
const char **upstream_name)
19971997
{
1998-
unsigned char sha1[20];
1998+
struct object_id oid;
19991999
struct commit *ours, *theirs;
20002000
struct rev_info revs;
20012001
const char *base;
@@ -2009,15 +2009,15 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
20092009
return -1;
20102010

20112011
/* 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))
20132013
return -1;
2014-
theirs = lookup_commit_reference(sha1);
2014+
theirs = lookup_commit_reference(oid.hash);
20152015
if (!theirs)
20162016
return -1;
20172017

2018-
if (read_ref(branch->refname, sha1))
2018+
if (read_ref(branch->refname, oid.hash))
20192019
return -1;
2020-
ours = lookup_commit_reference(sha1);
2020+
ours = lookup_commit_reference(oid.hash);
20212021
if (!ours)
20222022
return -1;
20232023

@@ -2328,14 +2328,14 @@ int is_empty_cas(const struct push_cas_option *cas)
23282328
* If we cannot do so, return negative to signal an error.
23292329
*/
23302330
static int remote_tracking(struct remote *remote, const char *refname,
2331-
unsigned char sha1[20])
2331+
struct object_id *oid)
23322332
{
23332333
char *dst;
23342334

23352335
dst = apply_refspecs(remote->fetch, remote->fetch_refspec_nr, refname);
23362336
if (!dst)
23372337
return -1; /* no tracking ref for refname at remote */
2338-
if (read_ref(dst, sha1))
2338+
if (read_ref(dst, oid->hash))
23392339
return -1; /* we know what the tracking ref is but we cannot read it */
23402340
return 0;
23412341
}
@@ -2354,7 +2354,7 @@ static void apply_cas(struct push_cas_option *cas,
23542354
ref->expect_old_sha1 = 1;
23552355
if (!entry->use_tracking)
23562356
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))
23582358
ref->expect_old_no_trackback = 1;
23592359
return;
23602360
}
@@ -2364,7 +2364,7 @@ static void apply_cas(struct push_cas_option *cas,
23642364
return;
23652365

23662366
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))
23682368
ref->expect_old_no_trackback = 1;
23692369
}
23702370

0 commit comments

Comments
 (0)