Skip to content

Commit 6e122b4

Browse files
mhaggergitster
authored andcommitted
setup_temporary_shallow(): use tempfile module
Signed-off-by: Michael Haggerty <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f6ecc62 commit 6e122b4

File tree

1 file changed

+7
-28
lines changed

1 file changed

+7
-28
lines changed

shallow.c

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "cache.h"
2+
#include "tempfile.h"
23
#include "lockfile.h"
34
#include "commit.h"
45
#include "tag.h"
@@ -208,50 +209,28 @@ int write_shallow_commits(struct strbuf *out, int use_pack_protocol,
208209
return write_shallow_commits_1(out, use_pack_protocol, extra, 0);
209210
}
210211

211-
static struct strbuf temporary_shallow = STRBUF_INIT;
212-
213-
static void remove_temporary_shallow(void)
214-
{
215-
if (temporary_shallow.len) {
216-
unlink_or_warn(temporary_shallow.buf);
217-
strbuf_reset(&temporary_shallow);
218-
}
219-
}
220-
221-
static void remove_temporary_shallow_on_signal(int signo)
222-
{
223-
remove_temporary_shallow();
224-
sigchain_pop(signo);
225-
raise(signo);
226-
}
212+
static struct tempfile temporary_shallow;
227213

228214
const char *setup_temporary_shallow(const struct sha1_array *extra)
229215
{
230216
struct strbuf sb = STRBUF_INIT;
231217
int fd;
232218

233-
if (temporary_shallow.len)
234-
die("BUG: attempt to create two temporary shallow files");
235-
236219
if (write_shallow_commits(&sb, 0, extra)) {
237-
strbuf_addstr(&temporary_shallow, git_path("shallow_XXXXXX"));
238-
fd = xmkstemp(temporary_shallow.buf);
239-
240-
atexit(remove_temporary_shallow);
241-
sigchain_push_common(remove_temporary_shallow_on_signal);
220+
fd = xmks_tempfile(&temporary_shallow, git_path("shallow_XXXXXX"));
242221

243222
if (write_in_full(fd, sb.buf, sb.len) != sb.len)
244223
die_errno("failed to write to %s",
245-
temporary_shallow.buf);
246-
close(fd);
224+
get_tempfile_path(&temporary_shallow));
225+
close_tempfile(&temporary_shallow);
247226
strbuf_release(&sb);
248-
return temporary_shallow.buf;
227+
return get_tempfile_path(&temporary_shallow);
249228
}
250229
/*
251230
* is_repository_shallow() sees empty string as "no shallow
252231
* file".
253232
*/
254-
return temporary_shallow.buf;
233+
return get_tempfile_path(&temporary_shallow);
255234
}
256235

257236
void setup_alternate_shallow(struct lock_file *shallow_lock,

0 commit comments

Comments
 (0)