@matheusbsbs / matheus-bagliano / commits / bef70b22ba
Fork 0

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 <barkalow@iabervon.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Daniel Barkalow committed Apr 17, 2008 at 19:32 UTC bef70b22ba63d71c1ae2e070e64ff9863ea1ad14
2 files changed +13
cache.h
+1
@@ -599,6 +599,7 @@ extern struct alternate_object_database {
599 char base[FLEX_ARRAY]; /* more */
600 } *alt_odb_list;
601 extern void prepare_alt_odb(void);
602 +extern void add_to_alternates_file(const char *reference);
603
604 struct pack_window {
605 struct pack_window *next;
sha1_file.c
+12
@@ -380,6 +380,18 @@ static void read_info_alternates(const char * relative_base, int depth)
380 munmap(map, mapsz);
381 }
382
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 +
395 void prepare_alt_odb(void)
396 {
397 const char *alt;