From cf6950d3bfe1447ac04867b1f5654a2fc9c5db96 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Wed, 1 Oct 2014 12:28:32 +0200 Subject: lockfile: change lock_file::filename into a strbuf MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For now, we still make sure to allocate at least PATH_MAX characters for the strbuf because resolve_symlink() doesn't know how to expand the space for its return value. (That will be fixed in a moment.) Another alternative would be to just use a strbuf as scratch space in lock_file() but then store a pointer to the naked string in struct lock_file. But lock_file objects are often reused. By reusing the same strbuf, we can avoid having to reallocate the string most times when a lock_file object is reused. Helped-by: Torsten Bögershausen Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- read-cache.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'read-cache.c') diff --git a/read-cache.c b/read-cache.c index af69f344a2..91bf876ee6 100644 --- a/read-cache.c +++ b/read-cache.c @@ -2044,10 +2044,10 @@ static int commit_locked_index(struct lock_file *lk) if (alternate_index_output) { if (close_lock_file(lk)) return -1; - if (rename(lk->filename, alternate_index_output)) + if (rename(lk->filename.buf, alternate_index_output)) return -1; lk->active = 0; - lk->filename[0] = 0; + strbuf_reset(&lk->filename); return 0; } else { return commit_lock_file(lk); -- cgit v1.2.3