summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 22c430a)
raw | patch | inline | side by side (parent: 22c430a)
author | Brandon Casey <casey@nrlssc.navy.mil> | |
Fri, 22 Feb 2008 18:47:08 +0000 (12:47 -0600) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Sat, 23 Feb 2008 06:52:06 +0000 (22:52 -0800) |
When expiring reflog entries, a new temporary log is written which contains
only the entries to retain. After it is written, it is renamed to replace
the existing reflog. Currently, we check that writing of the new log is
successful and print a message on failure, but the original reflog is still
replaced with the new reflog even on failure. This patch causes the
original reflog to be retained if we fail when writing the new reflog.
Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
only the entries to retain. After it is written, it is renamed to replace
the existing reflog. Currently, we check that writing of the new log is
successful and print a message on failure, but the original reflog is still
replaced with the new reflog even on failure. This patch causes the
original reflog to be retained if we fail when writing the new reflog.
Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-reflog.c | patch | blob | history |
diff --git a/builtin-reflog.c b/builtin-reflog.c
index 4836ec951be727512bcd550dd3604c43c39aa557..ab53c8cb7c08298c3ab0f69bf600a70385dafa64 100644 (file)
--- a/builtin-reflog.c
+++ b/builtin-reflog.c
@@ -276,10 +276,11 @@ static int expire_reflog(const char *ref, const unsigned char *sha1, int unused,
for_each_reflog_ent(ref, expire_reflog_ent, &cb);
finish:
if (cb.newlog) {
- if (fclose(cb.newlog))
+ if (fclose(cb.newlog)) {
status |= error("%s: %s", strerror(errno),
newlog_path);
- if (rename(newlog_path, log_file)) {
+ unlink(newlog_path);
+ } else if (rename(newlog_path, log_file)) {
status |= error("cannot rename %s to %s",
newlog_path, log_file);
unlink(newlog_path);