Skip to content

Commit 76887df

Browse files
avargitster
authored andcommitted
refs API: remove refs_read_ref_full() wrapper
Remove the refs_read_ref_full() wrapper in favor of migrating various refs.c API users to the underlying refs_werrres_ref_unsafe() function. A careful reading of these callers shows that the callers of this function did not care about "errno", by moving away from the refs_resolve_ref_unsafe() wrapper we can be sure that nothing relies on it anymore. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5210643 commit 76887df

File tree

4 files changed

+36
-31
lines changed

4 files changed

+36
-31
lines changed

refs.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -290,20 +290,17 @@ struct ref_filter {
290290
void *cb_data;
291291
};
292292

293-
int refs_read_ref_full(struct ref_store *refs, const char *refname,
294-
int resolve_flags, struct object_id *oid, int *flags)
293+
int read_ref_full(const char *refname, int resolve_flags, struct object_id *oid, int *flags)
295294
{
296-
if (refs_resolve_ref_unsafe(refs, refname, resolve_flags, oid, flags))
295+
int ignore_errno;
296+
struct ref_store *refs = get_main_ref_store(the_repository);
297+
298+
if (refs_werrres_ref_unsafe(refs, refname, resolve_flags,
299+
oid, flags, &ignore_errno))
297300
return 0;
298301
return -1;
299302
}
300303

