Fix revert --abort on Windows

On Windows, it is not possible to rename or remove a directory that has open files. 'revert --abort' renamed .git/sequencer when it still had .git/sequencer/head open. Close the file as early as possible to allow the rename operation on Windows. Signed-off-by: Johannes Sixt <j6t@kdbg.org> Acked-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Sixt committed Nov 23, 2011 at 09:49 UTC 2a4037d0a745134a3b94cb3d60d2793a26bd9027
1 file changed +2 -2
builtin/revert.c
+2 -2
@@ -931,8 +931,10 @@ static int sequencer_rollback(struct replay_opts *opts)
931 if (strbuf_getline(&buf, f, '\n')) {
932 error(_("cannot read %s: %s"), filename, ferror(f) ?
933 strerror(errno) : _("unexpected end of file"));
934 + fclose(f);
935 goto fail;
936 }
937 + fclose(f);
938 if (get_sha1_hex(buf.buf, sha1) || buf.buf[40] != '\0') {
939 error(_("stored pre-cherry-pick HEAD file '%s' is corrupt"),
940 filename);
@@ -941,11 +943,9 @@ static int sequencer_rollback(struct replay_opts *opts)
943 if (reset_for_rollback(sha1))
944 goto fail;
945 strbuf_release(&buf);
944 - fclose(f);
946 return 0;
947 fail:
948 strbuf_release(&buf);
948 - fclose(f);
949 return -1;
950 }
951