{"thread":{"id":"23042","subject":"[PATCH 2/2] Add support for GIT_ONE_FILESYSTEM","startedAt":"2010-03-16T22:04:59Z","lastAt":"2010-03-17T07:09:32Z","messageCount":5,"participants":["Lars R. Damerow","Nguyen Thai Ngoc Duy","Johannes Sixt"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"136978","messageId":"1268777101-22122-1-git-send-email-lars@pixar.com","threadId":"23042","inReplyTo":null,"subject":"[PATCH 0/2] Add support for GIT_ONE_FILESYSTEM (resubmission)","fromName":"Lars R. Damerow","fromEmail":"lars@pixar.com","sentAt":"2010-03-16T22:04:59Z","receivedAt":"2010-03-16T22:04:59Z","isPatch":true,"sender":{"key":"lars@pixar.com","avatar":"https://avatars.githubusercontent.com/u/318366?v=4"},"body":"\nHi all,\n\nI incorporated the feedback I got into a new patch for\nGIT_ONE_FILESYSTEM. It uses git_env_bool, doesn't do getenv calls within\nthe loop, and reports better error messages.\n\ngit_env_bool was marked static in config.c, so I had to remove that to\nmake it available in setup.c.\n\nLars R. Damerow (2):\n      config.c: remove static keyword from git_env_bool()\n      Add support for GIT_ONE_FILESYSTEM\n\n Documentation/git.txt |    3 +++\n cache.h               |    1 +\n config.c              |    2 +-\n setup.c               |   17 ++++++++++++++++-\n 4 files changed, 21 insertions(+), 2 deletions(-)\n"},{"id":"136977","messageId":"1268777101-22122-2-git-send-email-lars@pixar.com","threadId":"23042","inReplyTo":"1268777101-22122-1-git-send-email-lars@pixar.com","subject":"[PATCH 1/2] config.c: remove static keyword from git_env_bool()","fromName":"Lars R. Damerow","fromEmail":"lars@pixar.com","sentAt":"2010-03-16T22:05:00Z","receivedAt":"2010-03-16T22:05:00Z","isPatch":true,"sender":{"key":"lars@pixar.com","avatar":"https://avatars.githubusercontent.com/u/318366?v=4"},"body":"Since this function is the preferred way to handle boolean environment\nvariables it's useful to have it available to other files.\n\nSigned-off-by: Lars R. Damerow <lars@pixar.com>\n---\n cache.h  |    1 +\n config.c |    2 +-\n 2 files changed, 2 insertions(+), 1 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 89f6a40..c29030f 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -945,6 +945,7 @@ extern int git_config_set_multivar(const char *, const char *, const char *, int\n extern int git_config_rename_section(const char *, const char *);\n extern const char *git_etc_gitconfig(void);\n extern int check_repository_format_version(const char *var, const char *value, void *cb);\n+extern int git_env_bool(const char *, int);\n extern int git_config_system(void);\n extern int git_config_global(void);\n extern int config_error_nonbool(const char *);\ndiff --git a/config.c b/config.c\nindex 6963fbe..70e4600 100644\n--- a/config.c\n+++ b/config.c\n@@ -683,7 +683,7 @@ const char *git_etc_gitconfig(void)\n \treturn system_wide;\n }\n \n-static int git_env_bool(const char *k, int def)\n+int git_env_bool(const char *k, int def)\n {\n \tconst char *v = getenv(k);\n \treturn v ? git_config_bool(k, v) : def;\n-- \n1.6.5.2\n"},{"id":"136976","messageId":"1268777101-22122-3-git-send-email-lars@pixar.com","threadId":"23042","inReplyTo":"1268777101-22122-1-git-send-email-lars@pixar.com","subject":"[PATCH 2/2] Add support for GIT_ONE_FILESYSTEM","fromName":"Lars R. Damerow","fromEmail":"lars@pixar.com","sentAt":"2010-03-16T22:05:01Z","receivedAt":"2010-03-16T22:05:01Z","isPatch":true,"sender":{"key":"lars@pixar.com","avatar":"https://avatars.githubusercontent.com/u/318366?v=4"},"body":"This patch makes git pay attention to the GIT_ONE_FILESYSTEM environment\nvariable. When that variable is set, git will stop searching for a\nGIT_DIR when it attempts to cross a filesystem boundary.\n\nWhen working in an environment with too many automount points to make\nmaintaining a GIT_CEILING_DIRECTORIES list enjoyable, GIT_ONE_FILESYSTEM\ngives the option of turning all such attempts off with one setting.\n\nSigned-off-by: Lars R. Damerow <lars@pixar.com>\n---\n Documentation/git.txt |    3 +++\n setup.c               |   17 ++++++++++++++++-\n 2 files changed, 19 insertions(+), 1 deletions(-)\n\ndiff --git a/Documentation/git.txt b/Documentation/git.txt\nindex 35c0c79..dbb590f 100644\n--- a/Documentation/git.txt\n+++ b/Documentation/git.txt\n@@ -529,6 +529,9 @@ git so take care if using Cogito etc.\n \ta GIT_DIR set on the command line or in the environment.\n \t(Useful for excluding slow-loading network directories.)\n \n+'GIT_ONE_FILESYSTEM'::\n+\tStop at filesystem boundaries when looking for .git or objects.\n+\n git Commits\n ~~~~~~~~~~~\n 'GIT_AUTHOR_NAME'::\ndiff --git a/setup.c b/setup.c\nindex 5716d90..d40e2e6 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -319,10 +319,12 @@ const char *setup_git_directory_gently(int *nongit_ok)\n {\n \tconst char *work_tree_env = getenv(GIT_WORK_TREE_ENVIRONMENT);\n \tconst char *env_ceiling_dirs = getenv(CEILING_DIRECTORIES_ENVIRONMENT);\n-\tstatic char cwd[PATH_MAX+1];\n+\tstatic char cwd[PATH_MAX+1], err_cwd[PATH_MAX+1];\n \tconst char *gitdirenv;\n \tconst char *gitfile_dir;\n \tint len, offset, ceil_offset, root_len;\n+\tint current_device = 0, one_filesystem = 0;\n+\tstruct stat buf;\n \n \t/*\n \t * Let's assume that we are in a git repository.\n@@ -390,6 +392,11 @@ const char *setup_git_directory_gently(int *nongit_ok)\n \t *   etc.\n \t */\n \toffset = len = strlen(cwd);\n+\tif ((one_filesystem = git_env_bool(\"GIT_ONE_FILESYSTEM\", 0))) {\n+\t\tif (stat(\".\", &buf))\n+\t\t\tdie_errno(\"failed to stat '.'\");\n+\t\tcurrent_device = buf.st_dev;\n+\t}\n \tfor (;;) {\n \t\tgitfile_dir = read_gitfile_gently(DEFAULT_GIT_DIR_ENVIRONMENT);\n \t\tif (gitfile_dir) {\n@@ -422,6 +429,14 @@ const char *setup_git_directory_gently(int *nongit_ok)\n \t\t\t}\n \t\t\tdie(\"Not a git repository (or any of the parent directories): %s\", DEFAULT_GIT_DIR_ENVIRONMENT);\n \t\t}\n+\t\tif (one_filesystem) {\n+\t\t\tif (stat(\"..\", &buf))\n+\t\t\t\tdie_errno(\"failed to stat '%s/..'\", getcwd(err_cwd, sizeof(err_cwd)-1));\n+\t\t\tif (buf.st_dev != current_device)\n+\t\t\t\tdie(\"Not a git repository (or any parent up to %s/..)\\n\"\n+\t\t\t\t\t\"Stopping at filesystem boundary since GIT_ONE_FILESYSTEM is set.\",\n+\t\t\t\t\tgetcwd(err_cwd, sizeof(err_cwd)-1));\n+\t\t}\n \t\tif (chdir(\"..\"))\n \t\t\tdie_errno(\"Cannot change to '%s/..'\", cwd);\n \t}\n-- \n1.6.5.2\n"},{"id":"136983","messageId":"fcaeb9bf1003161745j17d13a8dv248d169276777c8a@mail.gmail.com","threadId":"23042","inReplyTo":"1268777101-22122-3-git-send-email-lars@pixar.com","subject":"Re: [PATCH 2/2] Add support for GIT_ONE_FILESYSTEM","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-03-17T00:45:50Z","receivedAt":"2010-03-17T00:45:50Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On 3/17/10, Lars R. Damerow <lars@pixar.com> wrote:\n>  @@ -422,6 +429,14 @@ const char *setup_git_directory_gently(int *nongit_ok)\n>                         }\n>                         die(\"Not a git repository (or any of the parent directories): %s\", DEFAULT_GIT_DIR_ENVIRONMENT);\n>                 }\n>  +               if (one_filesystem) {\n>  +                       if (stat(\"..\", &buf))\n>  +                               die_errno(\"failed to stat '%s/..'\", getcwd(err_cwd, sizeof(err_cwd)-1));\n>  +                       if (buf.st_dev != current_device)\n>  +                               die(\"Not a git repository (or any parent up to %s/..)\\n\"\n>  +                                       \"Stopping at filesystem boundary since GIT_ONE_FILESYSTEM is set.\",\n>  +                                       getcwd(err_cwd, sizeof(err_cwd)-1));\n>  +               }\n>                 if (chdir(\"..\"))\n>                         die_errno(\"Cannot change to '%s/..'\", cwd);\n>         }\n\nIt should not die() if nongit_ok != NULL (gentle mode). Maybe\nsomething like this on top:\n\ndiff --git a/setup.c b/setup.c\nindex 500c03e..625fb35 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -499,10 +499,17 @@ static const char\n*setup_git_directory_gently_1(int *nongit_ok)\n \t\tif (one_filesystem) {\n \t\t\tif (stat(\"..\", &buf))\n \t\t\t\tdie_errno(\"failed to stat '%s/..'\", getcwd(err_cwd, sizeof(err_cwd)-1));\n-\t\t\tif (buf.st_dev != current_device)\n+\t\t\tif (buf.st_dev != current_device) {\n+\t\t\t\tif (nongit_ok) {\n+\t\t\t\t\tif (chdir(cwd))\n+\t\t\t\t\t\tdie_errno(\"Cannot come back to cwd\");\n+\t\t\t\t\t*nongit_ok = 1;\n+\t\t\t\t\treturn NULL;\n+\t\t\t\t}\n \t\t\t\tdie(\"Not a git repository (or any parent up to %s/..)\\n\"\n \t\t\t\t\t\"Stopping at filesystem boundary since GIT_ONE_FILESYSTEM is set.\",\n \t\t\t\t\tgetcwd(err_cwd, sizeof(err_cwd)-1));\n+\t\t\t}\n \t\t}\n \t\tif (chdir(\"..\"))\n \t\t\tdie_errno(\"Cannot change to '%s/..'\", cwd);\n\nAnother thing. Is err_cwd needed? I think \"cwd\" can be used, like\ndie_errno(\"Cannot change to %s/..\", cwd) above. Hmm.. that die_errno\nneeds \"cwd[offset] = '\\0';\" first. Maybe you can fix it too ;-)\n-- \nDuy\n"},{"id":"136992","messageId":"4BA0802C.3020603@viscovery.net","threadId":"23042","inReplyTo":"1268777101-22122-3-git-send-email-lars@pixar.com","subject":"Re: [PATCH 2/2] Add support for GIT_ONE_FILESYSTEM","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2010-03-17T07:09:32Z","receivedAt":"2010-03-17T07:09:32Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Lars R. Damerow schrieb:\n> @@ -422,6 +429,14 @@ const char *setup_git_directory_gently(int *nongit_ok)\n>  \t\t\t}\n>  \t\t\tdie(\"Not a git repository (or any of the parent directories): %s\", DEFAULT_GIT_DIR_ENVIRONMENT);\n>  \t\t}\n> +\t\tif (one_filesystem) {\n> +\t\t\tif (stat(\"..\", &buf))\n> +\t\t\t\tdie_errno(\"failed to stat '%s/..'\", getcwd(err_cwd, sizeof(err_cwd)-1));\n\nWhen stat of .. fails, then it is not unlikely that getcwd fails, too.\nThen you would report the errno produced by getcwd.\n\nBut can't you avoid this getcwd()? The die() call in the context below\nuses cwd.\n\n> +\t\t\tif (buf.st_dev != current_device)\n> +\t\t\t\tdie(\"Not a git repository (or any parent up to %s/..)\\n\"\n> +\t\t\t\t\t\"Stopping at filesystem boundary since GIT_ONE_FILESYSTEM is set.\",\n> +\t\t\t\t\tgetcwd(err_cwd, sizeof(err_cwd)-1));\n> +\t\t}\n>  \t\tif (chdir(\"..\"))\n>  \t\t\tdie_errno(\"Cannot change to '%s/..'\", cwd);\n>  \t}\n\n-- Hannes\n"}]}