git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v4] To make GIT-VERSION-FILE, search for git more widely

From
MAMatthias Andree <matthias.andree@gmx.de>
Date
Jun 4, 2009, 00:12 UTC
Message-ID
<1244074328-20995-1-git-send-email-matthias.andree@gmx.de>
In-Reply-To
<200906022035.30081.j6t@kdbg.org>
Situation: sudo make install can rebuilds the whole package even if
you've just built it before. For instance:

make configure ./configure # defaults to --prefix=/usr/local make all doc sudo make install install-doc install-html # REBUILDS HAPPEN HERE

This causes the "sudo make install" to rebuild everything because it believes the version had changed. sudo strips $PATH for security reasons.

The underlying problem flow is:
1 - Makefile has "include GIT-VERSION-FILE", thus gmake builds
    GIT-VERSION-FILE early.
2 - GIT-VERSION-FILE depends on a .PHONY target (.FORCE-GIT-VERSION-FILE)
3 - Thus, GNU make *always* executes GIT-VERSION-GEN
4 - GIT-VERSION-GEN now, under the stripped $PATH, cannot find "git" and
    sees a different version number.
5 - GIT-VERSION-GEN notes the difference in versions and regenerates
    GIT-VERSION-FILE, with up-to-date timestamp.
6 - GNU make rebuilds everything because GIT-VERSION-FILE is new.

The patch makes GIT-VERSION-GEN look for git in $(prefix)/bin, then for the newly built git$X executable, before falling back to plain "git" and thus to the default version in GIT-VERSION-GEN. This increases chances that we get the same version with the stripped $PATH and get away without rebuild.

Junio C. Hamano suggested that we look into $(prefix)/bin before the current work directory in order to aid cross-compiling.

Signed-off-by: Matthias Andree <matthias.andree@gmx.de>
---
 GIT-VERSION-GEN         |    9 ++++-----
 Makefile                |    6 +++++-
 git-gui/GIT-VERSION-GEN |   18 ++++++++++--------
 git-gui/Makefile        |    6 +++++-
 4 files changed, 24 insertions(+), 15 deletions(-)
diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
index 39cde78..2334cc1 100755
--- a/GIT-VERSION-GEN
+++ b/GIT-VERSION-GEN
@@ -2,6 +2,7 @@
 
 GVF=GIT-VERSION-FILE
 DEF_VER=v1.6.3.GIT
+type >/dev/null "$GIT" || GIT=git
 
 LF='
 '
@@ -12,12 +13,12 @@ if test -f version
 then
 	VN=$(cat version) || VN="$DEF_VER"
 elif test -d .git -o -f .git &&
-	VN=$(git describe --abbrev=4 HEAD 2>/dev/null) &&
+	VN=$($GIT describe --abbrev=4 HEAD 2>/dev/null) &&
 	case "$VN" in
 	*$LF*) (exit 1) ;;
 	v[0-9]*)
-		git update-index -q --refresh
-		test -z "$(git diff-index --name-only HEAD --)" ||
+		$GIT update-index -q --refresh
+		test -z "$($GIT diff-index --name-only HEAD --)" ||
 		VN="$VN-dirty" ;;
 	esac
 then
@@ -38,5 +39,3 @@ test "$VN" = "$VC" || {
 	echo >&2 "GIT_VERSION = $VN"
 	echo "GIT_VERSION = $VN" >$GVF
 }
-
-
diff --git a/Makefile b/Makefile
index 06c39e4..7adcf40 100644
--- a/Makefile
+++ b/Makefile
@@ -184,7 +184,11 @@ all::
 # programs as a tar, where bin/ and libexec/ might be on different file systems.
 
 GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
-	@$(SHELL_PATH) ./GIT-VERSION-GEN
+	@{ GIT=$(prefix)/bin/git$X ; test -x "$$GIT" ; } \
+	|| { GIT=./git$X ; test -x "$$GIT" ; } \
+	|| GIT=git ; \
+	export GIT ; \
+	$(SHELL_PATH) ./GIT-VERSION-GEN
 -include GIT-VERSION-FILE
 
 uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
diff --git a/git-gui/GIT-VERSION-GEN b/git-gui/GIT-VERSION-GEN
index b3f937e..729e93f 100755
--- a/git-gui/GIT-VERSION-GEN
+++ b/git-gui/GIT-VERSION-GEN
@@ -3,6 +3,8 @@
 GVF=GIT-VERSION-FILE
 DEF_VER=0.12.GITGUI
 
+type >/dev/null "$GIT" || GIT=git
+
 LF='
 '
 
