summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Haggerty <mhagger@alum.mit.edu>2015-08-10 09:47:40 (GMT)
committerJunio C Hamano <gitster@pobox.com>2015-08-10 19:57:14 (GMT)
commit9c77381d6a495e102b811df954d0fa14e62250ab (patch)
tree6e40c31556209cb4c77b570924302e20fe937dba
parentb4fb09e4da53bfc6c720337142af5db3204736d5 (diff)
downloadgit-9c77381d6a495e102b811df954d0fa14e62250ab.zip
git-9c77381d6a495e102b811df954d0fa14e62250ab.tar.gz
git-9c77381d6a495e102b811df954d0fa14e62250ab.tar.bz2
commit_lock_file(): use get_locked_file_path()
First beef up the sanity checking in get_locked_file_path() to match that in commit_lock_file(). Then rewrite commit_lock_file() to use get_locked_file_path() for its pathname computation. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--lockfile.c28
1 files changed, 12 insertions, 16 deletions
diff --git a/lockfile.c b/lockfile.c
index 5e954ba..3904803 100644
--- a/lockfile.c
+++ b/lockfile.c
@@ -389,8 +389,10 @@ char *get_locked_file_path(struct lock_file *lk)
{
if (!lk->active)
die("BUG: get_locked_file_path() called for unlocked object");
- if (lk->filename.len <= LOCK_SUFFIX_LEN)
+ if (lk->filename.len <= LOCK_SUFFIX_LEN ||
+ strcmp(lk->filename.buf + lk->filename.len - LOCK_SUFFIX_LEN, LOCK_SUFFIX))
die("BUG: get_locked_file_path() called for malformed lock object");
+ /* remove ".lock": */
return xmemdupz(lk->filename.buf, lk->filename.len - LOCK_SUFFIX_LEN);
}
@@ -458,22 +460,16 @@ int commit_lock_file_to(struct lock_file *lk, const char *path)
int commit_lock_file(struct lock_file *lk)
{
- static struct strbuf result_file = STRBUF_INIT;
- int err;
+ char *result_path = get_locked_file_path(lk);
- if (!lk->active)
- die("BUG: attempt to commit unlocked object");
-
- if (lk->filename.len <= LOCK_SUFFIX_LEN ||
- strcmp(lk->filename.buf + lk->filename.len - LOCK_SUFFIX_LEN, LOCK_SUFFIX))
- die("BUG: lockfile filename corrupt");
-
- /* remove ".lock": */
- strbuf_add(&result_file, lk->filename.buf,
- lk->filename.len - LOCK_SUFFIX_LEN);
- err = commit_lock_file_to(lk, result_file.buf);
- strbuf_reset(&result_file);
- return err;
+ if (commit_lock_file_to(lk, result_path)) {
+ int save_errno = errno;
+ free(result_path);
+ errno = save_errno;
+ return -1;
+ }
+ free(result_path);
+ return 0;
}
void rollback_lock_file(struct lock_file *lk)