lock_ref_sha1_basic(): add a files_ref_store argument

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael Haggerty committed Sep 4, 2016 at 18:08 UTC 7eb27cdfe67f07bcfcd7781bed8110e8ae70d001
1 file changed +15 -11
refs/files-backend.c
+15 -11
@@ -1983,15 +1983,14 @@ static int remove_empty_directories(struct strbuf *path)
1983 * Locks a ref returning the lock on success and NULL on failure.
1984 * On failure errno is set to something meaningful.
1985 */
1986 -static struct ref_lock *lock_ref_sha1_basic(const char *refname,
1986 +static struct ref_lock *lock_ref_sha1_basic(struct files_ref_store *refs,
1987 + const char *refname,
1988 const unsigned char *old_sha1,
1989 const struct string_list *extras,
1990 const struct string_list *skip,
1991 unsigned int flags, int *type,
1992 struct strbuf *err)
1993 {
1993 - struct files_ref_store *refs =
1994 - get_files_ref_store(NULL, "lock_ref_sha1_basic");
1994 struct strbuf ref_file = STRBUF_INIT;
1995 struct ref_lock *lock;
1996 int last_errno = 0;
@@ -2001,6 +2000,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
2000 int attempts_remaining = 3;
2001 int resolved;
2002
2003 + assert_main_repository(&refs->base, "lock_ref_sha1_basic");
2004 assert(err);
2005
2006 lock = xcalloc(1, sizeof(struct ref_lock));
@@ -2644,8 +2644,8 @@ int rename_ref(const char *oldrefname, const char *newrefname, const char *logms
2644
2645 logmoved = log;
2646
2647 - lock = lock_ref_sha1_basic(newrefname, NULL, NULL, NULL, REF_NODEREF,
2648 - NULL, &err);
2647 + lock = lock_ref_sha1_basic(refs, newrefname, NULL, NULL, NULL,
2648 + REF_NODEREF, NULL, &err);
2649 if (!lock) {
2650 error("unable to rename '%s' to '%s': %s", oldrefname, newrefname, err.buf);
2651 strbuf_release(&err);
@@ -2663,8 +2663,8 @@ int rename_ref(const char *oldrefname, const char *newrefname, const char *logms
2663 return 0;
2664
2665 rollback:
2666 - lock = lock_ref_sha1_basic(oldrefname, NULL, NULL, NULL, REF_NODEREF,
2667 - NULL, &err);
2666 + lock = lock_ref_sha1_basic(refs, oldrefname, NULL, NULL, NULL,
2667 + REF_NODEREF, NULL, &err);
2668 if (!lock) {
2669 error("unable to lock %s for rollback: %s", oldrefname, err.buf);
2670 strbuf_release(&err);
@@ -3020,13 +3020,14 @@ static int files_create_symref(struct ref_store *ref_store,
3020 const char *refname, const char *target,
3021 const char *logmsg)
3022 {
3023 + struct files_ref_store *refs =
3024 + files_downcast(ref_store, 0, "create_symref");
3025 struct strbuf err = STRBUF_INIT;
3026 struct ref_lock *lock;
3027 int ret;
3028
3027 - files_downcast(ref_store, 0, "create_symref");
3028 -
3029 - lock = lock_ref_sha1_basic(refname, NULL, NULL, NULL, REF_NODEREF, NULL,
3029 + lock = lock_ref_sha1_basic(refs, refname, NULL,
3030 + NULL, NULL, REF_NODEREF, NULL,
3031 &err);
3032 if (!lock) {
3033 error("%s", err.buf);
@@ -3929,6 +3930,8 @@ int reflog_expire(const char *refname, const unsigned char *sha1,
3930 reflog_expiry_cleanup_fn cleanup_fn,
3931 void *policy_cb_data)
3932 {
3933 + struct files_ref_store *refs =
3934 + get_files_ref_store(NULL, "reflog_expire");
3935 static struct lock_file reflog_lock;
3936 struct expire_reflog_cb cb;
3937 struct ref_lock *lock;
@@ -3947,7 +3950,8 @@ int reflog_expire(const char *refname, const unsigned char *sha1,
3950 * reference itself, plus we might need to update the
3951 * reference if --updateref was specified:
3952 */
3950 - lock = lock_ref_sha1_basic(refname, sha1, NULL, NULL, REF_NODEREF,
3953 + lock = lock_ref_sha1_basic(refs, refname, sha1,
3954 + NULL, NULL, REF_NODEREF,
3955 &type, &err);
3956 if (!lock) {
3957 error("cannot lock ref '%s': %s", refname, err.buf);