From: Patrick Steinhardt Date: Tue, 11 Mar 2025 10:06:37 +0000 (+0100) Subject: git-gui: prepare GIT-VERSION-GEN for out-of-tree builds X-Git-Tag: v2.50.0-rc1~17^2^2~8 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3ef470fa5127b9858d203990211f4375d38d5dd6;p=thirdparty%2Fgit.git git-gui: prepare GIT-VERSION-GEN for out-of-tree builds The GIT-VERSION-GEN unconditionally writes version information into the source directory in the form of the "GIT-VERSION-FILE". We are about to introduce the Meson build system though, which enforces out-of-tree builds by default, and in that context we cannot continue to write version information into the source tree. Prepare the script for out-of-tree builds by treating the source directory different from the output file. Signed-off-by: Patrick Steinhardt --- diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN index 92373d251a..e40a09b6fd 100755 --- a/GIT-VERSION-GEN +++ b/GIT-VERSION-GEN @@ -1,19 +1,33 @@ #!/bin/sh -GVF=GIT-VERSION-FILE DEF_VER=0.21.GITGUI LF=' ' +if test "$#" -ne 2 +then + echo >&2 "usage: $0 " + exit 1 +fi + +SOURCE_DIR="$1" +OUTPUT="$2" + +# Protect us from reading Git version information outside of the Git directory +# in case it is not a repository itself, but embedded in an unrelated +# repository. +GIT_CEILING_DIRECTORIES="$SOURCE_DIR/.." +export GIT_CEILING_DIRECTORIES + tree_search () { head=$1 tree=$2 - for p in $(git rev-list --parents --max-count=1 $head 2>/dev/null) + for p in $(git -C "$SOURCE_DIR" 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 -C "$SOURCE_DIR" rev-parse $p^{tree} 2>/dev/null) && + vn=$(git -C "$SOURCE_DIR" describe --abbrev=4 $p 2>/dev/null) && case "$vn" in gitgui-[0-9]*) echo $vn; break;; esac @@ -34,14 +48,14 @@ tree_search () # If we are at the toplevel or the merge assumption fails # try looking for a gitgui-* tag. -if test -f version && - VN=$(cat version) +if test -f "$SOURCE_DIR"/version && + VN=$(cat "$SOURCE_DIR"/version) then : happy -elif prefix="$(git rev-parse --show-prefix 2>/dev/null)" +elif prefix="$(git -C "$SOURCE_DIR" 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 -C "$SOURCE_DIR" rev-list --max-count=1 HEAD -- . 2>/dev/null) && + tree=$(git -C "$SOURCE_DIR" rev-parse --verify "HEAD:$prefix" 2>/dev/null) && VN=$(tree_search $head $tree) case "$VN" in gitgui-[0-9]*) : happy ;; @@ -49,7 +63,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 -C "$SOURCE_DIR" describe --abbrev=4 HEAD 2>/dev/null) && case "$VN" in gitgui-[0-9]*) : happy ;; *) (exit 1) ;; @@ -60,7 +74,7 @@ else VN="$DEF_VER" fi -dirty=$(sh -c 'git diff-index --name-only HEAD' 2>/dev/null) || dirty= +dirty=$(git -C "$SOURCE_DIR" diff-index --name-only HEAD 2>/dev/null) || dirty= case "$dirty" in '') ;; @@ -68,13 +82,13 @@ case "$dirty" in VN="$VN-dirty" ;; esac -if test -r $GVF +if test -r "$OUTPUT" then - VC=$(sed -e 's/^GITGUI_VERSION = //' <$GVF) + VC=$(sed -e 's/^GITGUI_VERSION = //' <"$OUTPUT") else VC=unset fi test "$VN" = "$VC" || { echo >&2 "GITGUI_VERSION = $VN" - echo "GITGUI_VERSION = $VN" >$GVF + echo "GITGUI_VERSION = $VN" >"$OUTPUT" } diff --git a/Makefile b/Makefile index f4f98961b2..ea22b3af5d 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ all:: # GIT-VERSION-FILE: FORCE - @$(SHELL_PATH) ./GIT-VERSION-GEN + @$(SHELL_PATH) ./GIT-VERSION-GEN . $@ ifneq ($(MAKECMDGOALS),clean) -include GIT-VERSION-FILE endif