@@ -10,10 +12,10 @@ tree_search ()
 {
 	head=$1
 	tree=$2
-	for p in $(git rev-list --parents --max-count=1 $head 2>/dev/null)
+	for p in $($GIT rev-list --parents --max-count=1 $head 2>/dev/null)
 	do
-		test $tree = $(git rev-parse $p^{tree} 2>/dev/null) &&
-		vn=$(git describe --abbrev=4 $p 2>/dev/null) &&
+		test $tree = $($GIT rev-parse $p^{tree} 2>/dev/null) &&
+		vn=$($GIT describe --abbrev=4 $p 2>/dev/null) &&
 		case "$vn" in
 		gitgui-[0-9]*) echo $vn; break;;
 		esac
@@ -38,10 +40,10 @@ if test -f version &&
    VN=$(cat version)
 then
 	: happy
-elif prefix="$(git rev-parse --show-prefix 2>/dev/null)"
+elif prefix="$($GIT rev-parse --show-prefix 2>/dev/null)"
    test -n "$prefix" &&
-   head=$(git rev-list --max-count=1 HEAD -- . 2>/dev/null) &&
-   tree=$(git rev-parse --verify "HEAD:$prefix" 2>/dev/null) &&
+   head=$($GIT rev-list --max-count=1 HEAD -- . 2>/dev/null) &&
+   tree=$($GIT rev-parse --verify "HEAD:$prefix" 2>/dev/null) &&
    VN=$(tree_search $head $tree)
    case "$VN" in
    gitgui-[0-9]*) : happy ;;
@@ -49,7 +51,7 @@ elif prefix="$(git rev-parse --show-prefix 2>/dev/null)"
    esac
 then
 	VN=$(echo "$VN" | sed -e 's/^gitgui-//;s/-/./g');
-elif VN=$(git describe --abbrev=4 HEAD 2>/dev/null) &&
+elif VN=$($GIT describe --abbrev=4 HEAD 2>/dev/null) &&
    case "$VN" in
    gitgui-[0-9]*) : happy ;;
    *) (exit 1) ;;
@@ -60,7 +62,7 @@ else
 	VN="$DEF_VER"
 fi
 
-dirty=$(sh -c 'git diff-index --name-only HEAD' 2>/dev/null) || dirty=
+dirty=$(sh -c '$GIT diff-index --name-only HEAD' 2>/dev/null) || dirty=
 case "$dirty" in
 '')
 	;;
diff --git a/git-gui/Makefile b/git-gui/Makefile
index b3580e9..bbdb4d8 100644
--- a/git-gui/Makefile
+++ b/git-gui/Makefile
@@ -8,7 +8,11 @@ all::
 #
 
 GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
-	@$(SHELL_PATH) ./GIT-VERSION-GEN
+	@{ GIT=$(prefix)/bin/git$X ; test -x "$$GIT" ; } \
+	|| { GIT=./git$X ; test -x "$$GIT" ; } \
+	|| GIT=git ; \
+	export GIT ; \
+	$(SHELL_PATH) ./GIT-VERSION-GEN
 -include GIT-VERSION-FILE
 
 uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
-- 
1.6.3.1.267.gd260a
Previous: Matthias AndreeNext: Junio C Hamano
Message 19 of 22 in “To make GIT-VERSION-FILE, search for git more widely”
  1. To make GIT-VERSION-FILE, search for git more widelyMatthias Andree, May 7, 2009
  2. Michael J GruberMay 7, 2009
  3. Matthias AndreeMay 7, 2009
  4. Michael J GruberMay 7, 2009
  5. Matthias AndreeMay 7, 2009
  6. Junio C HamanoMay 8, 2009
  7. Matthias AndreeMay 8, 2009
  8. Junio C HamanoMay 8, 2009
  9. Matthias AndreeMay 8, 2009
  10. Junio C HamanoMay 9, 2009
  11. Francis GaliegueMay 9, 2009
  12. Matthias AndreeMay 9, 2009
  13. Matthias AndreeMay 13, 2009
  14. Junio C HamanoMay 13, 2009
  15. Nanako ShiraishiJun 2, 2009
  16. Junio C HamanoJun 2, 2009
  17. Johannes SixtJun 2, 2009
  18. Matthias AndreeJun 3, 2009
  19. To make GIT-VERSION-FILE, search for git more widelyMatthias Andree, Jun 4, 2009
  20. Junio C HamanoJun 4, 2009
  21. Matthias AndreeJun 4, 2009
  22. Johannes SixtMay 8, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.