GIT-VERSION-GEN 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/bin/sh
  2. GVF=GIT-VERSION-FILE
  3. DEF_VER=0.21.GITGUI
  4. LF='
  5. '
  6. tree_search ()
  7. {
  8. head=$1
  9. tree=$2
  10. for p in $(git rev-list --parents --max-count=1 $head 2>/dev/null)
  11. do
  12. test $tree = $(git rev-parse $p^{tree} 2>/dev/null) &&
  13. vn=$(git describe --abbrev=4 $p 2>/dev/null) &&
  14. case "$vn" in
  15. gitgui-[0-9]*) echo $vn; break;;
  16. esac
  17. done
  18. }
  19. # Always use the tarball version file if found, just
  20. # in case we are somehow contained in a larger git
  21. # repository that doesn't actually track our state.
  22. # (At least one package manager is doing this.)
  23. #
  24. # We may be a subproject, so try looking for the merge
  25. # commit that supplied this directory content if we are
  26. # not at the toplevel. We probably will always be the
  27. # second parent in the commit, but we shouldn't rely on
  28. # that fact.
  29. #
  30. # If we are at the toplevel or the merge assumption fails
  31. # try looking for a gitgui-* tag.
  32. if test -f version &&
  33. VN=$(cat version)
  34. then
  35. : happy
  36. elif prefix="$(git rev-parse --show-prefix 2>/dev/null)"
  37. test -n "$prefix" &&
  38. head=$(git rev-list --max-count=1 HEAD -- . 2>/dev/null) &&
  39. tree=$(git rev-parse --verify "HEAD:$prefix" 2>/dev/null) &&
  40. VN=$(tree_search $head $tree)
  41. case "$VN" in
  42. gitgui-[0-9]*) : happy ;;
  43. *) (exit 1) ;;
  44. esac
  45. then
  46. VN=$(echo "$VN" | sed -e 's/^gitgui-//;s/-/./g');
  47. elif VN=$(git describe --abbrev=4 HEAD 2>/dev/null) &&
  48. case "$VN" in
  49. gitgui-[0-9]*) : happy ;;
  50. *) (exit 1) ;;
  51. esac
  52. then
  53. VN=$(echo "$VN" | sed -e 's/^gitgui-//;s/-/./g');
  54. else
  55. VN="$DEF_VER"
  56. fi
  57. dirty=$(sh -c 'git diff-index --name-only HEAD' 2>/dev/null) || dirty=
  58. case "$dirty" in
  59. '')
  60. ;;
  61. *)
  62. VN="$VN-dirty" ;;
  63. esac
  64. if test -r $GVF
  65. then
  66. VC=$(sed -e 's/^GITGUI_VERSION = //' <$GVF)
  67. else
  68. VC=unset
  69. fi
  70. test "$VN" = "$VC" || {
  71. echo >&2 "GITGUI_VERSION = $VN"
  72. echo "GITGUI_VERSION = $VN" >$GVF
  73. }