Skip to content

Commit 49e6147

Browse files
bk2204gitster
authored andcommitted
refs: convert resolve_ref_unsafe to struct object_id
Convert resolve_ref_unsafe to take a pointer to struct object_id by converting one remaining caller to use struct object_id, removing the temporary NULL pointer check in expand_ref, converting the declaration and definition, and applying the following semantic patch: @@ expression E1, E2, E3, E4; @@ - resolve_ref_unsafe(E1, E2, E3.hash, E4) + resolve_ref_unsafe(E1, E2, &E3, E4) @@ expression E1, E2, E3, E4; @@ - resolve_ref_unsafe(E1, E2, E3->hash, E4) + resolve_ref_unsafe(E1, E2, E3, E4) Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0f05154 commit 49e6147

File tree

9 files changed

+36
-38
lines changed

9 files changed

+36
-38
lines changed

blame.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
166166
commit->date = now;
167167
parent_tail = &commit->parents;
168168

169-
if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, head_oid.hash, NULL))
169+
if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, &head_oid, NULL))
170170
die("no such ref: HEAD");
171171

172172
parent_tail = append_parent(parent_tail, &head_oid);
@@ -1689,7 +1689,7 @@ static struct commit *dwim_reverse_initial(struct rev_info *revs,
16891689
return NULL;
16901690

16911691
/* Do we have HEAD? */
1692-
if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, head_oid.hash, NULL))
1692+
if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, &head_oid, NULL))
16931693
return NULL;
16941694
head_commit = lookup_commit_reference_gently(&head_oid, 1);
16951695
if (!head_commit)

builtin/fsck.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ static int fsck_head_link(void)
555555
if (verbose)
556556
fprintf(stderr, "Checking HEAD link\n");
557557

558-
head_points_at = resolve_ref_unsafe("HEAD", 0, head_oid.hash, NULL);
558+
head_points_at = resolve_ref_unsafe("HEAD", 0, &head_oid, NULL);
559559
if (!head_points_at) {
560560
errors_found |= ERROR_REFS;
561561
return error("Invalid HEAD");

refs.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ char *refs_resolve_refdup(struct ref_store *refs,
199199
const char *result;
200200

201201
result = refs_resolve_ref_unsafe(refs, refname, resolve_flags,
202-
oid->hash, flags);
202+
oid, flags);
203203
return xstrdup_or_null(result);
204204
}
205205

@@ -221,7 +221,7 @@ struct ref_filter {
221221
int refs_read_ref_full(struct ref_store *refs, const char *refname,
222222
int resolve_flags, struct object_id *oid, int *flags)
223223
{
224-
if (refs_resolve_ref_unsafe(refs, refname, resolve_flags, oid->hash, flags))
224+
if (refs_resolve_ref_unsafe(refs, refname, resolve_flags, oid, flags))
225225
return 0;
226226
return -1;
227227
}
@@ -480,8 +480,7 @@ int expand_ref(const char *str, int len, struct object_id *oid, char **ref)
480480
strbuf_reset(&fullref);
481481
strbuf_addf(&fullref, *p, len, str);
482482
r = resolve_ref_unsafe(fullref.buf, RESOLVE_REF_READING,
483-
this_result ? this_result->hash : NULL,
484-
&flag);
483+
this_result, &flag);
485484
if (r) {
486485
if (!refs_found++)
487486
*ref = xstrdup(r);
@@ -512,7 +511,7 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **log)
512511
strbuf_reset(&path);
513512
strbuf_addf(&path, *p, len, str);
514513
ref = resolve_ref_unsafe(path.buf, RESOLVE_REF_READING,
515-
hash.hash, NULL);
514+
&hash, NULL);
516515
if (!ref)
517516
continue;
518517
if (reflog_exists(path.buf))
@@ -1393,15 +1392,15 @@ int refs_read_raw_ref(struct ref_store *ref_store,
13931392
const char *refs_resolve_ref_unsafe(struct ref_store *refs,
13941393
const char *refname,
13951394
int resolve_flags,
1396-
unsigned char *sha1, int *flags)
1395+
struct object_id *oid, int *flags)
13971396
{
13981397
static struct strbuf sb_refname = STRBUF_INIT;
13991398
struct object_id unused_oid;
14001399
int unused_flags;
14011400
int symref_count;
14021401

1403-
if (!sha1)
1404-
sha1 = unused_oid.hash;
1402+
if (!oid)
1403+
oid = &unused_oid;
14051404
if (!flags)
14061405
flags = &unused_flags;
14071406

@@ -1429,7 +1428,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
14291428
unsigned int read_flags = 0;
14301429

14311430
if (refs_read_raw_ref(refs, refname,
1432-
sha1, &sb_refname, &read_flags)) {
1431+
oid->hash, &sb_refname, &read_flags)) {
14331432
*flags |= read_flags;
14341433

14351434
/* In reading mode, refs must eventually resolve */
@@ -1446,7 +1445,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
14461445
errno != ENOTDIR)
14471446
return NULL;
14481447

