cvsimport: add <remote>/HEAD reference in separate remotes more
[gitweb.git] / lockfile.c
index 2023ebb6ffa4642a49b46cbce99bd49d3befebb6..23db35aff21d7c33197726128e2f120291e6e9f0 100644 (file)
@@ -4,11 +4,15 @@
 #include "cache.h"
 
 static struct lock_file *lock_file_list;
+static const char *alternate_index_output;
 
 static void remove_lock_file(void)
 {
+       pid_t me = getpid();
+
        while (lock_file_list) {
-               if (lock_file_list->filename[0])
+               if (lock_file_list->owner == me &&
+                   lock_file_list->filename[0])
                        unlink(lock_file_list->filename);
                lock_file_list = lock_file_list->next;
        }
@@ -27,6 +31,7 @@ static int lock_file(struct lock_file *lk, const char *path)
        sprintf(lk->filename, "%s.lock", path);
        fd = open(lk->filename, O_RDWR | O_CREAT | O_EXCL, 0666);
        if (0 <= fd) {
+               lk->owner = getpid();
                if (!lk->on_list) {
                        lk->next = lock_file_list;
                        lock_file_list = lk;
@@ -70,11 +75,15 @@ 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);
 }
 
+void set_alternate_index_output(const char *name)
+{
+       alternate_index_output = name;
+}
+
 int commit_locked_index(struct lock_file *lk)
 {
-       char *output = getenv(INDEX_OUTPUT_ENVIRONMENT);
-       if (output && *output) {
-               int result = rename(lk->filename, output);
+       if (alternate_index_output) {
+               int result = rename(lk->filename, alternate_index_output);
                lk->filename[0] = 0;
                return result;
        }