{"thread":{"id":"31118","subject":"[RFC/PATCH] Use work tree to determine if it supports symlinks","startedAt":"2012-07-27T21:39:41Z","lastAt":"2012-07-27T23:51:18Z","messageCount":5,"participants":["Sascha Cunz","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"195968","messageId":"17699041.7b2cBoDgE0@mephista","threadId":"31118","inReplyTo":null,"subject":"[RFC/PATCH] Use work tree to determine if it supports symlinks","fromName":"Sascha Cunz","fromEmail":"sascha-ml@babbelbox.org","sentAt":"2012-07-27T21:39:41Z","receivedAt":"2012-07-27T21:39:41Z","isPatch":true,"sender":{"key":"sascha-ml@babbelbox.org","avatar":null},"body":">From 3f449e719b924929f1f8ca9b5eff83f17bc64c60 Mon Sep 17 00:00:00 2001\nFrom: Sascha Cunz <Sascha@BabbelBox.org>\nDate: Fri, 27 Jul 2012 22:54:56 +0200\nSubject: [PATCH] Use work tree to determine if it supports symlinks\n\nWhen creating a new repository, we check some capabilities of the\nunderlying file system(s). We check the file system for its case\nsensitivity and the ability to create symbolic links.\n\nBefore this patch the .git-dir was used for this check, while the\ncomments in code clearly state to test on the work tree.\n\nThis patch teaches the tests for symbolic links and utf8 precomposion\nto use the work tree instead of the .git directory.\n\nSigned-off-by: Sascha Cunz <Sascha@BabbelBox.org>\n---\n builtin/init-db.c | 22 +++++++++++++++++-----\n 1 file changed, 17 insertions(+), 5 deletions(-)\n\nIn recent discussion[1] on libgit2, we found this little inconsistency\nand it's not exactly clear, whether the git implementation or documentation\nshould be followed.\n\nI left out to change the case-insensitive check. If you think, this patch\nis useful at all (I actually have a hard time to find a real world use\ncase), i would reroll it with that change included. I think in this case,\nthe probe_utf8_pathname_composition might be refactored: We don't have a\nfile in the work tree yet => we must create one, test its accessibility\nwith a different name and finally unlink it. That's more or less what\nprobe_utf8_pathname_composition does.\n\nSaCu\n\n[1] https://github.com/libgit2/libgit2/pull/844#issuecomment-7311677\n\ndiff --git a/builtin/init-db.c b/builtin/init-db.c\nindex 244fb7f..2f988ad 100644\n--- a/builtin/init-db.c\n+++ b/builtin/init-db.c\n@@ -273,6 +273,23 @@ static int create_default_files(const char *template_path)\n \t}\n \n \tif (!reinit) {\n+\t\tconst char *work_tree = get_git_work_tree();\n+\n+\t\t/* Check if the filesystem is case-insensitive */\n+\t\tpath[len] = 0;\n+\t\tstrcpy(path + len, \"CoNfIg\");\n+\t\tif (!access(path, F_OK))\n+\t\t\tgit_config_set(\"core.ignorecase\", \"true\");\n+\n+\t\t/* Point 'path' to the work tree */\n+\t\tlen = strlen(work_tree);\n+\t\tif (len > sizeof(path)-8)\n+\t\t\tdie(_(\"insane working directory %s\"), work_tree);\n+\n+\t\tmemcpy(path, work_tree, len);\n+\t\tif (len && path[len-1] != '/')\n+\t\t\tpath[len++] = '/';\n+\n \t\t/* Check if symlink is supported in the work tree */\n \t\tpath[len] = 0;\n \t\tstrcpy(path + len, \"tXXXXXX\");\n@@ -285,11 +302,6 @@ static int create_default_files(const char *template_path)\n \t\telse\n \t\t\tgit_config_set(\"core.symlinks\", \"false\");\n \n-\t\t/* Check if the filesystem is case-insensitive */\n-\t\tpath[len] = 0;\n-\t\tstrcpy(path + len, \"CoNfIg\");\n-\t\tif (!access(path, F_OK))\n-\t\t\tgit_config_set(\"core.ignorecase\", \"true\");\n \t\tprobe_utf8_pathname_composition(path, len);\n \t}\n \n-- \n1.7.12.rc0.23.g3f449e7\n"},{"id":"195970","messageId":"7vobn0zx5m.fsf@alter.siamese.dyndns.org","threadId":"31118","inReplyTo":"17699041.7b2cBoDgE0@mephista","subject":"Re: [RFC/PATCH] Use work tree to determine if it supports symlinks","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-07-27T21:55:49Z","receivedAt":"2012-07-27T21:55:49Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Sascha Cunz <Sascha-ML@babbelbox.org> writes:\n\n> From 3f449e719b924929f1f8ca9b5eff83f17bc64c60 Mon Sep 17 00:00:00 2001\n> From: Sascha Cunz <Sascha@BabbelBox.org>\n> Date: Fri, 27 Jul 2012 22:54:56 +0200\n> Subject: [PATCH] Use work tree to determine if it supports symlinks\n>\n> When creating a new repository, we check some capabilities of the\n> underlying file system(s). We check the file system for its case\n> sensitivity and the ability to create symbolic links.\n>\n> Before this patch the .git-dir was used for this check, while the\n> comments in code clearly state to test on the work tree.\n\nThat is simply because a layout that has .git and its containing\ndirectory (i.e. the working tree) on a separate filesystem when we\nrun \"git init\" is not supported, and more importantly, we do not\nwant to step outside \".git\", which is the simplest and safest way to\navoid touching the end-user data that sits in the working tree.\n\nThe code comment is about checking the filesystem that houses both\nthe working tree and \".git\"; if the user later wants to turn .git\ninto a separate mount point, or if the user wants to use GIT_DIR and\nGIT_WORK_TREE to create a funny layout, the user should know how to\nmuck with \".git/config\" to adjust to the peculiarity.\n"},{"id":"195977","messageId":"3068717.2K7be5iONg@mephista","threadId":"31118","inReplyTo":"7vobn0zx5m.fsf@alter.siamese.dyndns.org","subject":"Re: [RFC/PATCH] Use work tree to determine if it supports symlinks","fromName":"Sascha Cunz","fromEmail":"sascha@babbelbox.org","sentAt":"2012-07-27T22:40:37Z","receivedAt":"2012-07-27T22:40:37Z","isPatch":true,"sender":{"key":"sascha@babbelbox.org","avatar":"https://gravatar.com/avatar/14fb71bcad50c951a8c864b487f6390b89c350fc4916cf315fb5233c31e7377f?d=mp&s=160"},"body":"On Friday, July 27, 2012 02:55:49 PM you wrote:\n> Sascha Cunz <Sascha-ML@babbelbox.org> writes:\n> > From 3f449e719b924929f1f8ca9b5eff83f17bc64c60 Mon Sep 17 00:00:00 2001\n> > From: Sascha Cunz <Sascha@BabbelBox.org>\n> > Date: Fri, 27 Jul 2012 22:54:56 +0200\n> > Subject: [PATCH] Use work tree to determine if it supports symlinks\n> > \n> > When creating a new repository, we check some capabilities of the\n> > underlying file system(s). We check the file system for its case\n> > sensitivity and the ability to create symbolic links.\n> > \n> > Before this patch the .git-dir was used for this check, while the\n> > comments in code clearly state to test on the work tree.\n> \n> That is simply because a layout that has .git and its containing\n> directory (i.e. the working tree) on a separate filesystem when we\n> run \"git init\" is not supported,\n\nBut isn't enforced either. Are there known issues?\n\n> and more importantly, we do not\n> want to step outside \".git\", which is the simplest and safest way to\n> avoid touching the end-user data that sits in the working tree.\n\nWhile I think that this is true, I don't see the connection.\n\n> The code comment is about checking the filesystem that houses both\n> the working tree and \".git\"; if the user later wants to turn .git\n> into a separate mount point, or if the user wants to use GIT_DIR and\n> GIT_WORK_TREE to create a funny layout, the user should know how to\n> muck with \".git/config\" to adjust to the peculiarity.\n\nOk, so repository and working directory are simply not meant to be on \ndifferent file systems. Thanks for the clarification.\n"},{"id":"195979","messageId":"7vsjccyfo6.fsf@alter.siamese.dyndns.org","threadId":"31118","inReplyTo":"3068717.2K7be5iONg@mephista","subject":"Re: [RFC/PATCH] Use work tree to determine if it supports symlinks","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-07-27T22:58:49Z","receivedAt":"2012-07-27T22:58:49Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Sascha Cunz <Sascha@babbelbox.org> writes:\n\n> Ok, so repository and working directory are simply not meant to be on \n> different file systems. Thanks for the clarification.\n\nI did not mean \"and that is a rule we need to enforce and keep\nforever\". I was just answering your (implied) question \"why does\ncode comment, behaviour and documentation disagree?\", to give a data\npoint that would be useful when discussing what the ideal behaviour\nshould be.\n"},{"id":"195983","messageId":"5249760.yb8Rz8UMH4@mephista","threadId":"31118","inReplyTo":"7vsjccyfo6.fsf@alter.siamese.dyndns.org","subject":"Re: [RFC/PATCH] Use work tree to determine if it supports symlinks","fromName":"Sascha Cunz","fromEmail":"sascha-ml@babbelbox.org","sentAt":"2012-07-27T23:51:18Z","receivedAt":"2012-07-27T23:51:18Z","isPatch":true,"sender":{"key":"sascha-ml@babbelbox.org","avatar":null},"body":"On Friday, July 27, 2012 03:58:49 PM you wrote:\n> Sascha Cunz <Sascha@babbelbox.org> writes:\n\n> > Ok, so repository and working directory are simply not meant to be on\n> > different file systems. Thanks for the clarification.\n> \n> I did not mean \"and that is a rule we need to enforce and keep\n> forever\".\nI did not parse your statement as such - I just realized, that i probably \nwon't find a valid use case for using 2 file systems with different \ncapabilities. Which lead me to conclude that your \"is not supported\" is a \nsufficient response.\n\nThough, I think I have a valid use case for using different file systems: For \nspeed reasons one could setup .git to point to a different drive. I wanted to \ntry this ever since I saw, it would be possible - but I never came around \nactually trying it.\nHowever, if this would turn out to be an improvement, I don't think one would \nmix file systems with different capabilities (i.e. FAT+ext2).\n\n> I was just answering your (implied) question \"why does\n> code comment, behaviour and documentation disagree?\", to give a data\n> point that would be useful when discussing what the ideal behaviour\n> should be.\n\nI think, that 'git init --separate-git-dir' (without a 'different filesystems' \nrestriction) is some kind of support for creating non-bare repositories where \nwork tree and .git dir are located on different file systems.\n\nThen, in case a user _did_ setup a peculiar layout, an invocation of 'git \nsubmodule init' might make a call to 'git clone', which _should_ set \ncore.symlinks to false but doesn't. At that point the user might not remember \nin detail how peculiar the setup actually is - and at the same time did not \nrequest git to do anything special.\n\nI don't know how far-fetched that is, but it's at least possible.\n"}]}