close_lock_file(): exit (successfully) if file is already closed
authorMichael Haggerty <mhagger@alum.mit.edu>
Wed, 1 Oct 2014 10:28:07 +0000 (12:28 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 1 Oct 2014 20:38:39 +0000 (13:38 -0700)
Suggested-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
lockfile.c
read-cache.c
index f1ce1544d2e49fe9330d7842ddac9be78e3620c9..d02c3bf901560d1e2bb021b23de7aae24bb45c0d 100644 (file)
@@ -233,6 +233,10 @@ int hold_lock_file_for_append(struct lock_file *lk, const char *path, int flags)
 int close_lock_file(struct lock_file *lk)
 {
        int fd = lk->fd;
+
+       if (fd < 0)
+               return 0;
+
        lk->fd = -1;
        return close(fd);
 }
@@ -251,7 +255,7 @@ int commit_lock_file(struct lock_file *lk)
 {
        char result_file[PATH_MAX];
        size_t i;
-       if (lk->fd >= 0 && close_lock_file(lk))
+       if (close_lock_file(lk))
                return -1;
        strcpy(result_file, lk->filename);
        i = strlen(result_file) - 5; /* .lock */
index 2fc1182f2267b3e9aed799eaf7df234cd36fefb9..5ffb1d7bb6d1bbacf0ea54678eb047c578f21206 100644 (file)
@@ -2042,7 +2042,7 @@ 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))
+               if (close_lock_file(lk))
                        return -1;
                if (rename(lk->filename, alternate_index_output))
                        return -1;