summaryrefslogtreecommitdiff
path: root/shallow.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2015-08-25 14:57:09 -0700
committerJunio C Hamano <gitster@pobox.com>2015-08-25 14:57:09 -0700
commitdb86e61cbbc4c59a0886366bbf392498e64b53c8 (patch)
tree8b92645b8adeddaf02caa483579c64dbc09370fe /shallow.c
parent424f89f098a045785471cccb4f7307cc5b05bc54 (diff)
parent9e9033166b3a6b34aad917891b9210fa194fdfd9 (diff)
downloadgit-db86e61cbbc4c59a0886366bbf392498e64b53c8.tar.gz
Merge branch 'mh/tempfile'
The "lockfile" API has been rebuilt on top of a new "tempfile" API. * mh/tempfile: credential-cache--daemon: use tempfile module credential-cache--daemon: delete socket from main() gc: use tempfile module to handle gc.pid file lock_repo_for_gc(): compute the path to "gc.pid" only once diff: use tempfile module setup_temporary_shallow(): use tempfile module write_shared_index(): use tempfile module register_tempfile(): new function to handle an existing temporary file tempfile: add several functions for creating temporary files prepare_tempfile_object(): new function, extracted from create_tempfile() tempfile: a new module for handling temporary files commit_lock_file(): use get_locked_file_path() lockfile: add accessor get_lock_file_path() lockfile: add accessors get_lock_file_fd() and get_lock_file_fp() create_bundle(): duplicate file descriptor to avoid closing it twice lockfile: move documentation to lockfile.h and lockfile.c
Diffstat (limited to 'shallow.c')
-rw-r--r--shallow.c41
1 files changed, 10 insertions, 31 deletions
diff --git a/shallow.c b/shallow.c
index 4ded4a8cde..d49a3d6e9f 100644
--- a/shallow.c
+++ b/shallow.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "tempfile.h"
#include "lockfile.h"
#include "commit.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);
}
-static struct strbuf temporary_shallow = STRBUF_INIT;
-
-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);
-}
+static struct tempfile temporary_shallow;
const char *setup_temporary_shallow(const struct sha1_array *extra)
{
struct strbuf sb = STRBUF_INIT;
int fd;
- if (temporary_shallow.len)
- die("BUG: attempt to create two temporary shallow files");
-
if (write_shallow_commits(&sb, 0, extra)) {
- strbuf_addstr(&temporary_shallow, git_path("shallow_XXXXXX"));
- fd = xmkstemp(temporary_shallow.buf);
-
- atexit(remove_temporary_shallow);
- sigchain_push_common(remove_temporary_shallow_on_signal);
+ fd = xmks_tempfile(&temporary_shallow, git_path("shallow_XXXXXX"));
if (write_in_full(fd, sb.buf, sb.len) != sb.len)
die_errno("failed to write to %s",
- temporary_shallow.buf);
- close(fd);
+ get_tempfile_path(&temporary_shallow));
+ close_tempfile(&temporary_shallow);
strbuf_release(&sb);
- return temporary_shallow.buf;
+ return get_tempfile_path(&temporary_shallow);
}
/*
* is_repository_shallow() sees empty string as "no shallow
* file".
*/
- return temporary_shallow.buf;
+ return get_tempfile_path(&temporary_shallow);
}
void setup_alternate_shallow(struct lock_file *shallow_lock,
@@ -267,8 +246,8 @@ void setup_alternate_shallow(struct lock_file *shallow_lock,
if (write_shallow_commits(&sb, 0, extra)) {
if (write_in_full(fd, sb.buf, sb.len) != sb.len)
die_errno("failed to write to %s",
- shallow_lock->filename.buf);
- *alternate_shallow_file = shallow_lock->filename.buf;
+ get_lock_file_path(shallow_lock));
+ *alternate_shallow_file = get_lock_file_path(shallow_lock);
} else
/*
* is_repository_shallow() sees empty string as "no
@@ -314,7 +293,7 @@ void prune_shallow(int show_only)
if (write_shallow_commits_1(&sb, 0, NULL, SEEN_ONLY)) {
if (write_in_full(fd, sb.buf, sb.len) != sb.len)
die_errno("failed to write to %s",
- shallow_lock.filename.buf);
+ get_lock_file_path(&shallow_lock));
commit_lock_file(&shallow_lock);
} else {
unlink(git_path_shallow());