refs/files: remove unused "oid" in lock_ref_oid_basic()

In the preceding commit the last caller that passed a non-NULL OID was changed to pass NULL to lock_ref_oid_basic(). As noted in preceding commits use of this API has been going away (we should use ref transactions, or lock_raw_ref()), so we're unlikely to gain new callers that want to pass the "oid". So let's remove it, doing so means we can remove the "mustexist" condition, and therefore anything except the "flags = RESOLVE_REF_NO_RECURSE" case. Furthermore, since the verify_lock() function we called did most of its work when the "oid" was passed (as "old_oid") we can inline the trivial part of it that remains in its only remaining caller. Without a NULL "oid" passed it was equivalent to calling refs_read_ref_full() followed by oidclr(). Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Aug 23, 2021 at 13:36 UTC ff7a2e4dbb0cf3844fbd0fbab7fba95d8e47c8dd
1 file changed +14 -56
refs/files-backend.c
+14 -56
@@ -852,42 +852,6 @@ static struct ref_iterator *files_ref_iterator_begin(
852 return ref_iterator;
853 }
854
855 -/*
856 - * Verify that the reference locked by lock has the value old_oid
857 - * (unless it is NULL). Fail if the reference doesn't exist and
858 - * mustexist is set. Return 0 on success. On error, write an error
859 - * message to err, set errno, and return a negative value.
860 - */
861 -static int verify_lock(struct ref_store *ref_store, struct ref_lock *lock,
862 - const struct object_id *old_oid, int mustexist,
863 - struct strbuf *err)
864 -{
865 - assert(err);
866 -
867 - if (refs_read_ref_full(ref_store, lock->ref_name,
868 - mustexist ? RESOLVE_REF_READING : 0,
869 - &lock->old_oid, NULL)) {
870 - if (old_oid) {
871 - int save_errno = errno;
872 - strbuf_addf(err, "can't verify ref '%s'", lock->ref_name);
873 - errno = save_errno;
874 - return -1;
875 - } else {
876 - oidclr(&lock->old_oid);
877 - return 0;
878 - }
879 - }
880 - if (old_oid && !oideq(&lock->old_oid, old_oid)) {
881 - strbuf_addf(err, "ref '%s' is at %s but expected %s",
882 - lock->ref_name,
883 - oid_to_hex(&lock->old_oid),
884 - oid_to_hex(old_oid));
885 - errno = EBUSY;
886 - return -1;
887 - }
888 - return 0;
889 -}
890 -
855 static int remove_empty_directories(struct strbuf *path)
856 {
857 /*
@@ -912,15 +876,12 @@ static int create_reflock(const char *path, void *cb)
876 * On failure errno is set to something meaningful.
877 */
878 static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,
915 - const char *refname,
916 - const struct object_id *old_oid,
917 - int *type, struct strbuf *err)
879 + const char *refname, int *type,
880 + struct strbuf *err)
881 {
882 struct strbuf ref_file = STRBUF_INIT;
883 struct ref_lock *lock;
884 int last_errno = 0;
922 - int mustexist = (old_oid && !is_null_oid(old_oid));
923 - int resolve_flags = RESOLVE_REF_NO_RECURSE;
885 int resolved;
886
887 files_assert_main_repository(refs, "lock_ref_oid_basic");
@@ -928,12 +889,9 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,
889
890 CALLOC_ARRAY(lock, 1);
891
931 - if (mustexist)
932 - resolve_flags |= RESOLVE_REF_READING;
933 -
892 files_ref_path(refs, &ref_file, refname);
935 - resolved = !!refs_resolve_ref_unsafe(&refs->base,
936 - refname, resolve_flags,
893 + resolved = !!refs_resolve_ref_unsafe(&refs->base, refname,
894 + RESOLVE_REF_NO_RECURSE,
895 &lock->old_oid, type);
896 if (!resolved && errno == EISDIR) {
897 /*
@@ -951,8 +909,8 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,
909 refname);
910 goto error_return;
911 }
954 - resolved = !!refs_resolve_ref_unsafe(&refs->base,
955 - refname, resolve_flags,
912 + resolved = !!refs_resolve_ref_unsafe(&refs->base, refname,
913 + RESOLVE_REF_NO_RECURSE,
914 &lock->old_oid, type);
915 }
916 if (!resolved) {
@@ -987,10 +945,10 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,
945 goto error_return;
946 }
947
990 - if (verify_lock(&refs->base, lock, old_oid, mustexist, err)) {
991 - last_errno = errno;
992 - goto error_return;
993 - }
948 + if (refs_read_ref_full(&refs->base, lock->ref_name,
949 + 0,
950 + &lock->old_oid, NULL))
951 + oidclr(&lock->old_oid);
952 goto out;
953
954 error_return:
@@ -1409,7 +1367,7 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store,
1367
1368 logmoved = log;
1369
1412 - lock = lock_ref_oid_basic(refs, newrefname, NULL, NULL, &err);
1370 + lock = lock_ref_oid_basic(refs, newrefname, NULL, &err);
1371 if (!lock) {
1372 if (copy)
1373 error("unable to copy '%s' to '%s': %s", oldrefname, newrefname, err.buf);
@@ -1431,7 +1389,7 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store,
1389 goto out;
1390
1391 rollback:
1434 - lock = lock_ref_oid_basic(refs, oldrefname, NULL, NULL, &err);
1392 + lock = lock_ref_oid_basic(refs, oldrefname, NULL, &err);
1393 if (!lock) {
1394 error("unable to lock %s for rollback: %s", oldrefname, err.buf);
1395 strbuf_release(&err);
@@ -1838,7 +1796,7 @@ static int files_create_symref(struct ref_store *ref_store,
1796 struct ref_lock *lock;
1797 int ret;
1798
1841 - lock = lock_ref_oid_basic(refs, refname, NULL, NULL, &err);
1799 + lock = lock_ref_oid_basic(refs, refname, NULL, &err);
1800 if (!lock) {
1801 error("%s", err.buf);
1802 strbuf_release(&err);
@@ -3056,7 +3014,7 @@ static int files_reflog_expire(struct ref_store *ref_store,
3014 * reference itself, plus we might need to update the
3015 * reference if --updateref was specified:
3016 */
3059 - lock = lock_ref_oid_basic(refs, refname, NULL, &type, &err);
3017 + lock = lock_ref_oid_basic(refs, refname, &type, &err);
3018 if (!lock) {
3019 error("cannot lock ref '%s': %s", refname, err.buf);
3020 strbuf_release(&err);