301-
int read_ref_full(const char *refname, int resolve_flags, struct object_id *oid, int *flags)
302-
{
303-
return refs_read_ref_full(get_main_ref_store(the_repository), refname,
304-
resolve_flags, oid, flags);
305-
}
306-
307304
int read_ref(const char *refname, struct object_id *oid)
308305
{
309306
return read_ref_full(refname, RESOLVE_REF_READING, oid, NULL);
@@ -1376,9 +1373,10 @@ int refs_head_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data)
13761373
{
13771374
struct object_id oid;
13781375
int flag;
1376+
int ignore_errno;
13791377

1380-
if (!refs_read_ref_full(refs, "HEAD", RESOLVE_REF_READING,
1381-
&oid, &flag))
1378+
if (refs_werrres_ref_unsafe(refs, "HEAD", RESOLVE_REF_READING,
1379+
&oid, &flag, &ignore_errno))
13821380
return fn("HEAD", &oid, flag, cb_data);
13831381

13841382
return 0;

refs.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ char *refs_resolve_refdup(struct ref_store *refs,
8989
char *resolve_refdup(const char *refname, int resolve_flags,
9090
struct object_id *oid, int *flags);
9191

92-
int refs_read_ref_full(struct ref_store *refs, const char *refname,
93-
int resolve_flags, struct object_id *oid, int *flags);
9492
int read_ref_full(const char *refname, int resolve_flags,
9593
struct object_id *oid, int *flags);
9694
int read_ref(const char *refname, struct object_id *oid);

refs/files-backend.c

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,7 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,
10061006
{
10071007
struct strbuf ref_file = STRBUF_INIT;
10081008
struct ref_lock *lock;
1009+
int ignore_errno;
10091010

10101011
files_assert_main_repository(refs, "lock_ref_oid_basic");
10111012
assert(err);
@@ -1032,9 +1033,8 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,
10321033
goto error_return;
10331034
}
10341035

1035-
if (refs_read_ref_full(&refs->base, lock->ref_name,
1036-
0,
1037-
&lock->old_oid, NULL))
1036+
if (!refs_werrres_ref_unsafe(&refs->base, lock->ref_name, 0,
1037+
&lock->old_oid, NULL, &ignore_errno))
10381038
oidclr(&lock->old_oid);
10391039
goto out;
10401040

@@ -1397,6 +1397,7 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store,
13971397
struct strbuf tmp_renamed_log = STRBUF_INIT;
13981398
int log, ret;
13991399
struct strbuf err = STRBUF_INIT;
1400+
int ignore_errno;
14001401

14011402
files_reflog_path(refs, &sb_oldref, oldrefname);
14021403
files_reflog_path(refs, &sb_newref, newrefname);
@@ -1454,9 +1455,9 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store,
14541455
* the safety anyway; we want to delete the reference whatever
14551456
* its current value.
14561457
*/
1457-
if (!copy && !refs_read_ref_full(&refs->base, newrefname,
1458-
RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
1459-
NULL, NULL) &&
1458+
if (!copy && refs_werrres_ref_unsafe(&refs->base, newrefname,
1459+
RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
1460+
NULL, NULL, &ignore_errno) &&
14601461
refs_delete_ref(&refs->base, NULL, newrefname,
14611462
NULL, REF_NO_DEREF)) {
14621463
if (errno == EISDIR) {
@@ -1868,9 +1869,12 @@ static void update_symref_reflog(struct files_ref_store *refs,
18681869
{
18691870
struct strbuf err = STRBUF_INIT;
18701871
struct object_id new_oid;
1872+
int ignore_errno;
1873+
18711874
if (logmsg &&
1872-
!refs_read_ref_full(&refs->base, target,
1873-
RESOLVE_REF_READING, &new_oid, NULL) &&
1875+
refs_werrres_ref_unsafe(&refs->base, target,
1876+
RESOLVE_REF_READING, &new_oid, NULL,
1877+
&ignore_errno) &&
18741878
files_log_ref_write(refs, refname, &lock->old_oid,
18751879
&new_oid, logmsg, 0, &err)) {
18761880
error("%s", err.buf);
@@ -2144,6 +2148,7 @@ static int files_reflog_iterator_advance(struct ref_iterator *ref_iterator)
21442148
(struct files_reflog_iterator *)ref_iterator;
21452149
struct dir_iterator *diter = iter->dir_iterator;
21462150
int ok;
2151+
int ignore_errno;
21472152

21482153
while ((ok = dir_iterator_advance(diter)) == ITER_OK) {
21492154
int flags;
@@ -2155,9 +2160,10 @@ static int files_reflog_iterator_advance(struct ref_iterator *ref_iterator)
21552160
if (ends_with(diter->basename, ".lock"))
21562161
continue;
21572162

2158-
if (refs_read_ref_full(iter->ref_store,
2159-
diter->relative_path, 0,
2160-
&iter->oid, &flags)) {
2163+
if (!refs_werrres_ref_unsafe(iter->ref_store,
2164+
diter->relative_path, 0,
2165+
&iter->oid, &flags,
2166+
&ignore_errno)) {
21612167
error("bad ref for %s", diter->path.buf);
21622168
continue;
21632169
}
@@ -2501,9 +2507,11 @@ static int lock_ref_for_update(struct files_ref_store *refs,
25012507
* the transaction, so we have to read it here
25022508
* to record and possibly check old_oid:
25032509
*/
2504-
if (refs_read_ref_full(&refs->base,
2505-
referent.buf, 0,
2506-
&lock->old_oid, NULL)) {
2510+
int ignore_errno;
2511+
if (!refs_werrres_ref_unsafe(&refs->base,
2512+
referent.buf, 0,
2513+
&lock->old_oid, NULL,
2514+
&ignore_errno)) {
25072515
if (update->flags & REF_HAVE_OLD) {
25082516
strbuf_addf(err, "cannot lock ref '%s': "
25092517
"error reading reference",

worktree.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -563,16 +563,17 @@ int other_head_refs(each_ref_fn fn, void *cb_data)
563563
struct worktree *wt = *p;
564564
struct object_id oid;
565565
int flag;
566+
int ignore_errno;
566567

567568
if (wt->is_current)
568569
continue;
569570

570571
strbuf_reset(&refname);
571572
strbuf_worktree_ref(wt, &refname, "HEAD");
572-
if (!refs_read_ref_full(get_main_ref_store(the_repository),
573-
refname.buf,
574-
RESOLVE_REF_READING,
575-
&oid, &flag))
573+
if (refs_werrres_ref_unsafe(get_main_ref_store(the_repository),
574+
refname.buf,
575+
RESOLVE_REF_READING,
576+
&oid, &flag, &ignore_errno))
576577
ret = fn(refname.buf, &oid, flag, cb_data);
577578
if (ret)
578579
break;

0 commit comments

Comments
 (0)