{"thread":{"id":"2229","subject":"[PATCH 1/4] git-init-db should error out with a message","startedAt":"2005-10-25T23:39:24Z","lastAt":"2005-10-26T23:18:32Z","messageCount":5,"participants":["Johannes Schindelin","Alex Riesen","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"10625","messageId":"Pine.LNX.4.63.0510260139000.30576@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"2229","inReplyTo":null,"subject":"[PATCH 1/4] git-init-db should error out with a message","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2005-10-25T23:39:24Z","receivedAt":"2005-10-25T23:39:24Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"When the HEAD symref could not be created, it is helpful for the user to \nknow that.\n\nSigned-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n\n---\n\n init-db.c |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\napplies-to: 51f96562f1ef47cd9a09731e3f27445efaddbbe7\n159c632ef3cc7371aaa495c41afd5fd41e2d3f3f\ndiff --git a/init-db.c b/init-db.c\nindex aabc09f..2c27e18 100644\n--- a/init-db.c\n+++ b/init-db.c\n@@ -192,7 +192,7 @@ static void create_default_files(const c\n \tstrcpy(path + len, \"HEAD\");\n \tif (read_ref(path, sha1) < 0) {\n \t\tif (create_symref(path, \"refs/heads/master\") < 0)\n-\t\t\texit(1);\n+\t\t\tdie(\"Could not create HEAD symref!\");\n \t}\n \tpath[len] = 0;\n \tcopy_templates(path, len, template_path);\n---\n0.99.8.GIT\n"},{"id":"10679","messageId":"20051026194520.GC8030@steel.home","threadId":"2229","inReplyTo":"Pine.LNX.4.63.0510260139000.30576@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH 1/4] git-init-db should error out with a message","fromName":"Alex Riesen","fromEmail":"fork0@users.sourceforge.net","sentAt":"2005-10-26T19:45:20Z","receivedAt":"2005-10-26T19:45:20Z","isPatch":true,"sender":{"key":"fork0@users.sourceforge.net","avatar":null},"body":"Johannes Schindelin, Wed, Oct 26, 2005 01:39:24 +0200:\n> When the HEAD symref could not be created, it is helpful for the user to \n> know that.\n> \n\nNot just that. It would be interesting to give the user an option to\nuse the file references (\"ref: refs/heads/master\").\nSomething like that:\n\nAdd --no-symref (make init-db use file references)\n\n---\n\n cache.h   |    1 +\n init-db.c |   11 +++++++++--\n refs.c    |    7 ++++++-\n 3 files changed, 16 insertions(+), 3 deletions(-)\n\napplies-to: dba443573167bb9b0023613428e6d1a69477fac6\n097ca1bf9b21d19d425e8151986eb36f82cbeff3\ndiff --git a/cache.h b/cache.h\nindex d776016..e410ce2 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -239,6 +239,7 @@ extern char *sha1_to_hex(const unsigned \n extern int read_ref(const char *filename, unsigned char *sha1);\n extern const char *resolve_ref(const char *path, unsigned char *sha1, int);\n extern int create_symref(const char *git_HEAD, const char *refs_heads_master);\n+extern int create_file_symref(const char *git_HEAD, const char *refs_heads_master);\n extern int validate_symref(const char *git_HEAD);\n \n /* General helper functions */\ndiff --git a/init-db.c b/init-db.c\nindex aabc09f..2d2b705 100644\n--- a/init-db.c\n+++ b/init-db.c\n@@ -161,6 +161,8 @@ static void copy_templates(const char *g\n \tclosedir(dir);\n }\n \n+static int try_symref = 1;\n+\n static void create_default_files(const char *git_dir,\n \t\t\t\t char *template_path)\n {\n@@ -191,8 +193,11 @@ static void create_default_files(const c\n \t */\n \tstrcpy(path + len, \"HEAD\");\n \tif (read_ref(path, sha1) < 0) {\n-\t\tif (create_symref(path, \"refs/heads/master\") < 0)\n-\t\t\texit(1);\n+\t\tint err = 0;\n+\t\tif ( try_symref )\n+\t\t\terr = create_symref(path, \"refs/heads/master\");\n+\t\tif ( !err && create_file_symref(path, \"refs/heads/master\") < 0 )\n+\t\t\tdie(\"cannot create %s\", path);\n \t}\n \tpath[len] = 0;\n \tcopy_templates(path, len, template_path);\n@@ -220,6 +225,8 @@ int main(int argc, char **argv)\n \t\t\tbreak;\n \t\telse if (!strncmp(arg, \"--template=\", 11))\n \t\t\ttemplate_dir = arg+11;\n+\t\telse if (!strcmp(arg, \"--no-symref\"))\n+\t\t\ttry_symref = 0;\n \t\telse\n \t\t\tdie(init_db_usage);\n \t}\ndiff --git a/refs.c b/refs.c\nindex 97506a4..8029667 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -120,6 +120,12 @@ int create_symref(const char *git_HEAD, \n \tunlink(git_HEAD);\n \treturn symlink(refs_heads_master, git_HEAD);\n #else\n+\treturn create_file_symref(git_HEAD, refs_heads_master);\n+#endif\n+}\n+\n+int create_file_symref(const char *git_HEAD, const char *refs_heads_master)\n+{\n \tconst char *lockpath;\n \tchar ref[1000];\n \tint fd, len, written;\n@@ -144,7 +150,6 @@ int create_symref(const char *git_HEAD, \n \t\treturn -3;\n \t}\n \treturn 0;\n-#endif\n }\n \n int read_ref(const char *filename, unsigned char *sha1)\n---\n0.99.8.GIT\n"},{"id":"10684","messageId":"7v3bmoc9d7.fsf@assigned-by-dhcp.cox.net","threadId":"2229","inReplyTo":"20051026194520.GC8030@steel.home","subject":"Re: [PATCH 1/4] git-init-db should error out with a message","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-10-26T20:27:00Z","receivedAt":"2005-10-26T20:27:00Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Alex Riesen <fork0@users.sourceforge.net> writes:\n\n> Not just that. It would be interesting to give the user an option to\n> use the file references (\"ref: refs/heads/master\").\n\nActually, the users should not have to care how HEAD reference\nis implemented.  It might make sense to use regular file symref\nregardless of platforms (i.e. never define USE_SYMLINK_HEAD on\nany platform).\n\nWe support reading from either kind of symref, so if we did\nthat, the only case that *could* matter form compatibility point\nof view is that repositories touched by the updated git is\nunusable for an ancient git that does not understand regular\nfile symref.  From performance and simplicity point of view,\nhowever, using symlink when possible is better, and that is what\nJohannes' patch does.\n\nHOWEVER, I think \"falling back\" (both in Johannes' patch which\nis in the \"master\" branch, and your version) has a funny failure\nmode.  What happens when two processes try redirecting .git/HEAD\nsimultaneously, possibly to different branch heads?  Both of\nthem unlink(), one successfully does symlink(), and the other\ngets EEXIST and falls back to create regular file symref.\n\nWhich is probably not so wrong; if this race matters, then you\nhave bigger problem -- the user is doing 'git checkout' of\ndifferent branches at the same time, or something silly like\nthat.  But it does not feel quite right, either.\n"},{"id":"10685","messageId":"20051026204727.GA19846@steel.home","threadId":"2229","inReplyTo":"7v3bmoc9d7.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 1/4] git-init-db should error out with a message","fromName":"Alex Riesen","fromEmail":"fork0@users.sourceforge.net","sentAt":"2005-10-26T20:47:27Z","receivedAt":"2005-10-26T20:47:27Z","isPatch":true,"sender":{"key":"fork0@users.sourceforge.net","avatar":null},"body":"Junio C Hamano, Wed, Oct 26, 2005 22:27:00 +0200:\n> > Not just that. It would be interesting to give the user an option to\n> > use the file references (\"ref: refs/heads/master\").\n> \n> Actually, the users should not have to care how HEAD reference\n> is implemented.  It might make sense to use regular file symref\n> regardless of platforms (i.e. never define USE_SYMLINK_HEAD on\n> any platform).\n\nThis my idea too. All the time I was doing that patch :)\n\n> HOWEVER, I think \"falling back\" (both in Johannes' patch which\n> is in the \"master\" branch, and your version) has a funny failure\n> mode.  What happens when two processes try redirecting .git/HEAD\n> simultaneously, possibly to different branch heads?  Both of\n> them unlink(), one successfully does symlink(), and the other\n> gets EEXIST and falls back to create regular file symref.\n\nI think the file ref version uses rename of HEAD.lock into HEAD, doesn't it?\nRename(2) should just remove the symlink, right?\n"},{"id":"10687","messageId":"7vhdb3c1fb.fsf@assigned-by-dhcp.cox.net","threadId":"2229","inReplyTo":"20051026204727.GA19846@steel.home","subject":"Re: [PATCH 1/4] git-init-db should error out with a message","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-10-26T23:18:32Z","receivedAt":"2005-10-26T23:18:32Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Alex Riesen <fork0@users.sourceforge.net> writes:\n\n> I think the file ref version uses rename of HEAD.lock into HEAD, doesn't it?\n> Rename(2) should just remove the symlink, right?\n\nIf everybody used symlink or if everybody used regular file\nsymref, we would catch this race and the second one will be\nstopped.  My point was that by falling back we are introducing\nthis unnecessary race, which might be unimportant but still it\nis a new race.\n\nTo avoid that, I think symlink version needs to honor the\nHEAD.lock convention, which would slow down normal cases.\n"}]}