]> git.ipfire.org Git - thirdparty/git.git/blobdiff - refs.c
commit_lock_file_to(): refactor a helper out of commit_lock_file()
[thirdparty/git.git] / refs.c
diff --git a/refs.c b/refs.c
index ffd45e92922ec52dccccfaecf1ceaf29f9231337..598f4eb9e7555304d170db738c40af830d4a91de 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -79,7 +79,8 @@ out:
                if (refname[1] == '\0')
                        return -1; /* Component equals ".". */
        }
-       if (cp - refname >= 5 && !memcmp(cp - 5, ".lock", 5))
+       if (cp - refname >= LOCK_SUFFIX_LEN &&
+           !memcmp(cp - LOCK_SUFFIX_LEN, LOCK_SUFFIX, LOCK_SUFFIX_LEN))
                return -1; /* Refname ends with ".lock". */
        return cp - refname;
 }
@@ -2225,7 +2226,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
                         */
                        goto retry;
                else
-                       unable_to_lock_index_die(ref_file, errno);
+                       unable_to_lock_die(ref_file, errno);
        }
        return old_sha1 ? verify_lock(lock, old_sha1, mustexist) : lock;
 
@@ -2601,12 +2602,15 @@ int repack_without_refs(const char **refnames, int n, struct strbuf *err)
 static int delete_ref_loose(struct ref_lock *lock, int flag)
 {
        if (!(flag & REF_ISPACKED) || flag & REF_ISSYMREF) {
-               /* loose */
-               int err, i = strlen(lock->lk->filename) - 5; /* .lock */
-
-               lock->lk->filename[i] = 0;
-               err = unlink_or_warn(lock->lk->filename);
-               lock->lk->filename[i] = '.';
+               /*
+                * loose.  The loose file name is the same as the
+                * lockfile name, minus ".lock":
+                */
+               char *loose_filename = xmemdupz(
+                               lock->lk->filename.buf,
+                               lock->lk->filename.len - LOCK_SUFFIX_LEN);
+               int err = unlink_or_warn(loose_filename);
+               free(loose_filename);
                if (err && errno != ENOENT)
                        return 1;
        }
@@ -2968,7 +2972,7 @@ int write_ref_sha1(struct ref_lock *lock,
            write_in_full(lock->lock_fd, &term, 1) != 1 ||
            close_ref(lock) < 0) {
                int save_errno = errno;
-               error("Couldn't write %s", lock->lk->filename);
+               error("Couldn't write %s", lock->lk->filename.buf);
                unlock_ref(lock);
                errno = save_errno;
                return -1;