interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / git-gui / GIT-VERSION-GEN

102 lines · 2565 bytes Raw Blame History
1#!/bin/sh
2
3DEF_VER=0.21.GITGUI
4
5LF='
6'
7
8if test "$#" -lt 2
9then
10 echo >&2 "usage: $0 <SOURCE_DIR> <OUTPUT> [<PARENT_PROJECT_DIR>]"
11 exit 1
12fi
13
14SOURCE_DIR="$1"
15OUTPUT="$2"
16PARENT_PROJECT_DIR="$3"
17
18# Protect us from reading Git version information outside of the Git directory
19# in case it is not a repository itself, but embedded in an unrelated
20# repository. The PARENT_PROJECT_DIR variable can be used to override this, for
21# example when git-gui is included as a subproject.
22if test -n "$PARENT_PROJECT_DIR"
23then
24 GIT_CEILING_DIRECTORIES="$PARENT_PROJECT_DIR/.."
25else
26 GIT_CEILING_DIRECTORIES="$SOURCE_DIR/.."
27fi
28
29export GIT_CEILING_DIRECTORIES
30
31tree_search ()
32{
33 head=$1
34 tree=$2
35 for p in $(git -C "$SOURCE_DIR" rev-list --parents --max-count=1 $head 2>/dev/null)
36 do
37 test $tree = $(git -C "$SOURCE_DIR" rev-parse $p^{tree} 2>/dev/null) &&
38 vn=$(git -C "$SOURCE_DIR" describe --abbrev=4 $p 2>/dev/null) &&
39 case "$vn" in
40 gitgui-[0-9]*) echo $vn; break;;
41 esac
42 done
43}
44
45# Always use the tarball version file if found, just
46# in case we are somehow contained in a larger git
47# repository that doesn't actually track our state.
48# (At least one package manager is doing this.)
49#
50# We may be a subproject, so try looking for the merge
51# commit that supplied this directory content if we are
52# not at the toplevel. We probably will always be the
53# second parent in the commit, but we shouldn't rely on
54# that fact.
55#
56# If we are at the toplevel or the merge assumption fails
57# try looking for a gitgui-* tag.
58
59if test -f "$SOURCE_DIR"/version &&
60 VN=$(cat "$SOURCE_DIR"/version)
61then
62 : happy
63elif prefix="$(git -C "$SOURCE_DIR" rev-parse --show-prefix 2>/dev/null)"
64 test -n "$prefix" &&
65 head=$(git -C "$SOURCE_DIR" rev-list --max-count=1 HEAD -- . 2>/dev/null) &&
66 tree=$(git -C "$SOURCE_DIR" rev-parse --verify "HEAD:$prefix" 2>/dev/null) &&
67 VN=$(tree_search $head $tree)
68 case "$VN" in
69 gitgui-[0-9]*) : happy ;;
70 *) (exit 1) ;;
71 esac
72then
73 VN=$(echo "$VN" | sed -e 's/^gitgui-//;s/-/./g');
74elif VN=$(git -C "$SOURCE_DIR" describe --abbrev=4 HEAD 2>/dev/null) &&
75 case "$VN" in
76 gitgui-[0-9]*) : happy ;;
77 *) (exit 1) ;;
78 esac
79then
80 VN=$(echo "$VN" | sed -e 's/^gitgui-//;s/-/./g');
81else
82 VN="$DEF_VER"
83fi
84
85dirty=$(git -C "$SOURCE_DIR" diff-index --name-only HEAD 2>/dev/null) || dirty=
86case "$dirty" in
87'')
88 ;;
89*)
90 VN="$VN-dirty" ;;
91esac
92
93if test -r "$OUTPUT"
94then
95 VC=$(sed -e 's/^GITGUI_VERSION=//' <"$OUTPUT")
96else
97 VC=unset
98fi
99test "$VN" = "$VC" || {
100 echo >&2 "GITGUI_VERSION=$VN"
101 echo "GITGUI_VERSION=$VN" >"$OUTPUT"
102}