summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: fd7bcfb)
raw | patch | inline | side by side (parent: fd7bcfb)
author | Junio C Hamano <junkio@cox.net> | |
Sat, 12 Aug 2006 08:03:47 +0000 (01:03 -0700) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Sun, 13 Aug 2006 00:08:25 +0000 (17:08 -0700) |
Most of the callers except the one in refs.c use the function to
update the index file. Among the index writers, everybody
except write-tree dies if they cannot open it for writing.
This gives the function an extra argument, to tell it to die
when it cannot create a new file as the lockfile.
The only caller that does not have to die is write-tree, because
updating the index for the cache-tree part is optional and not
being able to do so does not affect the correctness. I think we
do not have to be so careful and make the failure into die() the
same way as other callers, but that would be a different patch.
Signed-off-by: Junio C Hamano <junkio@cox.net>
update the index file. Among the index writers, everybody
except write-tree dies if they cannot open it for writing.
This gives the function an extra argument, to tell it to die
when it cannot create a new file as the lockfile.
The only caller that does not have to die is write-tree, because
updating the index for the cache-tree part is optional and not
being able to do so does not affect the correctness. I think we
do not have to be so careful and make the failure into die() the
same way as other callers, but that would be a different patch.
Signed-off-by: Junio C Hamano <junkio@cox.net>
builtin-add.c | patch | blob | history | |
builtin-apply.c | patch | blob | history | |
builtin-mv.c | patch | blob | history | |
builtin-read-tree.c | patch | blob | history | |
builtin-rm.c | patch | blob | history | |
builtin-update-index.c | patch | blob | history | |
builtin-write-tree.c | patch | blob | history | |
cache.h | patch | blob | history | |
checkout-index.c | patch | blob | history | |
lockfile.c | patch | blob | history | |
refs.c | patch | blob | history |
diff --git a/builtin-add.c b/builtin-add.c
index 096b611b5b0eef1c5a96dcaddc21aa874bdaee29..0cb9c812006ba4826122b57b9732e895b0eed905 100644 (file)
--- a/builtin-add.c
+++ b/builtin-add.c
git_config(git_default_config);
- newfd = hold_lock_file_for_update(&lock_file, get_index_file());
- if (newfd < 0)
- die("unable to create new index file");
+ newfd = hold_lock_file_for_update(&lock_file, get_index_file(), 1);
if (read_cache() < 0)
die("index file corrupt");
diff --git a/builtin-apply.c b/builtin-apply.c
index be2c7152cd7ee8c8076cd4bbd5660dd2f85b0fd1..9cf477c701d3224efe86418113691768410beae9 100644 (file)
--- a/builtin-apply.c
+++ b/builtin-apply.c
apply = 0;
write_index = check_index && apply;
- if (write_index && newfd < 0) {
+ if (write_index && newfd < 0)
newfd = hold_lock_file_for_update(&lock_file,
- get_index_file());
- if (newfd < 0)
- die("unable to create new index file");
- }
+ get_index_file(), 1);
if (check_index) {
if (read_cache() < 0)
die("unable to read index file");
diff --git a/builtin-mv.c b/builtin-mv.c
index ce8187c1e96833e1a6db2fa368a84b02fec7b0c2..a731f8d9cfed783fb59cb64db93f854ef0a4ebf9 100644 (file)
--- a/builtin-mv.c
+++ b/builtin-mv.c
git_config(git_default_config);
- newfd = hold_lock_file_for_update(&lock_file, get_index_file());
- if (newfd < 0)
- die("unable to create new index file");
-
+ newfd = hold_lock_file_for_update(&lock_file, get_index_file(), 1);
if (read_cache() < 0)
die("index file corrupt");
diff --git a/builtin-read-tree.c b/builtin-read-tree.c
index b30160a5b36c3a2cd2cf941728dc4c3d6e76c36d..71a7026df4bec244acdf36ef9559eecc5b65fae3 100644 (file)
--- a/builtin-read-tree.c
+++ b/builtin-read-tree.c
git_config(git_default_config);
- newfd = hold_lock_file_for_update(&lock_file, get_index_file());
- if (newfd < 0)
- die("unable to create new index file");
+ newfd = hold_lock_file_for_update(&lock_file, get_index_file(), 1);
git_config(git_default_config);
diff --git a/builtin-rm.c b/builtin-rm.c
index 8af3d7eb48e70dc9a640c2e96a058903fb9fddd8..593d86744c41a1f28258b3adb6e6cd556a64b61f 100644 (file)
--- a/builtin-rm.c
+++ b/builtin-rm.c
git_config(git_default_config);
- newfd = hold_lock_file_for_update(&lock_file, get_index_file());
- if (newfd < 0)
- die("unable to create new index file");
+ newfd = hold_lock_file_for_update(&lock_file, get_index_file(), 1);
if (read_cache() < 0)
die("index file corrupt");
diff --git a/builtin-update-index.c b/builtin-update-index.c
index 24dca47d8d6e54429aa89b04e4d67bda04fa0173..d2556f376b293d2907cd8416e99f9c0bd31781ca 100644 (file)
--- a/builtin-update-index.c
+++ b/builtin-update-index.c
/* We can't free this memory, it becomes part of a linked list parsed atexit() */
lock_file = xcalloc(1, sizeof(struct lock_file));
- newfd = hold_lock_file_for_update(lock_file, get_index_file());
- if (newfd < 0)
- die("unable to create new cachefile");
+ newfd = hold_lock_file_for_update(lock_file, get_index_file(), 1);
entries = read_cache();
if (entries < 0)
diff --git a/builtin-write-tree.c b/builtin-write-tree.c
index 6b62d7dc8c8b17bd0ff6b639a9bab18400d2177d..ca06149f186449407c6536fcc3caa37cd4101ce3 100644 (file)
--- a/builtin-write-tree.c
+++ b/builtin-write-tree.c
/* We can't free this memory, it becomes part of a linked list parsed atexit() */
struct lock_file *lock_file = xcalloc(1, sizeof(struct lock_file));
- newfd = hold_lock_file_for_update(lock_file, get_index_file());
+ newfd = hold_lock_file_for_update(lock_file, get_index_file(), 0);
entries = read_cache();
if (entries < 0)
index b8c21e07b2e714de8e4e662b31a41ff06c5e0c9a..b2ab2088e37d39a4c8e1927591015bf05a813233 100644 (file)
--- a/cache.h
+++ b/cache.h
struct lock_file *next;
char filename[PATH_MAX];
};
-extern int hold_lock_file_for_update(struct lock_file *, const char *path);
+extern int hold_lock_file_for_update(struct lock_file *, const char *path, int);
extern int commit_lock_file(struct lock_file *);
extern void rollback_lock_file(struct lock_file *);
diff --git a/checkout-index.c b/checkout-index.c
index 61152f34b7fc00e745a2f7524c4da5b5a1a780a2..dfb1c4441550c6de596a1245161cfbca34ada10c 100644 (file)
--- a/checkout-index.c
+++ b/checkout-index.c
state.refresh_cache = 1;
if (newfd < 0)
newfd = hold_lock_file_for_update
- (&lock_file, get_index_file());
+ (&lock_file, get_index_file(), 1);
if (newfd < 0)
die("cannot open index.lock file.");
continue;
diff --git a/lockfile.c b/lockfile.c
index 2346e0e9ef0dbd247daf9d77c373029b491068c4..2a2fea3cb6bd1de059e7c0f8c2008c5fe8376b93 100644 (file)
--- a/lockfile.c
+++ b/lockfile.c
raise(signo);
}
-int hold_lock_file_for_update(struct lock_file *lk, const char *path)
+static int lock_file(struct lock_file *lk, const char *path)
{
int fd;
sprintf(lk->filename, "%s.lock", path);
return fd;
}
+int hold_lock_file_for_update(struct lock_file *lk, const char *path, int die_on_error)
+{
+ int fd = lock_file(lk, path);
+ if (fd < 0 && die_on_error)
+ die("unable to create '%s': %s", path, strerror(errno));
+ return fd;
+}
+
int commit_lock_file(struct lock_file *lk)
{
char result_file[PATH_MAX];
index 28a93946050d9825ca86b833b6c77368a4bcc94b..86ef91661400376f6bdc2af37fac7982f8872df9 100644 (file)
--- a/refs.c
+++ b/refs.c
if (safe_create_leading_directories(lock->ref_file))
die("unable to create directory for %s", lock->ref_file);
- lock->lock_fd = hold_lock_file_for_update(lock->lk, lock->ref_file);
- if (lock->lock_fd < 0) {
- error("Couldn't open lock file %s: %s",
- lock->lk->filename, strerror(errno));
- unlock_ref(lock);
- return NULL;
- }
+ lock->lock_fd = hold_lock_file_for_update(lock->lk, lock->ref_file, 1);
return old_sha1 ? verify_lock(lock, old_sha1, mustexist) : lock;
}