Skip to content

Commit 08ea65a

Browse files
pcloudsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6a3bbb4 commit 08ea65a

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

commit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ extern void set_alternate_shallow_file(const char *path);
201201
extern int write_shallow_commits(struct strbuf *out, int use_pack_protocol);
202202
extern void setup_alternate_shallow(struct lock_file *shallow_lock,
203203
const char **alternate_shallow_file);
204+
extern char *setup_temporary_shallow(void);
204205

205206
int is_descendant_of(struct commit *, struct commit_list *);
206207
int in_merge_bases(struct commit *, struct commit *);

shallow.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,29 @@ int write_shallow_commits(struct strbuf *out, int use_pack_protocol)
175175
return data.count;
176176
}
177177

178+
char *setup_temporary_shallow(void)
179+
{
180+
struct strbuf sb = STRBUF_INIT;
181+
int fd;
182+
183+
if (write_shallow_commits(&sb, 0)) {
184+
struct strbuf path = STRBUF_INIT;
185+
strbuf_addstr(&path, git_path("shallow_XXXXXX"));
186+
fd = xmkstemp(path.buf);
187+
if (write_in_full(fd, sb.buf, sb.len) != sb.len)
188+
die_errno("failed to write to %s",
189+
path.buf);
190+
close(fd);
191+
strbuf_release(&sb);
192+
return strbuf_detach(&path, NULL);
193+
}
194+
/*
195+
* is_repository_shallow() sees empty string as "no shallow
196+
* file".
197+
*/
198+
return xstrdup("");
199+
}
200+
178201
void setup_alternate_shallow(struct lock_file *shallow_lock,
179202
const char **alternate_shallow_file)
180203
{

0 commit comments

Comments
 (0)