write_index_as_tree: cleanup tempfile on error
commitc82c75b9518750a94e38c84fc89741a51b815014
authorJeff King <peff@peff.net>
Tue, 5 Sep 2017 12:14:07 +0000 (5 08:14 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 6 Sep 2017 08:19:52 +0000 (6 17:19 +0900)
treea63ff13b872b8614172ab8a77151039cf61b83aa
parent3ec7d702a89c647ddf42a59bc3539361367de9d5
write_index_as_tree: cleanup tempfile on error

If we failed to write our new index file, we rollback our
lockfile to remove the temporary index. But if we fail
before we even get to the write step (because reading the
old index failed), we leave the lockfile in place, which
makes no sense.

In practice this hasn't been a big deal because failing at
write_index_as_tree() typically results in the whole program
exiting (and thus the tempfile handler kicking in and
cleaning up the files). But this function should
consistently take responsibility for the resources it
allocates.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
cache-tree.c