Skip to content

Commit 4f01e50

Browse files
bk2204gitster
authored andcommitted
refs/files-backend: convert static functions to object_id
Convert several static functions to take pointers to struct object_id. Change the relevant parameters to write_packed_entry to be const, as we don't modify them. Rename lock_ref_sha1_basic to lock_ref_oid_basic to reflect its new argument. Update the docstring for verify lock to account for the new parameter name, and note additionally that the old_oid may be NULL. Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 99afe91 commit 4f01e50

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

refs/files-backend.c

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -770,21 +770,21 @@ static struct ref_iterator *files_ref_iterator_begin(
770770
}
771771

772772
/*
773-
* Verify that the reference locked by lock has the value old_sha1.
774-
* Fail if the reference doesn't exist and mustexist is set. Return 0
775-
* on success. On error, write an error message to err, set errno, and
776-
* return a negative value.
773+
* Verify that the reference locked by lock has the value old_oid
774+
* (unless it is NULL). Fail if the reference doesn't exist and
775+
* mustexist is set. Return 0 on success. On error, write an error
776+
* message to err, set errno, and return a negative value.
777777
*/
778778
static int verify_lock(struct ref_store *ref_store, struct ref_lock *lock,
779-
const unsigned char *old_sha1, int mustexist,
779+
const struct object_id *old_oid, int mustexist,
780780
struct strbuf *err)
781781
{
782782
assert(err);
783783

784784
if (refs_read_ref_full(ref_store, lock->ref_name,
785785
mustexist ? RESOLVE_REF_READING : 0,
786786
&lock->old_oid, NULL)) {
787-
if (old_sha1) {
787+
if (old_oid) {
788788
int save_errno = errno;
789789
strbuf_addf(err, "can't verify ref '%s'", lock->ref_name);
790790
errno = save_errno;
@@ -794,11 +794,11 @@ static int verify_lock(struct ref_store *ref_store, struct ref_lock *lock,
794794
return 0;
795795
}
796796
}
797-
if (old_sha1 && hashcmp(lock->old_oid.hash, old_sha1)) {
797+
if (old_oid && oidcmp(&lock->old_oid, old_oid)) {
798798
strbuf_addf(err, "ref '%s' is at %s but expected %s",
799799
lock->ref_name,
800800
oid_to_hex(&lock->old_oid),
801-
sha1_to_hex(old_sha1));
801+
oid_to_hex(old_oid));
802802
errno = EBUSY;
803803
return -1;
804804
}
@@ -828,22 +828,22 @@ static int create_reflock(const char *path, void *cb)
828828
* Locks a ref returning the lock on success and NULL on failure.
829829
* On failure errno is set to something meaningful.
830830
*/
831-
static struct ref_lock *lock_ref_sha1_basic(struct files_ref_store *refs,
832-
const char *refname,
833-
const unsigned char *old_sha1,
834-
const struct string_list *extras,
835-
const struct string_list *skip,
836-
unsigned int flags, int *type,
837-
struct strbuf *err)
831+
static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,
832+
const char *refname,
833+
const struct object_id *old_oid,
834+
const struct string_list *extras,
835+
const struct string_list *skip,
836+
unsigned int flags, int *type,
837+
struct strbuf *err)
838838
{
839839
struct strbuf ref_file = STRBUF_INIT;
840840
struct ref_lock *lock;
841841
int last_errno = 0;
842-
int mustexist = (old_sha1 && !is_null_sha1(old_sha1));
842+
int mustexist = (old_oid && !is_null_oid(old_oid));
843843
int resolve_flags = RESOLVE_REF_NO_RECURSE;
844844
int resolved;
845845

846-
files_assert_main_repository(refs, "lock_ref_sha1_basic");
846+
files_assert_main_repository(refs, "lock_ref_oid_basic");
847847
assert(err);
848848

849849
lock = xcalloc(1, sizeof(struct ref_lock));
@@ -909,7 +909,7 @@ static struct ref_lock *lock_ref_sha1_basic(struct files_ref_store *refs,
909909
goto error_return;
910910
}
911911

912-
if (verify_lock(&refs->base, lock, old_sha1, mustexist, err)) {
912+
if (verify_lock(&refs->base, lock, old_oid, mustexist, err)) {
913913
last_errno = errno;
914914
goto error_return;
915915
}
@@ -1324,8 +1324,8 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store,
13241324

13251325
logmoved = log;
13261326

1327-
lock = lock_ref_sha1_basic(refs, newrefname, NULL, NULL, NULL,
1328-
REF_NODEREF, NULL, &err);
1327+
lock = lock_ref_oid_basic(refs, newrefname, NULL, NULL, NULL,
1328+
REF_NODEREF, NULL, &err);
13291329
if (!lock) {
13301330
if (copy)
13311331
error("unable to copy '%s' to '%s': %s", oldrefname, newrefname, err.buf);
@@ -1347,8 +1347,8 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store,
13471347
goto out;
13481348

13491349
rollback:
1350-
lock = lock_ref_sha1_basic(refs, oldrefname, NULL, NULL, NULL,
1351-
REF_NODEREF, NULL, &err);
1350+
lock = lock_ref_oid_basic(refs, oldrefname, NULL, NULL, NULL,
1351+
REF_NODEREF, NULL, &err);
13521352
if (!lock) {
13531353
error("unable to lock %s for rollback: %s", oldrefname, err.buf);
13541354
strbuf_release(&err);
@@ -1763,9 +1763,9 @@ static int files_create_symref(struct ref_store *ref_store,
17631763
struct ref_lock *lock;
17641764
int ret;
17651765

1766-
lock = lock_ref_sha1_basic(refs, refname, NULL,
1767-
NULL, NULL, REF_NODEREF, NULL,
1768-
&err);
1766+
lock = lock_ref_oid_basic(refs, refname, NULL,
1767+
NULL, NULL, REF_NODEREF, NULL,
1768+
&err);
17691769
if (!lock) {
17701770
error("%s", err.buf);
17711771
strbuf_release(&err);
@@ -2937,9 +2937,9 @@ static int files_reflog_expire(struct ref_store *ref_store,
29372937
* reference itself, plus we might need to update the
29382938
* reference if --updateref was specified:
29392939
*/
2940-
lock = lock_ref_sha1_basic(refs, refname, oid->hash,
2941-
NULL, NULL, REF_NODEREF,
2942-
&type, &err);
2940+
lock = lock_ref_oid_basic(refs, refname, oid,
2941+
NULL, NULL, REF_NODEREF,
2942+
&type, &err);
29432943
if (!lock) {
29442944
error("cannot lock ref '%s': %s", refname, err.buf);
29452945
strbuf_release(&err);

0 commit comments

Comments
 (0)