Code

Fix revert --abort on Windows
authorJohannes Sixt <j6t@kdbg.org>
Wed, 23 Nov 2011 08:49:38 +0000 (09:49 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 23 Nov 2011 18:54:57 +0000 (10:54 -0800)
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>
builtin/revert.c

index 9b9b2e57475ad201719d5d590c9e1be2d4d43401..c0b259225146d4712e82e61805210a0327a3c27a 100644 (file)
@@ -931,8 +931,10 @@ static int sequencer_rollback(struct replay_opts *opts)
        if (strbuf_getline(&buf, f, '\n')) {
                error(_("cannot read %s: %s"), filename, ferror(f) ?
                        strerror(errno) : _("unexpected end of file"));
+               fclose(f);
                goto fail;
        }
+       fclose(f);
        if (get_sha1_hex(buf.buf, sha1) || buf.buf[40] != '\0') {
                error(_("stored pre-cherry-pick HEAD file '%s' is corrupt"),
                        filename);
@@ -941,11 +943,9 @@ static int sequencer_rollback(struct replay_opts *opts)
        if (reset_for_rollback(sha1))
                goto fail;
        strbuf_release(&buf);
-       fclose(f);
        return 0;
 fail:
        strbuf_release(&buf);
-       fclose(f);
        return -1;
 }