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 <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Oct 16, 2021 at 11:39 UTC 76887df01440018e1e757761fea81a4d3a676f25
4 files changed +36 -31
refs.c
+9 -11
@@ -290,20 +290,17 @@ struct ref_filter {
290 void *cb_data;
291 };
292
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)
294 {
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))
300 return 0;
301 return -1;
302 }
303
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 -
304 int read_ref(const char *refname, struct object_id *oid)
305 {
306 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)
1373 {
1374 struct object_id oid;
1375 int flag;
1376 + int ignore_errno;
1377
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))
1380 return fn("HEAD", &oid, flag, cb_data);
1381
1382 return 0;
refs.h
-2
@@ -89,8 +89,6 @@ char *refs_resolve_refdup(struct ref_store *refs,
89 char *resolve_refdup(const char *refname, int resolve_flags,
90 struct object_id *oid, int *flags);
91
92 -int refs_read_ref_full(struct ref_store *refs, const char *refname,
93 - int resolve_flags, struct object_id *oid, int *flags);
92 int read_ref_full(const char *refname, int resolve_flags,
93 struct object_id *oid, int *flags);
94 int read_ref(const char *refname, struct object_id *oid);
refs/files-backend.c
+22 -14
@@ -1006,6 +1006,7 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,
1006 {
1007 struct strbuf ref_file = STRBUF_INIT;
1008 struct ref_lock *lock;
1009 + int ignore_errno;
1010
1011 files_assert_main_repository(refs, "lock_ref_oid_basic");
1012 assert(err);
@@ -1032,9 +1033,8 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,
1033 goto error_return;
1034 }
1035
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))
1038 oidclr(&lock->old_oid);
1039 goto out;
1040
@@ -1397,6 +1397,7 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store,
1397 struct strbuf tmp_renamed_log = STRBUF_INIT;
1398 int log, ret;
1399 struct strbuf err = STRBUF_INIT;
1400 + int ignore_errno;
1401
1402 files_reflog_path(refs, &sb_oldref, oldrefname);
1403 files_reflog_path(refs, &sb_newref, newrefname);
@@ -1454,9 +1455,9 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store,
1455 * the safety anyway; we want to delete the reference whatever
1456 * its current value.
1457 */
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) &&
1461 refs_delete_ref(&refs->base, NULL, newrefname,
1462 NULL, REF_NO_DEREF)) {
1463 if (errno == EISDIR) {
@@ -1868,9 +1869,12 @@ static void update_symref_reflog(struct files_ref_store *refs,
1869 {
1870 struct strbuf err = STRBUF_INIT;
1871 struct object_id new_oid;
1872 + int ignore_errno;
1873 +
1874 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) &&
1878 files_log_ref_write(refs, refname, &lock->old_oid,
1879 &new_oid, logmsg, 0, &err)) {
1880 error("%s", err.buf);
@@ -2144,6 +2148,7 @@ static int files_reflog_iterator_advance(struct ref_iterator *ref_iterator)
2148 (struct files_reflog_iterator *)ref_iterator;
2149 struct dir_iterator *diter = iter->dir_iterator;
2150 int ok;
2151 + int ignore_errno;
2152
2153 while ((ok = dir_iterator_advance(diter)) == ITER_OK) {
2154 int flags;
@@ -2155,9 +2160,10 @@ static int files_reflog_iterator_advance(struct ref_iterator *ref_iterator)
2160 if (ends_with(diter->basename, ".lock"))
2161 continue;
2162
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)) {
2167 error("bad ref for %s", diter->path.buf);
2168 continue;
2169 }
@@ -2501,9 +2507,11 @@ static int lock_ref_for_update(struct files_ref_store *refs,
2507 * the transaction, so we have to read it here
2508 * to record and possibly check old_oid:
2509 */
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)) {
2515 if (update->flags & REF_HAVE_OLD) {
2516 strbuf_addf(err, "cannot lock ref '%s': "
2517 "error reading reference",
worktree.c
+5 -4
@@ -563,16 +563,17 @@ int other_head_refs(each_ref_fn fn, void *cb_data)
563 struct worktree *wt = *p;
564 struct object_id oid;
565 int flag;
566 + int ignore_errno;
567
568 if (wt->is_current)
569 continue;
570
571 strbuf_reset(&refname);
572 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))
577 ret = fn(refname.buf, &oid, flag, cb_data);
578 if (ret)
579 break;