copy_fd(): do not close the input file descriptor
[gitweb.git] / lockfile.c
index a921d77afcc5b54fdeba7bca6afcd85548332f0d..2448d30cd06b5f356b1cf3ca0d37200a408d9da1 100644 (file)
@@ -5,7 +5,6 @@
 #include "sigchain.h"
 
 static struct lock_file *lock_file_list;
-static const char *alternate_index_output;
 
 static void remove_lock_file(void)
 {
@@ -225,8 +224,11 @@ int hold_lock_file_for_append(struct lock_file *lk, const char *path, int flags)
        } else if (copy_fd(orig_fd, fd)) {
                if (flags & LOCK_DIE_ON_ERROR)
                        exit(128);
+               close(orig_fd);
                close(fd);
                return -1;
+       } else {
+               close(orig_fd);
        }
        return fd;
 }
@@ -261,25 +263,6 @@ int hold_locked_index(struct lock_file *lk, int die_on_error)
                                         : 0);
 }
 
-void set_alternate_index_output(const char *name)
-{
-       alternate_index_output = name;
-}
-
-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
-               return commit_lock_file(lk);
-}
-
 void rollback_lock_file(struct lock_file *lk)
 {
        if (lk->filename[0]) {