1449-
hashclr(sha1);
1448+
oidclr(oid);
14501449
if (*flags & REF_BAD_NAME)
14511450
*flags |= REF_ISBROKEN;
14521451
return refname;
@@ -1456,15 +1455,15 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
14561455

14571456
if (!(read_flags & REF_ISSYMREF)) {
14581457
if (*flags & REF_BAD_NAME) {
1459-
hashclr(sha1);
1458+
oidclr(oid);
14601459
*flags |= REF_ISBROKEN;
14611460
}
14621461
return refname;
14631462
}
14641463

14651464
refname = sb_refname.buf;
14661465
if (resolve_flags & RESOLVE_REF_NO_RECURSE) {
1467-
hashclr(sha1);
1466+
oidclr(oid);
14681467
return refname;
14691468
}
14701469
if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) {
@@ -1491,10 +1490,10 @@ int refs_init_db(struct strbuf *err)
14911490
}
14921491

14931492
const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
1494-
unsigned char *sha1, int *flags)
1493+
struct object_id *oid, int *flags)
14951494
{
14961495
return refs_resolve_ref_unsafe(get_main_ref_store(), refname,
1497-
resolve_flags, sha1, flags);
1496+
resolve_flags, oid, flags);
14981497
}
14991498

15001499
int resolve_gitlink_ref(const char *submodule, const char *refname,
@@ -1508,7 +1507,7 @@ int resolve_gitlink_ref(const char *submodule, const char *refname,
15081507
if (!refs)
15091508
return -1;
15101509

1511-
if (!refs_resolve_ref_unsafe(refs, refname, 0, oid->hash, &flags) ||
1510+
if (!refs_resolve_ref_unsafe(refs, refname, 0, oid, &flags) ||
15121511
is_null_oid(oid))
15131512
return -1;
15141513
return 0;

refs.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@ struct worktree;
1414
* at the resolved object name. The return value, if not NULL, is a
1515
* pointer into either a static buffer or the input ref.
1616
*
17-
* If sha1 is non-NULL, store the referred-to object's name in it.
17+
* If oid is non-NULL, store the referred-to object's name in it.
1818
*
1919
* If the reference cannot be resolved to an object, the behavior
2020
* depends on the RESOLVE_REF_READING flag:
2121
*
2222
* - If RESOLVE_REF_READING is set, return NULL.
2323
*
24-
* - If RESOLVE_REF_READING is not set, clear sha1 and return the name of
24+
* - If RESOLVE_REF_READING is not set, clear oid and return the name of
2525
* the last reference name in the chain, which will either be a non-symbolic
2626
* reference or an undefined reference. If this is a prelude to
2727
* "writing" to the ref, the return value is the name of the ref
2828
* that will actually be created or changed.
2929
*
3030
* If the RESOLVE_REF_NO_RECURSE flag is passed, only resolves one
31-
* level of symbolic reference. The value stored in sha1 for a symbolic
32-
* reference will always be null_sha1 in this case, and the return
31+
* level of symbolic reference. The value stored in oid for a symbolic
32+
* reference will always be null_oid in this case, and the return
3333
* value is the reference that the symref refers to directly.
3434
*
3535
* If flags is non-NULL, set the value that it points to the
@@ -46,7 +46,7 @@ struct worktree;
4646
*
4747
* RESOLVE_REF_ALLOW_BAD_NAME allows resolving refs even when their
4848
* name is invalid according to git-check-ref-format(1). If the name
49-
* is bad then the value stored in sha1 will be null_sha1 and the two
49+
* is bad then the value stored in oid will be null_oid and the two
5050
* flags REF_ISBROKEN and REF_BAD_NAME will be set.
5151
*
5252
* Even with RESOLVE_REF_ALLOW_BAD_NAME, names that escape the refs/
@@ -62,10 +62,10 @@ struct worktree;
6262
const char *refs_resolve_ref_unsafe(struct ref_store *refs,
6363
const char *refname,
6464
int resolve_flags,
65-
unsigned char *sha1,
65+
struct object_id *oid,
6666
int *flags);
6767
const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
68-
unsigned char *sha1, int *flags);
68+
struct object_id *oid, int *flags);
6969

7070
char *refs_resolve_refdup(struct ref_store *refs,
7171
const char *refname, int resolve_flags,

refs/files-backend.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ static void loose_fill_ref_dir(struct ref_store *ref_store,
189189
if (!refs_resolve_ref_unsafe(&refs->base,
190190
refname.buf,
191191
RESOLVE_REF_READING,
192-
oid.hash, &flag)) {
192+
&oid, &flag)) {
193193
oidclr(&oid);
194194
flag |= REF_ISBROKEN;
195195
} else if (is_null_oid(&oid)) {
@@ -855,7 +855,7 @@ static struct ref_lock *lock_ref_sha1_basic(struct files_ref_store *refs,
855855
files_ref_path(refs, &ref_file, refname);
856856
resolved = !!refs_resolve_ref_unsafe(&refs->base,
857857
refname, resolve_flags,
858-
lock->old_oid.hash, type);
858+
&lock->old_oid, type);
859859
if (!resolved && errno == EISDIR) {
860860
/*
861861
* we are trying to lock foo but we used to
@@ -874,7 +874,7 @@ static struct ref_lock *lock_ref_sha1_basic(struct files_ref_store *refs,
874874
}
875875
resolved = !!refs_resolve_ref_unsafe(&refs->base,
876876
refname, resolve_flags,
877-
lock->old_oid.hash, type);
877+
&lock->old_oid, type);
878878
}
879879
if (!resolved) {
880880
last_errno = errno;
@@ -1251,7 +1251,7 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store,
12511251

12521252
if (!refs_resolve_ref_unsafe(&refs->base, oldrefname,
12531253
RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
1254-
orig_oid.hash, &flag)) {
1254+
&orig_oid, &flag)) {
12551255
ret = error("refname %s not found", oldrefname);
12561256
goto out;
12571257
}

sequencer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ static int is_index_unchanged(void)
489489
struct object_id head_oid;
490490
struct commit *head_commit;
491491

492-
if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, head_oid.hash, NULL))
492+
if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, &head_oid, NULL))
493493
return error(_("could not resolve HEAD commit\n"));
494494

495495
head_commit = lookup_commit(&head_oid);

t/helper/test-ref-store.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,15 @@ static int cmd_for_each_ref(struct ref_store *refs, const char **argv)
127127

128128
static int cmd_resolve_ref(struct ref_store *refs, const char **argv)
129129
{
130-
unsigned char sha1[20];
130+
struct object_id oid;
131131
const char *refname = notnull(*argv++, "refname");
132132
int resolve_flags = arg_flags(*argv++, "resolve-flags");
133133
int flags;
134134
const char *ref;
135135

136136
ref = refs_resolve_ref_unsafe(refs, refname, resolve_flags,
137-
sha1, &flags);
138-
printf("%s %s 0x%x\n", sha1_to_hex(sha1), ref, flags);
137+
&oid, &flags);
138+
printf("%s %s 0x%x\n", oid_to_hex(&oid), ref, flags);
139139
return ref ? 0 : 1;
140140
}
141141

transport-helper.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -942,10 +942,9 @@ static int push_refs_with_export(struct transport *transport,
942942
int flag;
943943

944944
/* Follow symbolic refs (mainly for HEAD). */
945-
name = resolve_ref_unsafe(
946-
ref->peer_ref->name,
947-
RESOLVE_REF_READING,
948-
oid.hash, &flag);
945+
name = resolve_ref_unsafe(ref->peer_ref->name,
946+
RESOLVE_REF_READING,
947+
&oid, &flag);
949948
if (!name || !(flag & REF_ISSYMREF))
950949
name = ref->peer_ref->name;
951950

worktree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static void add_head_info(struct worktree *wt)
3131
target = refs_resolve_ref_unsafe(get_worktree_ref_store(wt),
3232
"HEAD",
3333
0,
34-
wt->head_oid.hash, &flags);
34+
&wt->head_oid, &flags);
3535
if (!target)
3636
return;
3737

0 commit comments

Comments
 (0)