@matheusbsbs / matheus-bagliano / commits / 4cd883d724
Fork 0

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 <casey@nrlssc.navy.mil> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brandon Casey committed Feb 22, 2008 at 12:47 UTC 4cd883d724ec36a120263d47058e65c6d1de642f
1 file changed +3 -2
builtin-reflog.c
+3 -2
@@ -276,10 +276,11 @@ static int expire_reflog(const char *ref, const unsigned char *sha1, int unused,
276 for_each_reflog_ent(ref, expire_reflog_ent, &cb);
277 finish:
278 if (cb.newlog) {
279 - if (fclose(cb.newlog))
279 + if (fclose(cb.newlog)) {
280 status |= error("%s: %s", strerror(errno),
281 newlog_path);
282 - if (rename(newlog_path, log_file)) {
282 + unlink(newlog_path);
283 + } else if (rename(newlog_path, log_file)) {
284 status |= error("cannot rename %s to %s",
285 newlog_path, log_file);
286 unlink(newlog_path);