Skip to content

Commit 3ef470f

Browse files
committed
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 <[email protected]>
1 parent 3271d2e commit 3ef470f

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

GIT-VERSION-GEN

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
11
#!/bin/sh
22

3-
GVF=GIT-VERSION-FILE
43
DEF_VER=0.21.GITGUI
54

65
LF='
76
'
87

8+
if test "$#" -ne 2
9+
then
10+
echo >&2 "usage: $0 <SOURCE_DIR> <OUTPUT>"
11+
exit 1
12+
fi
13+
14+
SOURCE_DIR="$1"
15+
OUTPUT="$2"
16+
17+
# Protect us from reading Git version information outside of the Git directory
18+
# in case it is not a repository itself, but embedded in an unrelated
19+
# repository.
20+
GIT_CEILING_DIRECTORIES="$SOURCE_DIR/.."
21+
export GIT_CEILING_DIRECTORIES
22+
923
tree_search ()
1024
{
1125
head=$1
1226
tree=$2
13-
for p in $(git rev-list --parents --max-count=1 $head 2>/dev/null)
27+
for p in $(git -C "$SOURCE_DIR" rev-list --parents --max-count=1 $head 2>/dev/null)
1428
do
15-
test $tree = $(git rev-parse $p^{tree} 2>/dev/null) &&
16-
vn=$(git describe --abbrev=4 $p 2>/dev/null) &&
29+
test $tree = $(git -C "$SOURCE_DIR" rev-parse $p^{tree} 2>/dev/null) &&
30+
vn=$(git -C "$SOURCE_DIR" describe --abbrev=4 $p 2>/dev/null) &&
1731
case "$vn" in
1832
gitgui-[0-9]*) echo $vn; break;;
1933
esac
@@ -34,22 +48,22 @@ tree_search ()
3448
# If we are at the toplevel or the merge assumption fails
3549
# try looking for a gitgui-* tag.
3650

37-
if test -f version &&
38-
VN=$(cat version)
51+
if test -f "$SOURCE_DIR"/version &&
52+
VN=$(cat "$SOURCE_DIR"/version)
3953
then
4054
: happy
41-
elif prefix="$(git rev-parse --show-prefix 2>/dev/null)"
55+
elif prefix="$(git -C "$SOURCE_DIR" rev-parse --show-prefix 2>/dev/null)"
4256
test -n "$prefix" &&
43-
head=$(git rev-list --max-count=1 HEAD -- . 2>/dev/null) &&
44-
tree=$(git rev-parse --verify "HEAD:$prefix" 2>/dev/null) &&
57+
head=$(git -C "$SOURCE_DIR" rev-list --max-count=1 HEAD -- . 2>/dev/null) &&
58+
tree=$(git -C "$SOURCE_DIR" rev-parse --verify "HEAD:$prefix" 2>/dev/null) &&
4559
VN=$(tree_search $head $tree)
4660
case "$VN" in
4761
gitgui-[0-9]*) : happy ;;
4862
*) (exit 1) ;;
4963
esac
5064
then
5165
VN=$(echo "$VN" | sed -e 's/^gitgui-//;s/-/./g');
52-
elif VN=$(git describe --abbrev=4 HEAD 2>/dev/null) &&
66+
elif VN=$(git -C "$SOURCE_DIR" describe --abbrev=4 HEAD 2>/dev/null) &&
5367
case "$VN" in
5468
gitgui-[0-9]*) : happy ;;
5569
*) (exit 1) ;;
@@ -60,21 +74,21 @@ else
6074
VN="$DEF_VER"
6175
fi
6276

63-
dirty=$(sh -c 'git diff-index --name-only HEAD' 2>/dev/null) || dirty=
77+
dirty=$(git -C "$SOURCE_DIR" diff-index --name-only HEAD 2>/dev/null) || dirty=
6478
case "$dirty" in
6579
'')
6680
;;
6781
*)
6882
VN="$VN-dirty" ;;
6983
esac
7084

71-
if test -r $GVF
85+
if test -r "$OUTPUT"
7286
then
73-
VC=$(sed -e 's/^GITGUI_VERSION = //' <$GVF)
87+
VC=$(sed -e 's/^GITGUI_VERSION = //' <"$OUTPUT")
7488
else
7589
VC=unset
7690
fi
7791
test "$VN" = "$VC" || {
7892
echo >&2 "GITGUI_VERSION = $VN"
79-
echo "GITGUI_VERSION = $VN" >$GVF
93+
echo "GITGUI_VERSION = $VN" >"$OUTPUT"
8094
}

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ all::
88
#
99

1010
GIT-VERSION-FILE: FORCE
11-
@$(SHELL_PATH) ./GIT-VERSION-GEN
11+
@$(SHELL_PATH) ./GIT-VERSION-GEN . $@
1212
ifneq ($(MAKECMDGOALS),clean)
1313
-include GIT-VERSION-FILE
1414
endif

0 commit comments

Comments
 (0)