{"thread":{"id":"13165","subject":"[PATCH 3/8] Add a library function to add an alternate to the alternates file","startedAt":"2008-04-17T23:32:30Z","lastAt":"2008-04-17T23:32:30Z","messageCount":1,"participants":["Daniel Barkalow"],"isPatch":true,"patchVersion":1,"patchTotal":8},"messages":[{"id":"74697","messageId":"alpine.LNX.1.00.0804171931520.19665@iabervon.org","threadId":"13165","inReplyTo":null,"subject":"[PATCH 3/8] Add a library function to add an alternate to the alternates file","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2008-04-17T23:32:30Z","receivedAt":"2008-04-17T23:32:30Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"This is in the core so that, if the alternates file has already been\nread, the addition can be parsed and put into effect for the current\nprocess.\n\nSigned-off-by: Daniel Barkalow <barkalow@iabervon.org>\n---\n cache.h     |    1 +\n sha1_file.c |   12 ++++++++++++\n 2 files changed, 13 insertions(+), 0 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 4a113b0..96dcb49 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -589,6 +589,7 @@ extern struct alternate_object_database {\n \tchar base[FLEX_ARRAY]; /* more */\n } *alt_odb_list;\n extern void prepare_alt_odb(void);\n+extern void add_to_alternates_file(const char *reference);\n \n struct pack_window {\n \tstruct pack_window *next;\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 445a871..1aa3cef 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -379,6 +379,18 @@ static void read_info_alternates(const char * relative_base, int depth)\n \tmunmap(map, mapsz);\n }\n \n+void add_to_alternates_file(const char *reference)\n+{\n+\tstruct lock_file *lock = xcalloc(1, sizeof(struct lock_file));\n+\tint fd = hold_lock_file_for_append(lock, git_path(\"objects/info/alternates\"), 1);\n+\tchar *alt = mkpath(\"%s/objects\\n\", reference);\n+\twrite_or_die(fd, alt, strlen(alt));\n+\tif (commit_lock_file(lock))\n+\t\tdie(\"could not close alternates file\");\n+\tif (alt_odb_tail)\n+\t\tlink_alt_odb_entries(alt, alt + strlen(alt), '\\n', NULL, 0);\n+}\n+\n void prepare_alt_odb(void)\n {\n \tconst char *alt;\n-- \n1.5.4.3.610.gea6cd\n"}]}