Skip to content

Commit bef70b2

Browse files
iabervongitster
authored andcommitted
Add a library function to add an alternate to the alternates file
This is in the core so that, if the alternates file has already been read, the addition can be parsed and put into effect for the current process. Signed-off-by: Daniel Barkalow <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ea3cd5c commit bef70b2

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,7 @@ extern struct alternate_object_database {
599599
char base[FLEX_ARRAY]; /* more */
600600
} *alt_odb_list;
601601
extern void prepare_alt_odb(void);
602+
extern void add_to_alternates_file(const char *reference);
602603

603604
struct pack_window {
604605
struct pack_window *next;

sha1_file.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,18 @@ static void read_info_alternates(const char * relative_base, int depth)
380380
munmap(map, mapsz);
381381
}
382382

383+
void add_to_alternates_file(const char *reference)
384+
{
385+
struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
386+
int fd = hold_lock_file_for_append(lock, git_path("objects/info/alternates"), 1);
387+
char *alt = mkpath("%s/objects\n", reference);
388+
write_or_die(fd, alt, strlen(alt));
389+
if (commit_lock_file(lock))
390+
die("could not close alternates file");
391+
if (alt_odb_tail)
392+
link_alt_odb_entries(alt, alt + strlen(alt), '\n', NULL, 0);
393+
}
394+
383395
void prepare_alt_odb(void)
384396
{
385397
const char *alt;

0 commit comments

Comments
 (0)