|
1 | 1 | #include "cache.h"
|
| 2 | +#include "tempfile.h" |
2 | 3 | #include "lockfile.h"
|
3 | 4 | #include "commit.h"
|
4 | 5 | #include "tag.h"
|
@@ -208,50 +209,28 @@ int write_shallow_commits(struct strbuf *out, int use_pack_protocol,
|
208 | 209 | return write_shallow_commits_1(out, use_pack_protocol, extra, 0);
|
209 | 210 | }
|
210 | 211 |
|
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; |
227 | 213 |
|
228 | 214 | const char *setup_temporary_shallow(const struct sha1_array *extra)
|
229 | 215 | {
|
230 | 216 | struct strbuf sb = STRBUF_INIT;
|
231 | 217 | int fd;
|
232 | 218 |
|
233 |
| - if (temporary_shallow.len) |
234 |
| - die("BUG: attempt to create two temporary shallow files"); |
235 |
| - |
236 | 219 | 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")); |
242 | 221 |
|
243 | 222 | if (write_in_full(fd, sb.buf, sb.len) != sb.len)
|
244 | 223 | 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); |
247 | 226 | strbuf_release(&sb);
|
248 |
| - return temporary_shallow.buf; |
| 227 | + return get_tempfile_path(&temporary_shallow); |
249 | 228 | }
|
250 | 229 | /*
|
251 | 230 | * is_repository_shallow() sees empty string as "no shallow
|
252 | 231 | * file".
|
253 | 232 | */
|
254 |
| - return temporary_shallow.buf; |
| 233 | + return get_tempfile_path(&temporary_shallow); |
255 | 234 | }
|
256 | 235 |
|
257 | 236 | void setup_alternate_shallow(struct lock_file *shallow_lock,
|
|
0 commit comments