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 <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Oct 15, 2017 at 22:07 UTC
49e61479be913f67e66bb3fdf8de9475c41b58bd
9 files changed
+36
-38
blame.c
+2
-2
@@ -166,7 +166,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
166
commit->date = now;
167
parent_tail = &commit->parents;
168
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))
170
die("no such ref: HEAD");
171
172
parent_tail = append_parent(parent_tail, &head_oid);
@@ -1689,7 +1689,7 @@ static struct commit *dwim_reverse_initial(struct rev_info *revs,
1689
return NULL;
1690
1691
/* 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))
1693
return NULL;
1694
head_commit = lookup_commit_reference_gently(&head_oid, 1);
1695
if (!head_commit)
builtin/fsck.c
+1
-1
@@ -555,7 +555,7 @@ static int fsck_head_link(void)
555
if (verbose)
556
fprintf(stderr, "Checking HEAD link\n");
557
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);
559
if (!head_points_at) {
560
errors_found |= ERROR_REFS;
561
return error("Invalid HEAD");
refs.c
+14
-15
@@ -199,7 +199,7 @@ char *refs_resolve_refdup(struct ref_store *refs,
199
const char *result;
200
201
result = refs_resolve_ref_unsafe(refs, refname, resolve_flags,
202
- oid->hash, flags);
202
+ oid, flags);
203
return xstrdup_or_null(result);
204
}
205
@@ -221,7 +221,7 @@ struct ref_filter {
221
int refs_read_ref_full(struct ref_store *refs, const char *refname,
222
int resolve_flags, struct object_id *oid, int *flags)
223
{
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))
225
return 0;
226
return -1;
227
}
@@ -480,8 +480,7 @@ int expand_ref(const char *str, int len, struct object_id *oid, char **ref)
480
strbuf_reset(&fullref);
481
strbuf_addf(&fullref, *p, len, str);
482
r = resolve_ref_unsafe(fullref.buf, RESOLVE_REF_READING,
483
- this_result ? this_result->hash : NULL,
484
- &flag);
483
+ this_result, &flag);
484
if (r) {
485
if (!refs_found++)
486
*ref = xstrdup(r);
@@ -512,7 +511,7 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **log)
511
strbuf_reset(&path);
512
strbuf_addf(&path, *p, len, str);
513
ref = resolve_ref_unsafe(path.buf, RESOLVE_REF_READING,
515
- hash.hash, NULL);
514
+ &hash, NULL);
515
if (!ref)
516
continue;
517
if (reflog_exists(path.buf))
@@ -1393,15 +1392,15 @@ int refs_read_raw_ref(struct ref_store *ref_store,
1392
const char *refs_resolve_ref_unsafe(struct ref_store *refs,
1393
const char *refname,
1394
int resolve_flags,
1396
- unsigned char *sha1, int *flags)
1395
+ struct object_id *oid, int *flags)
1396
{
1397
static struct strbuf sb_refname = STRBUF_INIT;
1398
struct object_id unused_oid;
1399
int unused_flags;
1400
int symref_count;
1401
1403
- if (!sha1)
1404
- sha1 = unused_oid.hash;
1402
+ if (!oid)
1403
+ oid = &unused_oid;
1404
if (!flags)
1405
flags = &unused_flags;
1406
@@ -1429,7 +1428,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
1428
unsigned int read_flags = 0;
1429
1430
if (refs_read_raw_ref(refs, refname,
1432
- sha1, &sb_refname, &read_flags)) {
1431
+ oid->hash, &sb_refname, &read_flags)) {
1432
*flags |= read_flags;
1433
1434
/* In reading mode, refs must eventually resolve */
@@ -1446,7 +1445,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
1445
errno != ENOTDIR)
1446
return NULL;
1447
1449
- hashclr(sha1);
1448
+ oidclr(oid);
1449
if (*flags & REF_BAD_NAME)
1450
*flags |= REF_ISBROKEN;
1451
return refname;
@@ -1456,7 +1455,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
1455
1456
if (!(read_flags & REF_ISSYMREF)) {
1457
if (*flags & REF_BAD_NAME) {
1459
- hashclr(sha1);
1458
+ oidclr(oid);
1459
*flags |= REF_ISBROKEN;
1460
}
1461
return refname;
@@ -1464,7 +1463,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
1463
1464
refname = sb_refname.buf;
1465
if (resolve_flags & RESOLVE_REF_NO_RECURSE) {
1467
- hashclr(sha1);
1466
+ oidclr(oid);
1467
return refname;
1468
}
1469
if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) {
@@ -1491,10 +1490,10 @@ int refs_init_db(struct strbuf *err)
1490
}
1491
1492
const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
1494
- unsigned char *sha1, int *flags)
1493
+ struct object_id *oid, int *flags)
1494
{
1495
return refs_resolve_ref_unsafe(get_main_ref_store(), refname,
1497
- resolve_flags, sha1, flags);
1496
+ resolve_flags, oid, flags);
1497
}
1498
1499
int resolve_gitlink_ref(const char *submodule, const char *refname,
@@ -1508,7 +1507,7 @@ int resolve_gitlink_ref(const char *submodule, const char *refname,
1507
if (!refs)
1508
return -1;
1509
1511
- if (!refs_resolve_ref_unsafe(refs, refname, 0, oid->hash, &flags) ||
1510
+ if (!refs_resolve_ref_unsafe(refs, refname, 0, oid, &flags) ||
1511
is_null_oid(oid))
1512
return -1;
1513
return 0;
refs.h
+7
-7
@@ -14,22 +14,22 @@ struct worktree;
14
* at the resolved object name. The return value, if not NULL, is a
15
* pointer into either a static buffer or the input ref.
16
*
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.
18
*
19
* If the reference cannot be resolved to an object, the behavior
20
* depends on the RESOLVE_REF_READING flag:
21
*
22
* - If RESOLVE_REF_READING is set, return NULL.
23
*
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
25
* the last reference name in the chain, which will either be a non-symbolic
26
* reference or an undefined reference. If this is a prelude to
27
* "writing" to the ref, the return value is the name of the ref
28
* that will actually be created or changed.
29
*
30
* 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
33
* value is the reference that the symref refers to directly.
34
*
35
* If flags is non-NULL, set the value that it points to the
@@ -46,7 +46,7 @@ struct worktree;
46
*
47
* RESOLVE_REF_ALLOW_BAD_NAME allows resolving refs even when their
48
* 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
50
* flags REF_ISBROKEN and REF_BAD_NAME will be set.
51
*
52
* Even with RESOLVE_REF_ALLOW_BAD_NAME, names that escape the refs/
@@ -62,10 +62,10 @@ struct worktree;
62
const char *refs_resolve_ref_unsafe(struct ref_store *refs,
63
const char *refname,
64
int resolve_flags,
65
- unsigned char *sha1,
65
+ struct object_id *oid,
66
int *flags);
67
const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
68
- unsigned char *sha1, int *flags);
68
+ struct object_id *oid, int *flags);
69
70
char *refs_resolve_refdup(struct ref_store *refs,
71
const char *refname, int resolve_flags,
refs/files-backend.c
+4
-4
@@ -189,7 +189,7 @@ static void loose_fill_ref_dir(struct ref_store *ref_store,
189
if (!refs_resolve_ref_unsafe(&refs->base,
190
refname.buf,
191
RESOLVE_REF_READING,
192
- oid.hash, &flag)) {
192
+ &oid, &flag)) {
193
oidclr(&oid);
194
flag |= REF_ISBROKEN;
195
} else if (is_null_oid(&oid)) {
@@ -855,7 +855,7 @@ static struct ref_lock *lock_ref_sha1_basic(struct files_ref_store *refs,
855
files_ref_path(refs, &ref_file, refname);
856
resolved = !!refs_resolve_ref_unsafe(&refs->base,
857
refname, resolve_flags,
858
- lock->old_oid.hash, type);
858
+ &lock->old_oid, type);
859
if (!resolved && errno == EISDIR) {
860
/*
861
* 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,
874
}
875
resolved = !!refs_resolve_ref_unsafe(&refs->base,
876
refname, resolve_flags,
877
- lock->old_oid.hash, type);
877
+ &lock->old_oid, type);
878
}
879
if (!resolved) {
880
last_errno = errno;
@@ -1251,7 +1251,7 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store,
1251
1252
if (!refs_resolve_ref_unsafe(&refs->base, oldrefname,
1253
RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
1254
- orig_oid.hash, &flag)) {
1254
+ &orig_oid, &flag)) {
1255
ret = error("refname %s not found", oldrefname);
1256
goto out;
1257
}
sequencer.c
+1
-1
@@ -489,7 +489,7 @@ static int is_index_unchanged(void)
489
struct object_id head_oid;
490
struct commit *head_commit;
491
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))
493
return error(_("could not resolve HEAD commit\n"));
494
495
head_commit = lookup_commit(&head_oid);
t/helper/test-ref-store.c
+3
-3
@@ -127,15 +127,15 @@ static int cmd_for_each_ref(struct ref_store *refs, const char **argv)
127
128
static int cmd_resolve_ref(struct ref_store *refs, const char **argv)
129
{
130
- unsigned char sha1[20];
130
+ struct object_id oid;
131
const char *refname = notnull(*argv++, "refname");
132
int resolve_flags = arg_flags(*argv++, "resolve-flags");
133
int flags;
134
const char *ref;
135
136
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);
139
return ref ? 0 : 1;
140
}
141
transport-helper.c
+3
-4
@@ -942,10 +942,9 @@ static int push_refs_with_export(struct transport *transport,
942
int flag;
943
944
/* 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);
948
if (!name || !(flag & REF_ISSYMREF))
949
name = ref->peer_ref->name;
950
worktree.c
+1
-1
@@ -31,7 +31,7 @@ static void add_head_info(struct worktree *wt)
31
target = refs_resolve_ref_unsafe(get_worktree_ref_store(wt),
32
"HEAD",
33
0,
34
- wt->head_oid.hash, &flags);
34
+ &wt->head_oid, &flags);
35
if (!target)
36
return;
37