Skip to content

Commit

Permalink
Add a library function to add an alternate to the alternates file
Browse files Browse the repository at this point in the history
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 <barkalow@iabervon.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Daniel Barkalow authored and Junio C Hamano committed May 5, 2008
1 parent ea3cd5c commit bef70b2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,7 @@ extern struct alternate_object_database {
char base[FLEX_ARRAY]; /* more */
} *alt_odb_list;
extern void prepare_alt_odb(void);
extern void add_to_alternates_file(const char *reference);

struct pack_window {
struct pack_window *next;
Expand Down
12 changes: 12 additions & 0 deletions sha1_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,18 @@ static void read_info_alternates(const char * relative_base, int depth)
munmap(map, mapsz);
}

void add_to_alternates_file(const char *reference)
{
struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
int fd = hold_lock_file_for_append(lock, git_path("objects/info/alternates"), 1);
char *alt = mkpath("%s/objects\n", reference);
write_or_die(fd, alt, strlen(alt));
if (commit_lock_file(lock))
die("could not close alternates file");
if (alt_odb_tail)
link_alt_odb_entries(alt, alt + strlen(alt), '\n', NULL, 0);
}

void prepare_alt_odb(void)
{
const char *alt;
Expand Down

0 comments on commit bef70b2

Please sign in to comment.