Skip to contentSkip to conversation

Locate git helpers with type -P, for when git --exec-path is multivalued

PATCH In review Dominique Quatravaux 3 participants 4 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Locate git helpers with type -P, for when git --exec-path is multivalued

Under a setting of (eg) GIT_EXEC_PATH=/home/joe/bin:/usr/lib/git-core, constructs such as

  . "$(git --exec-path)"/git-sh-setup

do not work. The proper way is

. "$(PATH="$(git --exec-path)" type -p git-sh-setup)"

---
 Documentation/git-mergetool--lib.txt |    3 ++-
 Documentation/git-parse-remote.txt   |    2 +-
 Documentation/git-sh-i18n.txt        |    2 +-
 Documentation/git-sh-setup.txt       |    2 +-
 contrib/diffall/git-diffall          |    4 ++--
 git-mergetool--lib.sh                |    2 +-
 6 files changed, 8 insertions(+), 7 deletions(-)
Documentation/git-mergetool--lib.txt +2 -1
index f98a41b..c7188d3 100644
@@ -8,7 +8,8 @@ git-mergetool--lib - Common git merge tool shell scriptlets
 SYNOPSIS
 --------
 [verse]
-'TOOL_MODE=(diff|merge) . "$(git --exec-path)/git-mergetool{litdd}lib"'
+'TOOL_MODE=(diff|merge) \
+  . "$(PATH="$(git --exec-path)" type -P git-mergetool{litdd}lib)"'
 
 DESCRIPTION
 -----------
Documentation/git-parse-remote.txt +1 -1
index a45ea1e..c17d7b8 100644
@@ -9,7 +9,7 @@ git-parse-remote - Routines to help parsing remote repository access parameters
 SYNOPSIS
 --------
 [verse]
-'. "$(git --exec-path)/git-parse-remote"'
+'. "$(PATH="$(git --exec-path)" type -P git-parse-remote)"'
 
 DESCRIPTION
 -----------
Documentation/git-sh-i18n.txt +1 -1
index 60cf49c..f74820c 100644
@@ -8,7 +8,7 @@ git-sh-i18n - Git's i18n setup code for shell scripts
 SYNOPSIS
 --------
 [verse]
-'. "$(git --exec-path)/git-sh-i18n"'
+'. "$(PATH="$(git --exec-path)" type -P git-sh-i18n)"'
 
 DESCRIPTION
 -----------
Documentation/git-sh-setup.txt +1 -1
index 5e5f1c8..44c6aa9 100644
@@ -8,7 +8,7 @@ git-sh-setup - Common git shell script setup code
 SYNOPSIS
 --------
 [verse]
-'. "$(git --exec-path)/git-sh-setup"'
+'. "$(PATH="$(git --exec-path)" type -P git-sh-setup)"'
 
 DESCRIPTION
 -----------
contrib/diffall/git-diffall +2 -2
index 84f2b65..451ca98 100755
@@ -22,10 +22,10 @@ USAGE='[--cached] [--copy-back] [-x|--extcmd=<command>] <commit>{0,2} [-- <path>
 '
 
 SUBDIRECTORY_OK=1
-. "$(git --exec-path)/git-sh-setup"
+PATH="$(PATH="$(git --exec-path)" type -P git-sh-setup)"
 
 TOOL_MODE=diff
-. "$(git --exec-path)/git-mergetool--lib"
+. "$(PATH="$(git --exec-path)" type -P git-mergetool--lib)"
 
 merge_tool="$(get_merge_tool)"
 if test -z "$merge_tool"
git-mergetool--lib.sh +1 -1
index ed630b2..73d8510 100644
@@ -52,7 +52,7 @@ setup_tool () {
 		tool="$1"
 		;;
 	esac
-	mergetools="$(git --exec-path)/mergetools"
+	mergetools="$(PATH="$(git --exec-path)" type -P mergetools)"
 
 	# Load the default definitions
 	. "$mergetools/defaults"
Signature · 1 line
1.7.7.3
#1 lore raw
Quoted 8 lines · Dominique Quatravaux

Under a setting of (eg) GIT_EXEC_PATH=/home/joe/bin:/usr/lib/git-core, constructs such as

  . "$(git --exec-path)"/git-sh-setup

do not work. The proper way is

  . "$(PATH="$(git --exec-path)" type -p git-sh-setup)"

NAK. The documented(!) way of loading git-sh-setup is

  . "$(git --exec-path)/git-sh-setup"

and we can't break that. I don't know where you are getting your multivalued GIT_EXEC_PATH from, but there are other places in the code that assume a single path, too. For example, the callchain (irrelevant stuff snipped)

void setup_path(void)

{
	add_path(&new_path, git_exec_path());
}

static void add_path(struct strbuf *out, const char *path)

{
	if (path && *path) {
		if (is_absolute_path(path))
			strbuf_addstr(out, path);
		else
			strbuf_addstr(out, absolute_path(path));

		strbuf_addch(out, PATH_SEP);
        }
}

makes no sense at is_absolute_path(path) if path is multivalued.

Signature · 2 lines
Thomas Rast
trast@{inf,student}.ethz.ch
#2 lore raw
Quoted 2 lines · Thomas Rast

I don't know where you are getting your
multivalued GIT_EXEC_PATH from,

Well it used to work for me before, apparently not by design... Too bad.

Signature · 2 lines
  Dominique Quatravaux
  +41 79 609 40 72
#3 lore raw
In reply to Dominique Quatravaux
Quoted 8 lines · Dominique Quatravaux

Under a setting of (eg) GIT_EXEC_PATH=/home/joe/bin:/usr/lib/git-core, constructs such as

  . "$(git --exec-path)"/git-sh-setup

do not work. The proper way is

  . "$(PATH="$(git --exec-path)" type -p git-sh-setup)"

type doesn't take any options in POSIX, and -P is bash-only.

Andreas.

Signature · 3 lines
Andreas Schwab, [email protected]
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."