Add support for GIT_CEILING_DIRS
PATCH 2/2 Add support for GIT_CEILING_DIRS
Make git recognize a new environment variable that prevents it from chdir'ing up into specified directories when looking for a GIT_DIR. Useful for avoiding slow network directories.
---
Just a bit of context about the motivation for this. I use git in an environment where homedirs are automounted and "ls /home/nonexistent" takes about 9 seconds. I use the git bash completion, which runs "git help -a". As of Git 1.5.5, this calls setup_git_directory_gently, which searches /home/.git and /home/objects, which takes forever, delaying all of my logins. This patch lets me set "GIT_CEILING_DIRS=/home", which makes this operation fast. As a bonus, the "git symbolic-ref HEAD" in my shell prompt now works quickly when I'm in a non-git directory.
Documentation/git.txt | 8 ++++ cache.h | 1 + setup.c | 67 +++++++++++++++++++++++++----- t/t1504-ceiling-dirs.sh | 104 +++++++++++++++++++++++++++++++++++++++++++++++ t/test-lib.sh | 1 + 5 files changed, 170 insertions(+), 11 deletions(-) create mode 100755 t/t1504-ceiling-dirs.sh
Documentation/git.txt +8 -0
@@ -415,6 +415,14 @@ git so take care if using Cogito etc. This can also be controlled by the '--work-tree' command line option and the core.worktree configuration variable. +'GIT_CEILING_DIRS':: + This should be a colon-separated list of absolute paths. + If set, it is a list of directories that git should not chdir + up into while looking for a repository directory. + It will not exclude the current working directory or + a GIT_DIR set on the command line or in the environment. + (Useful for excluding slow-loading network directories.) + git Commits ~~~~~~~~~~~ 'GIT_AUTHOR_NAME'::
cache.h +1 -0
@@ -300,6 +300,7 @@ static inline enum object_type object_type(unsigned int mode)#define CONFIG_ENVIRONMENT "GIT_CONFIG"#define CONFIG_LOCAL_ENVIRONMENT "GIT_CONFIG_LOCAL"#define EXEC_PATH_ENVIRONMENT "GIT_EXEC_PATH" +#define CEILING_DIRS_ENVIRONMENT "GIT_CEILING_DIRS"#define GITATTRIBUTES_FILE ".gitattributes"#define INFOATTRIBUTES_FILE "info/attributes"#define ATTRIBUTE_MACRO_PREFIX "[attr]"
setup.c +56 -11
95 lines not on this page · raw message
t/t1504-ceiling-dirs.sh new file +104 -0
104 lines not on this page · raw message
t/test-lib.sh +1 -0
@@ -35,6 +35,7 @@ unset GIT_WORK_TREE unset GIT_EXTERNAL_DIFF unset GIT_INDEX_FILE unset GIT_OBJECT_DIRECTORY +unset GIT_CEILING_DIRS unset SHA1_FILE_DIRECTORIES unset SHA1_FILE_DIRECTORY GIT_MERGE_VERBOSITY=5
Signature · 1 line
1.5.4
Hi,
Quoted 9 lines · David Reiss
Make git recognize a new environment variable that prevents it from chdir'ing up into specified directories when looking for a
GIT_DIR. Useful for avoiding slow network directories.Signed-off-by David Reiss <[email protected]>---
Just a bit of context about the motivation for this. I use git in an environment where homedirs are automounted and "ls/home/nonexistent" takes about 9 seconds.
I think this is a very strong argument in favor of your patch, so it belongs into the commit message.
Quoted 5 lines
setup.c +0
-0
setup.c const char *read_gitfile_gently(const char *path) · line 366
Quoted 9 lines
setup.c +2
-1@@ -359,10 +359,11 @@ const char *read_gitfile_gently(const char *path)const char *setup_git_directory_gently (int *nongit_ok) {const char *work_tree_env =getenv (GIT_WORK_TREE_ENVIRONMENT ); +const char *env_ceiling_dirs =getenv (CEILING_DIRS_ENVIRONMENT );static char cwd[PATH_MAX +1 ];const char *gitdirenv;const char *gitfile_dir; -int len, offset; +int len, offset, min_offset =-1 ;
AFAIR we have min_offset in the mingw branch, too, but I think it is initialized to 0.
setup.c const char *setup_git_directory_gently(int *nongit_ok) · line 418
Quoted 5 lines
setup.c +1
-0@@ -414,6 +415,37 @@ const char *setup_git_directory_gently(int *nongit_ok)if (!getcwd (cwd,sizeof (cwd)-1 ))die ("Unable to read current working directory" ); +// Compute min_offset based on GIT_CEILING_DIRS.
We do not like C99 style comments. Remember, there are people who compile Git on something else than the super-latest Linux with cutting-edge GCC.
setup.c const char *setup_git_directory_gently(int *nongit_ok) · line 421
Quoted 3 lines
setup.c +3
-0+if (env_ceiling_dirs) { +char *ceils, *ceil, *colon; + ceil = ceils =xstrdup (env_ceiling_dirs);
I think it is quite possible to do this without data copying.
Besides, I think that this whole block should be a function in path.c, if only to _document_ what it does: it is much easier to read for people who did not write the code.
Something like
int longest_prefix(const char *path, const char *prefix_list)
{
int max_length = 0, length = 0, i;
for (i = 0; *prefix_list; i++)
if (prefix_list[i] == ':') {
if (length > max_length)
max_length = length;
length = 0;
}
else if (length >= 0) {
if (prefix_list[i] == path[length])
length++;
else {
if (length > max_length)
max_length = length;
length = -1;
}
}
return max_length;
}(Completely untested, though.)
setup.c const char *setup_git_directory_gently(int *nongit_ok) · line 462
Quoted 5 lines
setup.c +1
-0@@ -427,6 +459,7 @@ const char *setup_git_directory_gently(int *nongit_ok)*/ offset = len =strlen (cwd);for (;;) { +// Check the current directory (.git first).
Again, C99 comments are a no-go.
Quoted 28 lines
setup.c +13
-10@@ -443,17 +476,29 @@ const char *setup_git_directory_gently(int *nongit_ok)check_repository_format_gently (nongit_ok);return NULL ; } -do { -if (!offset) { -if (nongit_ok) { -if (chdir (cwd)) -die ("Cannot come back to cwd" ); - *nongit_ok =1 ; -return NULL ; - } -die ("Not a git repository" ); + +// Did we just check the root dir? +if (!offset) { + not_a_repo: +if (nongit_ok) { +if (chdir (cwd)) +die ("Cannot come back to cwd" ); + *nongit_ok =1 ; +return NULL ; } - }while (cwd[--offset] !='/' ); +die ("Not a git repository" ); + } + +while (cwd[--offset] !='/' ) {
setup.c const char *setup_git_directory_gently(int *nongit_ok) · line 502
Quoted 10 lines
setup.c +9
-0+assert (offset >0 ); + } + +// Don't chdir into the ceiling. +if (offset <= min_offset) { +assert (offset == min_offset); + goto not_a_repo; + } +chdir (".." );
Why this big, ugly change in the code? I would have expected you to simply change the "if (!offset)" to "if (offset <= min_offset)" (together with the initialization to 0).
Quoted 14 lines
t/t1504-ceiling-dirs.sh new file +8
-0@@ -0,0 +1,104 @@ +#!/bin/sh + +test_description='test GIT_CEILING_DIRS' +. ./test-lib.sh + +test_prefix() { + test_expect_success "$1" \ + "test '$2' = \"\$(git rev-parse --show-prefix)\""
t/t1504-ceiling-dirs.sh line 18
Quoted 10 lines
t/t1504-ceiling-dirs.sh new file +10
-0+ shift + [ $# -eq 0 ] && return +} + +test_fail() { + test_expect_code 128 "$1: prefix" \ + "git rev-parse --show-prefix" + shift + [ $# -eq 0 ] && return +}
I think it would make more sense to write these out. Besides, I think that the "&& return" is not necessary.
And your tests are, uhm, quite extensive.
Ciao,
Dscho
Quoted 10 lines · Johannes Schindelin
Quoted 9 lines · David Reiss
setup.c +1
-0@@ -359,10 +359,11 @@ const char *read_gitfile_gently(const char *path)const char *setup_git_directory_gently (int *nongit_ok) {const char *work_tree_env =getenv (GIT_WORK_TREE_ENVIRONMENT ); +const char *env_ceiling_dirs =getenv (CEILING_DIRS_ENVIRONMENT );
Quoted 8 lines
setup.c const char *read_gitfile_gently(const char *path) · line 366
Quoted 5 lines
setup.c +1
-1static char cwd[PATH_MAX +1 ];const char *gitdirenv;const char *gitfile_dir; -int len, offset; +int len, offset, min_offset =-1 ;AFAIR we have
min_offsetin the mingw branch, too, but I think it is initialized to 0.
Yes, indeed, and even for much the same purpose (i.e. to stop before the beginning of the path is reached - on Windows we don't want to look at "C:" prefixes). Please look at this commit:
http://repo.or.cz/w/git/mingw/j6t.git?a=commitdiff;h=4ab30965f520bd444f3eefe1dee4622181933f90
-- Hannes
Quoted 9 lines · Johannes Schindelin
setup.c const char *setup_git_directory_gently(int · line 419
Quoted 6 lines
setup.c +1
-0@@ -414,6 +415,37 @@ const char *setup_git_directory_gently(int *nongit_ok)if (!getcwd (cwd,sizeof (cwd)-1 ))die ("Unable to read current working directory" ); +// Compute min_offset based on GIT_CEILING_DIRS. We do not like C99 style comments. Remember, there are people who compile Git on something else than the super-latest Linux with cutting-edge GCC.
Out of curiosity, what environment these days doesn't allow C99 comments? I think I started programming roughly 10 years ago (granted, I didn't start with C, but I did C programming at least 8 years ago, if not earlier) and every environment I've ever used has supported those comments even in C89 mode.
I mean, I fully understand that git wants to be portable across all platforms, but it still makes me wonder if there's any environment that anybody actually uses these days that doesn't understand those comments when compiling C.
Signature · 4 lines
Kevin Ballard http://kevin.sb.org [email protected] http://www.tildesoft.com
Hi,
Quoted 6 lines · Kevin Ballard
Quoted 4 lines · Johannes Schindelin
Quoted 4 lines
setup.c +0
-0@@ -414,6 +415,37 @@ const char *setup_git_directory_gently(int *nongit_ok)if (!getcwd (cwd,sizeof (cwd)-1 ))die ("Unable to read current working directory" );
Quoted 6 lines
Quoted 4 lines
setup.c const char *setup_git_directory_gently(int *nongit_ok) · line 418
Quoted 1 line
setup.c +1
-0+// Compute min_offset based on GIT_CEILING_DIRS. We do not like C99 style comments. Remember, there are people who compile Git on something else than the super-latest Linux with cutting-edge GCC.
Out of curiosity, what environment these days doesn't allow C99 comments?
On an SGI/IRIX machine I was working some time ago, GCC was too big for my quota. And the admin was not willing to install it.
But I have to wonder: why argue something as C99 comments, when it is _no problem_ whatsoever to replace them with C89-style comments, especially given the fact that this makes our source code more consistent and thus easier on the eye?
Ciao,
Dscho
Quoted 16 lines · Johannes Schindelin
Quoted 7 lines · Kevin Ballard
Quoted 5 lines · Johannes Schindelin
Quoted 5 lines
setup.c +0
-0@@ -414,6 +415,37 @@ const char *setup_git_directory_gently(int *nongit_ok)if (!getcwd (cwd,sizeof (cwd)-1 ))die ("Unable to read current working directory" );Quoted 6 lines
Quoted 4 lines
setup.c const char *setup_git_directory_gently(int *nongit_ok) · line 418
Quoted 1 line
setup.c +1
-0+// Compute min_offset based on GIT_CEILING_DIRS. We do not like C99 style comments. Remember, there are people who compile Git on something else than the super-latest Linux with cutting-edge GCC.
Out of curiosity, what environment these days doesn't allow C99 comments?
Quoted 7 lines
On an SGI/IRIX machine I was working some time ago, GCC was too big for my quota. And the admin was not willing to install it.
But I have to wonder: why argue something as C99 comments, when it is
_noproblem_whatsoever to replace them with C89-style comments, especially given the fact that this makes our source code more consistent and thus easier on the eye?
Oh I wasn't intending to argue, I just was curious. I'm always happy to adopt the style of the surrounding code (except when people use the One True Brace Style, ugh).
Granted, I personally prefer C99 comments for one-liners and C89 comments for multi-liners. It's especially helpful if the comment goes off the right side of the screen, because I don't have to hunt for the closing */ (source code highlighting generally solves this issue, but I don't always read code in an environment that can understand it, e.g. email).
-Kevin Ballard
Signature · 4 lines
Kevin Ballard http://kevin.sb.org [email protected] http://www.tildesoft.com