"git help -a" should search all exec_paths and PATH
PATCH 1/1 "git help -a" should search all exec_paths and PATH
Currently "git help -a" only searches in the highest priority exec_path, meaning at worst, nothing is listed if the git commands are only available from the PATH. It also makes git slightly less extensible.
To fix this, help.c is modified to search in all the exec_paths and PATH for potential git commands. So that it has access to all the exec_paths, exec_cmd.c now exposes the various paths. "current_exec_path" is renamed as its name is misleading.
--- exec_cmd.c | 26 +++++++++++--- exec_cmd.h | 3 ++ git.c | 2 +- help.c | 103 +++++++++++++++++++++++++++++++++++++++++++----------------- 4 files changed, 98 insertions(+), 36 deletions(-)
exec_cmd.c +20 -6
@@ -5,21 +5,35 @@extern char **environ;static const char *builtin_exec_path =GIT_EXEC_PATH ; -static const char *current_exec_path; +static const char *argv_exec_path; -void git_set_exec_path (const char *exec_path) +void git_set_argv_exec_path (const char *exec_path) { - current_exec_path = exec_path; + argv_exec_path = exec_path; } +const char *git_argv_exec_path (void ) +{ +return argv_exec_path; +} + +const char *git_builtin_exec_path (void ) +{ +return builtin_exec_path; +} + +const char *git_env_exec_path (void ) +{ +return getenv (EXEC_PATH_ENVIRONMENT ); +}/* Returns the highest-priority, location to look for git programs. */ const char *git_exec_path (void ) {const char *env; -if (current_exec_path) -return current_exec_path; +if (argv_exec_path) +return argv_exec_path; env =getenv (EXEC_PATH_ENVIRONMENT );if (env && *env) {
@@ -34,7 +48,7 @@ int execv_git_cmd(const char **argv) {char git_command[PATH_MAX +1 ];int i; -const char *paths[] = { current_exec_path, +const char *paths[] = { argv_exec_path,getenv (EXEC_PATH_ENVIRONMENT ), builtin_exec_path,"" };
exec_cmd.h +3 -0
@@ -3,6 +3,9 @@extern void git_set_exec_path (const char *exec_path);extern const char *git_exec_path (void ); +extern const char *git_argv_exec_path (void ); +extern const char *git_builtin_exec_path (void ); +extern const char *git_env_exec_path (void );extern int execv_git_cmd (const char **argv);/* NULL terminated */ extern int execl_git_cmd (const char *cmd, ...);
git.c +1 -1
@@ -51,7 +51,7 @@ static int handle_options(const char*** argv, int* argc, int* envchanged)if (!prefixcmp (cmd,"--exec-path" )) { cmd +=11 ;if (*cmd =='=' ) -git_set_exec_path (cmd +1 ); +git_set_argv_exec_path (cmd +1 );else {puts (git_exec_path ());exit (0 );
help.c +74 -29
137 lines not on this page · raw message
Signature · 1 line
1.5.3.4.209.g5d1ce-dirty
Quoted 3 lines · Scott R Parish
Currently "git help -a" only searches in the highest priority
exec_path, meaning at worst, nothing is listed if the git commands are only available from the PATH. It also makes git slightly less extensible.
...
exec_cmd.c line 13
Quoted 11 lines
extern char **environ;
static const char*builtin_exec_path=GIT_EXEC_PATH;exec_cmd.c +3
-3-static const char *current_exec_path; +static const char *argv_exec_path; -void git_set_exec_path (const char *exec_path) +void git_set_argv_exec_path (const char *exec_path) { - current_exec_path = exec_path; + argv_exec_path = exec_path; }
I'd rather see a rename isolated from a logic change. I find it easier to review.
exec_cmd.c line 25
Quoted 3 lines
exec_cmd.c +3
-0+const char *git_argv_exec_path (void ) +const char *git_builtin_exec_path(void) +const char *git_env_exec_path(void)
And yet later you then build the same priority array as already used by execv_git_cmd(). Why not just make a function that builds the array for the caller, so both execv_git_cmd() and list_commands() can both use the same array?
Quoted 3 lines
help.c +2
-0+static unsigned int list_commands_in_dir (const char *dir,const char *prefix) { +int start_dir =open ("." ,O_RDONLY ,0 );
...
help.c static void pretty_print_string_list(struct cmdname **cmdname, int longest) · line 104
Quoted 2 lines
help.c +2
-0+if (!dirp ||chdir (dir)) { +fchdir (start_dir);
fchdir() isn't as portable as Git currently is. Thus far we have avoided using fchdir(). Requiring it here for something as "simple" as listing help is not a good improvement as it will limit who can run git-help. Why can't you stat the individual entries by joining the paths together?
Signature · 1 line
Shawn.
Quoted 5 lines · Shawn O. Pearce
fchdir()isn't as portable as Git currently is. Thus far we have avoided usingfchdir(). Requiring it here for something as "simple" as listing help is not a good improvement as it will limit who can run git-help. Why can't you stat the individual entries by joining the paths together?
I hadn't realized it wasn't portable, but i do see that there's no POSIX entry in its man page. I was actually looking to use getcwd, but its man page had suggested using this open()/fchdir() method.
Anyway, is there a reason to avoid changing the directory? If not i'm tempted to take the approach that j.sixt suggested--not restoring the cwd since we're exiting anyway. I don't have any good reason to not do the string manipulation, but why do something more complicated then necessary?
sRp
Signature · 2 lines
Scott Parish http://srparish.net/
Quoted 8 lines · Scott Parish
Quoted 1 line · Shawn O. Pearce
fchdir()isn't as portable as Git currently is.I hadn't realized it wasn't portable, but i do see that there's no POSIX entry in its man page. I was actually looking to use getcwd, but its man page had suggested using this open()/fchdir() method.
Quoted 5 lines
Anyway, is there a reason to avoid changing the directory? If not i'm tempted to take the approach that j.sixt suggested--not restoring the cwd since we're exiting anyway. I don't have any good reason to not do the string manipulation, but why do something more complicated then necessary?
Yea, that was another thought I had. You probably can just chdir(), list, exit, and not worry about going back to the previous directory. And more complicated is always a bad idea. Keep it simple, 'cause us gits like it that way. :-)
Signature · 1 line
Shawn.
help.c static void pretty_print_string_list(struct cmdname **cmdname, int longest) · line 104
Quoted 2 lines · Scott R Parish
help.c +2
-0+if (!dirp ||chdir (dir)) { +fchdir (start_dir);
/me dislikes this. Windows doesn't have fchdir().
AFAIKS you are only using this to chdir back to where you started, but is this necessary? Aren't we exiting anyway after the command list was printed?
-- Hannes
Hi,
Quoted 6 lines · Scott R Parish
Currently "git help -a" only searches in the highest priority
exec_path, meaning at worst, nothing is listed if the git commands are only available from the PATH. It also makes git slightly less extensible.To fix this,
help.cis modified to search in all theexec_pathsand PATH for potential git commands.
With this explanation, I would have expected that you add a loop just like in exec-cmd.c. Not anything more. And certainly not the removal of a sanity check for the length of the path name.
Ciao,
Dscho
Quoted 6 lines · Johannes Schindelin
Quoted 2 lines
To fix this,
help.cis modified to search in all theexec_pathsand PATH for potential git commands.With this explanation, I would have expected that you add a loop just like in
exec-cmd.c. Not anything more. And certainly not the removal of a sanity check for the length of the path name.
Well, i took a slightly different approach where that sanity check wasn't nessisary. Instead of building up a string of the path of each file, i'm saving the original directory in a file descriptor, and "cd"ing to the exec_path currently being listed. Because of that i can just stat() the names returned by readdir. Much simpler imho
sRp
Signature · 2 lines
Scott Parish http://srparish.net/