From: Brandon Casey Date: Fri, 22 Feb 2008 18:47:08 +0000 (-0600) Subject: builtin-reflog.c: don't install new reflog on write failure X-Git-Tag: v1.5.5-rc0~144^2 X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=commitdiff_plain;h=4cd883d724ec36a120263d47058e65c6d1de642f;p=git.git builtin-reflog.c: don't install new reflog on write failure 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 Signed-off-by: Junio C Hamano --- diff --git a/builtin-reflog.c b/builtin-reflog.c index 4836ec951..ab53c8cb7 100644 --- 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);