diff options
author | Junio C Hamano <junkio@cox.net> | 2006-06-06 23:42:52 (GMT) |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2006-06-06 23:42:52 (GMT) |
commit | 9941afc051d953ee5e8fd9a8a27c5cd659ef9552 (patch) | |
tree | 1c2e8296f1cb0e97e341c220a5246bd3154ced7a /index.c | |
parent | 44fe4f522e63d3f01174459af674af2f9c293671 (diff) | |
parent | e5f38ec3c5d8553413501e6141932b8ccc7aceb4 (diff) | |
download | git-9941afc051d953ee5e8fd9a8a27c5cd659ef9552.zip git-9941afc051d953ee5e8fd9a8a27c5cd659ef9552.tar.gz git-9941afc051d953ee5e8fd9a8a27c5cd659ef9552.tar.bz2 |
Merge branch 'jc/lockfile'
* jc/lockfile:
ref-log: style fixes.
refs.c: convert it to use lockfile interface.
Make index file locking code reusable to others.
Diffstat (limited to 'index.c')
-rw-r--r-- | index.c | 57 |
1 files changed, 0 insertions, 57 deletions
diff --git a/index.c b/index.c deleted file mode 100644 index f92b960..0000000 --- a/index.c +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2005, Junio C Hamano - */ -#include <signal.h> -#include "cache.h" - -static struct cache_file *cache_file_list; - -static void remove_lock_file(void) -{ - while (cache_file_list) { - if (cache_file_list->lockfile[0]) - unlink(cache_file_list->lockfile); - cache_file_list = cache_file_list->next; - } -} - -static void remove_lock_file_on_signal(int signo) -{ - remove_lock_file(); - signal(SIGINT, SIG_DFL); - raise(signo); -} - -int hold_index_file_for_update(struct cache_file *cf, const char *path) -{ - int fd; - sprintf(cf->lockfile, "%s.lock", path); - fd = open(cf->lockfile, O_RDWR | O_CREAT | O_EXCL, 0666); - if (fd >=0 && !cf->next) { - cf->next = cache_file_list; - cache_file_list = cf; - signal(SIGINT, remove_lock_file_on_signal); - atexit(remove_lock_file); - } - return fd; -} - -int commit_index_file(struct cache_file *cf) -{ - char indexfile[PATH_MAX]; - int i; - strcpy(indexfile, cf->lockfile); - i = strlen(indexfile) - 5; /* .lock */ - indexfile[i] = 0; - i = rename(cf->lockfile, indexfile); - cf->lockfile[0] = 0; - return i; -} - -void rollback_index_file(struct cache_file *cf) -{ - if (cf->lockfile[0]) - unlink(cf->lockfile); - cf->lockfile[0] = 0; -} - |