summaryrefslogtreecommitdiff
path: root/shallow.c
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2013-08-16 16:52:04 +0700
committerJunio C Hamano <gitster@pobox.com>2013-08-28 11:51:54 -0700
commit08ea65ad13faaf24f57732cdc8af3d830d4b367f (patch)
treec1143ed482a92214c09223fd32914292e4db1dd7 /shallow.c
parent6a3bbb4db409c5417960ffd3f020f75e0cb36f81 (diff)
downloadgit-08ea65ad13faaf24f57732cdc8af3d830d4b367f.tar.gz
shallow: add setup_temporary_shallow()
This function is like setup_alternate_shallow() except that it does not lock $GIT_DIR/shallow. It is supposed to be used when a program generates temporary shallow for use by another program, then throw the shallow file away. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'shallow.c')
-rw-r--r--shallow.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/shallow.c b/shallow.c
index 5f626c0138..cdf37d694d 100644
--- a/shallow.c
+++ b/shallow.c
@@ -175,6 +175,29 @@ int write_shallow_commits(struct strbuf *out, int use_pack_protocol)
return data.count;
}
+char *setup_temporary_shallow(void)
+{
+ struct strbuf sb = STRBUF_INIT;
+ int fd;
+
+ if (write_shallow_commits(&sb, 0)) {
+ struct strbuf path = STRBUF_INIT;
+ strbuf_addstr(&path, git_path("shallow_XXXXXX"));
+ fd = xmkstemp(path.buf);
+ if (write_in_full(fd, sb.buf, sb.len) != sb.len)
+ die_errno("failed to write to %s",
+ path.buf);
+ close(fd);
+ strbuf_release(&sb);
+ return strbuf_detach(&path, NULL);
+ }
+ /*
+ * is_repository_shallow() sees empty string as "no shallow
+ * file".
+ */
+ return xstrdup("");
+}
+
void setup_alternate_shallow(struct lock_file *shallow_lock,
const char **alternate_shallow_file)
{