From: Torsten Bögershausen Date: Wed, 02 Apr 2014 06:52:17 GMT Subject: Re: [PATCH 12/22] delete_ref_loose(): don't muck around in the lock_file's filename Message-ID: <533BB3A1.1080203@web.de> In-Reply-To: <1396367910-7299-13-git-send-email-mhagger@alum.mit.edu> [] diff --git a/refs.c b/refs.c index 28d5eca..11ad23e 100644 --- a/refs.c +++ b/refs.c @@ -2485,12 +2485,14 @@ static int repack_without_ref(const char *refname) 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, + strlen(lock->lk->filename) - 5); At other places (lockfile.c) we use this +#define LOCK_SUFFIX_LEN 5 I think it makes sense to move this definition to an include file (lockfile.h ??) and use it here.