Skip to content

Commit

Permalink
builtin-reflog.c: don't install new reflog on write failure
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Brandon Casey authored and Junio C Hamano committed Feb 27, 2008
1 parent 6ecbc85 commit 7a0a34c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions builtin-reflog.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 7a0a34c

Please sign in to comment.