{"thread":{"id":"12590","subject":"[PATCH 05/11] Add a library function to add an alternate to the alternates file","startedAt":"2008-03-08T23:04:10Z","lastAt":"2008-03-08T23:22:41Z","messageCount":3,"participants":["Daniel Barkalow","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":11},"messages":[{"id":"71463","messageId":"alpine.LNX.1.00.0803081804090.19665@iabervon.org","threadId":"12590","inReplyTo":null,"subject":"[PATCH 05/11] Add a library function to add an alternate to the alternates file","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2008-03-08T23:04:10Z","receivedAt":"2008-03-08T23:04:10Z","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 |   19 +++++++++++++++++++\n 2 files changed, 20 insertions(+), 0 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex bdefcc9..6aae174 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -587,6 +587,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..4ce4d9d 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -379,6 +379,25 @@ 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+\tchar *file;\n+\tchar *alt;\n+\tint fd;\n+\n+\tfile = mkpath(\"%s/objects/info/alternates\", get_git_dir());\n+\tfd = open(file, O_CREAT | O_WRONLY | O_APPEND, 0666);\n+\tif (fd < 0)\n+\t\tdie(\"failed to create %s\", file);\n+\talt = mkpath(\"%s/objects\\n\", reference);\n+\twrite_or_die(fd, alt, strlen(alt));\n+\tif (close(fd))\n+\t\tdie(\"could not close %s\", file);\n+\tfprintf(stderr, \"Wrote %s to %s\\n\", alt, 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.327.g614d7.dirty\n\n"},{"id":"71470","messageId":"alpine.LSU.1.00.0803090017150.3975@racer.site","threadId":"12590","inReplyTo":"alpine.LNX.1.00.0803081804090.19665@iabervon.org","subject":"Re: [PATCH 05/11] Add a library function to add an alternate to the alternates file","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-03-08T23:18:16Z","receivedAt":"2008-03-08T23:18:16Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sat, 8 Mar 2008, Daniel Barkalow wrote:\n\n\n> +void add_to_alternates_file(const char *reference)\n> +{\n> +\tchar *file;\n> +\tchar *alt;\n> +\tint fd;\n> +\n> +\tfile = mkpath(\"%s/objects/info/alternates\", get_git_dir());\n> +\tfd = open(file, O_CREAT | O_WRONLY | O_APPEND, 0666);\n> +\tif (fd < 0)\n> +\t\tdie(\"failed to create %s\", file);\n\nEven with alternates, which are probably written only rarely, I would have \nexpected a lockfile procedure (if only to be consistent with the rest).\n\nCiao,\nDscho\n\n"},{"id":"71474","messageId":"alpine.LNX.1.00.0803081820310.19665@iabervon.org","threadId":"12590","inReplyTo":"alpine.LSU.1.00.0803090017150.3975@racer.site","subject":"Re: [PATCH 05/11] Add a library function to add an alternate to the alternates file","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2008-03-08T23:22:41Z","receivedAt":"2008-03-08T23:22:41Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"On Sun, 9 Mar 2008, Johannes Schindelin wrote:\n\n> Hi,\n> \n> On Sat, 8 Mar 2008, Daniel Barkalow wrote:\n> \n> \n> > +void add_to_alternates_file(const char *reference)\n> > +{\n> > +\tchar *file;\n> > +\tchar *alt;\n> > +\tint fd;\n> > +\n> > +\tfile = mkpath(\"%s/objects/info/alternates\", get_git_dir());\n> > +\tfd = open(file, O_CREAT | O_WRONLY | O_APPEND, 0666);\n> > +\tif (fd < 0)\n> > +\t\tdie(\"failed to create %s\", file);\n> \n> Even with alternates, which are probably written only rarely, I would have \n> expected a lockfile procedure (if only to be consistent with the rest).\n\nThat's a good idea; I started with this inside clone, where you can be \npretty certain not to get contention (and the shell version is using >> to \nupdate it), but in the library the lockfile is the right thing to do, so \nthat other code can use it safely.\n\n\t-Daniel\n*This .sig left intentionally blank*\n"}]}