aboutsummaryrefslogtreecommitdiff
path: root/shallow.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2017-09-05 08:14:19 -0400
committerJunio C Hamano <gitster@pobox.com>2017-09-06 17:19:52 +0900
commitc0e963b77c6892d40d4ca81a71098aaa6c4eaed3 (patch)
tree2d3cba440242655bf439197c5f3ea8eb0d42b1ef /shallow.c
parent0899013993cd5eb327bc1a40d7c629db37e5ea83 (diff)
downloadgit-c0e963b77c6892d40d4ca81a71098aaa6c4eaed3.tar.gz
git-c0e963b77c6892d40d4ca81a71098aaa6c4eaed3.tar.xz
setup_temporary_shallow: move tempfile struct into function
The setup_temporary_shallow() function creates a temporary file, but we never access the tempfile struct outside of the function. This is OK, since it means we'll just clean up the tempfile on exit. But we can simplify the code a bit by moving the global tempfile struct to the only function in which it's used. Note that it must remain "static" due to tempfile.c's requirement that tempfile storage never goes away until program exit. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'shallow.c')
-rw-r--r--shallow.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/shallow.c b/shallow.c
index 29194b475..c7fd68ace 100644
--- a/shallow.c
+++ b/shallow.c
@@ -286,22 +286,21 @@ int write_shallow_commits(struct strbuf *out, int use_pack_protocol,
return write_shallow_commits_1(out, use_pack_protocol, extra, 0);
}
-static struct tempfile temporary_shallow;
-
const char *setup_temporary_shallow(const struct oid_array *extra)
{
+ static struct tempfile temp;
struct strbuf sb = STRBUF_INIT;
int fd;
if (write_shallow_commits(&sb, 0, extra)) {
- fd = xmks_tempfile(&temporary_shallow, git_path("shallow_XXXXXX"));
+ fd = xmks_tempfile(&temp, git_path("shallow_XXXXXX"));
if (write_in_full(fd, sb.buf, sb.len) != sb.len)
die_errno("failed to write to %s",
- get_tempfile_path(&temporary_shallow));
- close_tempfile(&temporary_shallow);
+ get_tempfile_path(&temp));
+ close_tempfile(&temp);
strbuf_release(&sb);
- return get_tempfile_path(&temporary_shallow);
+ return get_tempfile_path(&temp);
}
/*
* is_repository_shallow() sees empty string as "no shallow