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

brian m. carlson committed Oct 15, 2017 at 22:07 UTC 4f01e5080c4a7eee69da47c958888358e6127584
1 file changed +28 -28
refs/files-backend.c
+28 -28
@@ -770,13 +770,13 @@ static struct ref_iterator *files_ref_iterator_begin(
770 }
771
772 /*
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.
777 */
778 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,
780 struct strbuf *err)
781 {
782 assert(err);
@@ -784,7 +784,7 @@ static int verify_lock(struct ref_store *ref_store, struct ref_lock *lock,
784 if (refs_read_ref_full(ref_store, lock->ref_name,
785 mustexist ? RESOLVE_REF_READING : 0,
786 &lock->old_oid, NULL)) {
787 - if (old_sha1) {
787 + if (old_oid) {
788 int save_errno = errno;
789 strbuf_addf(err, "can't verify ref '%s'", lock->ref_name);
790 errno = save_errno;
@@ -794,11 +794,11 @@ static int verify_lock(struct ref_store *ref_store, struct ref_lock *lock,
794 return 0;
795 }
796 }
797 - if (old_sha1 && hashcmp(lock->old_oid.hash, old_sha1)) {
797 + if (old_oid && oidcmp(&lock->old_oid, old_oid)) {
798 strbuf_addf(err, "ref '%s' is at %s but expected %s",
799 lock->ref_name,
800 oid_to_hex(&lock->old_oid),
801 - sha1_to_hex(old_sha1));
801 + oid_to_hex(old_oid));
802 errno = EBUSY;
803 return -1;
804 }
@@ -828,22 +828,22 @@ static int create_reflock(const char *path, void *cb)
828 * Locks a ref returning the lock on success and NULL on failure.
829 * On failure errno is set to something meaningful.
830 */
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)
838 {
839 struct strbuf ref_file = STRBUF_INIT;
840 struct ref_lock *lock;
841 int last_errno = 0;
842 - int mustexist = (old_sha1 && !is_null_sha1(old_sha1));
842 + int mustexist = (old_oid && !is_null_oid(old_oid));
843 int resolve_flags = RESOLVE_REF_NO_RECURSE;
844 int resolved;
845
846 - files_assert_main_repository(refs, "lock_ref_sha1_basic");
846 + files_assert_main_repository(refs, "lock_ref_oid_basic");
847 assert(err);
848
849 lock = xcalloc(1, sizeof(struct ref_lock));
@@ -909,7 +909,7 @@ static struct ref_lock *lock_ref_sha1_basic(struct files_ref_store *refs,
909 goto error_return;
910 }
911
912 - if (verify_lock(&refs->base, lock, old_sha1, mustexist, err)) {
912 + if (verify_lock(&refs->base, lock, old_oid, mustexist, err)) {
913 last_errno = errno;
914 goto error_return;
915 }
@@ -1324,8 +1324,8 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store,
1324
1325 logmoved = log;
1326
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);
1329 if (!lock) {
1330 if (copy)
1331 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,
1347 goto out;
1348
1349 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);
1352 if (!lock) {
1353 error("unable to lock %s for rollback: %s", oldrefname, err.buf);
1354 strbuf_release(&err);
@@ -1763,9 +1763,9 @@ static int files_create_symref(struct ref_store *ref_store,
1763 struct ref_lock *lock;
1764 int ret;
1765
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);
1769 if (!lock) {
1770 error("%s", err.buf);
1771 strbuf_release(&err);
@@ -2937,9 +2937,9 @@ static int files_reflog_expire(struct ref_store *ref_store,
2937 * reference itself, plus we might need to update the
2938 * reference if --updateref was specified:
2939 */
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);
2943 if (!lock) {
2944 error("cannot lock ref '%s': %s", refname, err.buf);
2945 strbuf_release(&err);