Makefile: insert SANE_TOOL_PATH to PATH before /bin or /usr/bin
In an earlier patch, we introduced SANE_TOOL_PATH that is prepended to user's PATH. This had an unintended consequence of overriding user's private binary directory that typically comes earlier in the PATH to holds even saner commands than whatever comes with the system. For example, a user may have ~/bin that is early in the path and contains a shell script "vi" that launches system's /bin/vi with specific options. Prepending SANE_TOOL_PATH to the PATH that happens to have "vi" in it defeats such customization. This fixes the issue by inserting SANE_TOOL_PATH just before /bin or /usr/bin appears on the PATH. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Jun 8, 2009 at 09:41 UTC
61dbb3c4415169194d9351cc4b68dd88788a93c5
2 files changed
+31
-4
Makefile
+4
-3
@@ -881,10 +881,11 @@ endif
881
-include config.mak
882
883
ifdef SANE_TOOL_PATH
884
-BROKEN_PATH_FIX = s|^. @@PATH@@|PATH=$(SANE_TOOL_PATH)|
884
+SANE_TOOL_PATH_SQ = $(subst ','\'',$(SANE_TOOL_PATH))
885
+BROKEN_PATH_FIX = 's|^\# @@BROKEN_PATH_FIX@@$$|git_broken_path_fix $(SANE_TOOL_PATH_SQ)|'
886
PATH := $(SANE_TOOL_PATH):${PATH}
887
else
887
-BROKEN_PATH_FIX = d
888
+BROKEN_PATH_FIX = '/^\# @@BROKEN_PATH_FIX@@$$/d'
889
endif
890
891
ifeq ($(uname_S),Darwin)
@@ -1288,7 +1289,7 @@ $(patsubst %.sh,%,$(SCRIPT_SH)) : % : %.sh
1289
-e 's|@SHELL_PATH@|$(SHELL_PATH_SQ)|' \
1290
-e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
1291
-e 's/@@NO_CURL@@/$(NO_CURL)/g' \
1291
- -e '/^# @@PATH@@/$(BROKEN_PATH_FIX)' \
1292
+ -e $(BROKEN_PATH_FIX) \
1293
$@.sh >$@+ && \
1294
chmod +x $@+ && \
1295
mv $@+ $@
git-sh-setup.sh
+27
-1
@@ -11,7 +11,33 @@
11
# exporting it.
12
unset CDPATH
13
14
-# @@PATH@@:$PATH
14
+git_broken_path_fix () {
15
+ case ":$PATH:" in
16
+ *:$1:*) : ok ;;
17
+ *)
18
+ PATH=$(
19
+ SANE_TOOL_PATH="$1"
20
+ IFS=: path= sep=
21
+ set x $PATH
22
+ shift
23
+ for elem
24
+ do
25
+ case "$SANE_TOOL_PATH:$elem" in
26
+ (?*:/bin | ?*:/usr/bin)
27
+ path="$path$sep$SANE_TOOL_PATH"
28
+ sep=:
29
+ SANE_TOOL_PATH=
30
+ esac
31
+ path="$path$sep$elem"
32
+ sep=:
33
+ done
34
+ echo "$path"
35
+ )
36
+ ;;
37
+ esac
38
+}
39
+
40
+# @@BROKEN_PATH_FIX@@
41
42
die() {
43
echo >&2 "$@"