diff options
author | Jeff King <peff@peff.net> | 2014-02-27 06:25:20 -0500 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-02-27 12:07:13 -0800 |
commit | 0179c945fce361c56b465e8a3f0fdf0962a816a1 (patch) | |
tree | 714556b0cbd64a39b374adc71484bc3e4e4a5a05 /upload-pack.c | |
parent | 0cc77c386cea7afebb54a5e7263ca37569ecfe7a (diff) | |
download | git-0179c945fce361c56b465e8a3f0fdf0962a816a1.tar.gz |
shallow: automatically clean up shallow tempfiles
We sometimes write tempfiles of the form "shallow_XXXXXX"
during fetch/push operations with shallow repositories.
Under normal circumstances, we clean up the result when we
are done. However, we do no take steps to clean up after
ourselves when we exit due to die() or signal death.
This patch teaches the tempfile creation code to register
handlers to clean up after ourselves. To handle this, we
change the ownership semantics of the filename returned by
setup_temporary_shallow. It now keeps a copy of the filename
itself, and returns only a const pointer to it.
We can also do away with explicit tempfile removal in the
callers. They all exit not long after finishing with the
file, so they can rely on the auto-cleanup, simplifying the
code.
Note that we keep things simple and maintain only a single
filename to be cleaned. This is sufficient for the current
caller, but we future-proof it with a die("BUG").
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'upload-pack.c')
-rw-r--r-- | upload-pack.c | 7 |
1 files changed, 1 insertions, 6 deletions
diff --git a/upload-pack.c b/upload-pack.c index 0c44f6b292..a3c52f691d 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -81,7 +81,7 @@ static void create_pack_file(void) const char *argv[12]; int i, arg = 0; FILE *pipe_fd; - char *shallow_file = NULL; + const char *shallow_file = NULL; if (shallow_nr) { shallow_file = setup_temporary_shallow(NULL); @@ -242,11 +242,6 @@ static void create_pack_file(void) error("git upload-pack: git-pack-objects died with error."); goto fail; } - if (shallow_file) { - if (*shallow_file) - unlink(shallow_file); - free(shallow_file); - } /* flush the data */ if (0 <= buffered) { |