summaryrefslogtreecommitdiff
path: root/read-cache.c
diff options
context:
space:
mode:
authorMichael Haggerty <mhagger@alum.mit.edu>2014-10-01 12:28:36 +0200
committerJunio C Hamano <gitster@pobox.com>2014-10-01 13:52:06 -0700
commit751bacedaa507b7b6d10b2c1f48e019a01a8fa6e (patch)
treec93a688ada9b9139a4aa661273d5867eab6e74aa /read-cache.c
parent0c0d6e8601a1cfb8ebbdadb6a25a9f6fadc91359 (diff)
downloadgit-751bacedaa507b7b6d10b2c1f48e019a01a8fa6e.tar.gz
commit_lock_file_to(): refactor a helper out of commit_lock_file()
commit_locked_index(), when writing to an alternate index file, duplicates (poorly) the code in commit_lock_file(). And anyway, it shouldn't have to know so much about the internal workings of lockfile objects. So extract a new function commit_lock_file_to() that does the work common to the two functions, and call it from both commit_lock_file() and commit_locked_index(). Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'read-cache.c')
-rw-r--r--read-cache.c13
1 files changed, 3 insertions, 10 deletions
diff --git a/read-cache.c b/read-cache.c
index 91bf876ee6..e887e23fb6 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -2041,17 +2041,10 @@ void set_alternate_index_output(const char *name)
static int commit_locked_index(struct lock_file *lk)
{
- if (alternate_index_output) {
- if (close_lock_file(lk))
- return -1;
- if (rename(lk->filename.buf, alternate_index_output))
- return -1;
- lk->active = 0;
- strbuf_reset(&lk->filename);
- return 0;
- } else {
+ if (alternate_index_output)
+ return commit_lock_file_to(lk, alternate_index_output);
+ else
return commit_lock_file(lk);
- }
}
static int do_write_locked_index(struct index_state *istate, struct lock_file *lock,