summaryrefslogtreecommitdiff
path: root/index.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2005-05-15 14:23:12 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-05-19 09:50:57 -0700
commit415e96c8b7e7d47f98a45ae1b6d524418245a3b4 (patch)
tree08f5f8433a6d56642b64fe9ab941647da6c8aef5 /index.c
parent875d0f8ddb1d420f6465498842740c4f5ab03e6f (diff)
downloadgit-415e96c8b7e7d47f98a45ae1b6d524418245a3b4.tar.gz
[PATCH] Implement git-checkout-cache -u to update stat information in the cache.
With -u flag, git-checkout-cache picks up the stat information from newly created file and updates the cache. This removes the need to run git-update-cache --refresh immediately after running git-checkout-cache. Signed-off-by: Junio C Hamano <junkio@cox.net> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'index.c')
-rw-r--r--index.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/index.c b/index.c
new file mode 100644
index 0000000000..87fc7b0387
--- /dev/null
+++ b/index.c
@@ -0,0 +1,53 @@
+/*
+ * 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();
+}
+
+int hold_index_file_for_update(struct cache_file *cf, const char *path)
+{
+ sprintf(cf->lockfile, "%s.lock", path);
+ cf->next = cache_file_list;
+ cache_file_list = cf;
+ if (!cf->next) {
+ signal(SIGINT, remove_lock_file_on_signal);
+ atexit(remove_lock_file);
+ }
+ return open(cf->lockfile, O_RDWR | O_CREAT | O_EXCL, 0600);
+}
+
+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;
+}
+