hold_locked_index(): move from lockfile.c to read-cache.c
[gitweb.git] / read-cache.c
index 2fc1182f2267b3e9aed799eaf7df234cd36fefb9..9f137e7f27fa8db36c7bb3cfb0848b4595331dea 100644 (file)
@@ -1367,6 +1367,14 @@ static int read_index_extension(struct index_state *istate,
        return 0;
 }
 
+int hold_locked_index(struct lock_file *lk, int die_on_error)
+{
+       return hold_lock_file_for_update(lk, get_index_file(),
+                                        die_on_error
+                                        ? LOCK_DIE_ON_ERROR
+                                        : 0);
+}
+
 int read_index(struct index_state *istate)
 {
        return read_index_from(istate, get_index_file());
@@ -2041,16 +2049,10 @@ void set_alternate_index_output(const char *name)
 
 static int commit_locked_index(struct lock_file *lk)
 {
-       if (alternate_index_output) {
-               if (lk->fd >= 0 && close_lock_file(lk))
-                       return -1;
-               if (rename(lk->filename, alternate_index_output))
-                       return -1;
-               lk->filename[0] = 0;
-               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,