setup_temporary_shallow(): use tempfile module
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
f6ecc62dbf
commit
6e122b449b
35
shallow.c
35
shallow.c
@ -1,4 +1,5 @@
|
|||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
|
#include "tempfile.h"
|
||||||
#include "lockfile.h"
|
#include "lockfile.h"
|
||||||
#include "commit.h"
|
#include "commit.h"
|
||||||
#include "tag.h"
|
#include "tag.h"
|
||||||
@ -208,50 +209,28 @@ int write_shallow_commits(struct strbuf *out, int use_pack_protocol,
|
|||||||
return write_shallow_commits_1(out, use_pack_protocol, extra, 0);
|
return write_shallow_commits_1(out, use_pack_protocol, extra, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct strbuf temporary_shallow = STRBUF_INIT;
|
static struct tempfile temporary_shallow;
|
||||||
|
|
||||||
static void remove_temporary_shallow(void)
|
|
||||||
{
|
|
||||||
if (temporary_shallow.len) {
|
|
||||||
unlink_or_warn(temporary_shallow.buf);
|
|
||||||
strbuf_reset(&temporary_shallow);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void remove_temporary_shallow_on_signal(int signo)
|
|
||||||
{
|
|
||||||
remove_temporary_shallow();
|
|
||||||
sigchain_pop(signo);
|
|
||||||
raise(signo);
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *setup_temporary_shallow(const struct sha1_array *extra)
|
const char *setup_temporary_shallow(const struct sha1_array *extra)
|
||||||
{
|
{
|
||||||
struct strbuf sb = STRBUF_INIT;
|
struct strbuf sb = STRBUF_INIT;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
if (temporary_shallow.len)
|
|
||||||
die("BUG: attempt to create two temporary shallow files");
|
|
||||||
|
|
||||||
if (write_shallow_commits(&sb, 0, extra)) {
|
if (write_shallow_commits(&sb, 0, extra)) {
|
||||||
strbuf_addstr(&temporary_shallow, git_path("shallow_XXXXXX"));
|
fd = xmks_tempfile(&temporary_shallow, git_path("shallow_XXXXXX"));
|
||||||
fd = xmkstemp(temporary_shallow.buf);
|
|
||||||
|
|
||||||
atexit(remove_temporary_shallow);
|
|
||||||
sigchain_push_common(remove_temporary_shallow_on_signal);
|
|
||||||
|
|
||||||
if (write_in_full(fd, sb.buf, sb.len) != sb.len)
|
if (write_in_full(fd, sb.buf, sb.len) != sb.len)
|
||||||
die_errno("failed to write to %s",
|
die_errno("failed to write to %s",
|
||||||
temporary_shallow.buf);
|
get_tempfile_path(&temporary_shallow));
|
||||||
close(fd);
|
close_tempfile(&temporary_shallow);
|
||||||
strbuf_release(&sb);
|
strbuf_release(&sb);
|
||||||
return temporary_shallow.buf;
|
return get_tempfile_path(&temporary_shallow);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* is_repository_shallow() sees empty string as "no shallow
|
* is_repository_shallow() sees empty string as "no shallow
|
||||||
* file".
|
* file".
|
||||||
*/
|
*/
|
||||||
return temporary_shallow.buf;
|
return get_tempfile_path(&temporary_shallow);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup_alternate_shallow(struct lock_file *shallow_lock,
|
void setup_alternate_shallow(struct lock_file *shallow_lock,
|
||||||
|
Loading…
Reference in New Issue
Block a user