From: Daniel Barkalow Date: Thu, 17 Apr 2008 23:32:30 +0000 (-0400) Subject: Add a library function to add an alternate to the alternates file X-Git-Tag: v1.5.6-rc0~5^2~11 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=bef70b22ba63d71c1ae2e070e64ff9863ea1ad14;p=git.git 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 Signed-off-by: Junio C Hamano --- diff --git a/cache.h b/cache.h index 396eabf6e..9da9179af 100644 --- a/cache.h +++ b/cache.h @@ -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; diff --git a/sha1_file.c b/sha1_file.c index 3516777bc..d21e23b46 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -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;