diff options
-rw-r--r-- | refs.c | 15 |
1 files changed, 9 insertions, 6 deletions
@@ -2602,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) - LOCK_SUFFIX_LEN; - - lock->lk->filename[i] = 0; - err = unlink_or_warn(lock->lk->filename); - lock->lk->filename[i] = LOCK_SUFFIX[0]; + /* + * loose. The loose file name is the same as the + * lockfile name, minus ".lock": + */ + char *loose_filename = xmemdupz( + lock->lk->filename, + strlen(lock->lk->filename) - LOCK_SUFFIX_LEN); + int err = unlink_or_warn(loose_filename); + free(loose_filename); if (err && errno != ENOENT) return 1; } |