Re: [PATCH v5 11/35] delete_ref_loose(): don't muck around in the lock_file's filename
- From
Jonathan Nieder <jrnieder@gmail.com>
- Date
- Sep 16, 2014, 21:11 UTC
- Message-ID
- <20140916211140.GL29050@google.com>
- In-Reply-To
- <1410896036-12750-12-git-send-email-mhagger@alum.mit.edu>
Michael Haggerty wrote:
Show 6 quoted lines
> It's bad manners. Especially since there could be a signal during the > call to unlink_or_warn(), in which case the signal handler will see > the wrong filename and delete the reference file, leaving the lockfile > behind. > > So make our own copy to work with.
Nice. Could this be a helper, to help others avoid a PATH_MAX sized buffer too?
[...]
> --- a/refs.c > +++ b/refs.c > @@ -2551,12 +2551,15 @@ int repack_without_refs(const char **refnames, int n, struct strbuf *err) > static int delete_ref_loose(struct ref_lock *lock, int flag)
[...]
Show 7 quoted lines
> + /* > + * 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);
Ronnie mentioned that this would misbehave in the !lock->lk->filename[0] case, which shouldn't come up because lock_ref_sha1_basic dies on error but seems worth futureproofing against. Maybe something like
assert(lock->lk->filename[0]);
would be enough to make the assumption obvious for people reading.
Otherwise looks good.
Thanks, Jonathan