make_version 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #!/bin/sh
  2. if [ -f ${1}/.version ]; then
  3. cat ${1}.version
  4. elif [ -f ${1}/.svnrevision ]; then
  5. echo SVN-`cat ${1}/.svnbranch`-r`cat ${1}/.svnrevision`
  6. elif [ -d ${1}/.svn ]; then
  7. PARTS=`LANG=C svn info ${1} | grep URL | awk '{print $2;}' | sed -e s:^.*/svn/${2}/:: | sed -e 's:/: :g'`
  8. BRANCH=0
  9. TEAM=0
  10. REV=`svnversion -c ${1} | cut -d: -f2`
  11. if [ "${PARTS}" = "trunk" ]
  12. then
  13. echo SVN-'trunk'-r${REV}
  14. exit 0
  15. fi
  16. for PART in $PARTS
  17. do
  18. if [ ${BRANCH} != 0 ]
  19. then
  20. RESULT="${RESULT}-${PART}"
  21. break
  22. fi
  23. if [ ${TEAM} != 0 ]
  24. then
  25. RESULT="${RESULT}-${PART}"
  26. continue
  27. fi
  28. if [ "${PART}" = "branches" ]
  29. then
  30. BRANCH=1
  31. RESULT="branch"
  32. continue
  33. fi
  34. if [ "${PART}" = "tags" ]
  35. then
  36. BRANCH=1
  37. RESULT="tag"
  38. continue
  39. fi
  40. if [ "${PART}" = "team" ]
  41. then
  42. TEAM=1
  43. continue
  44. fi
  45. done
  46. echo SVN-${RESULT##-}-r${REV}
  47. elif [ -d ${1}/.git ]; then
  48. # If the first log commit messages indicates that this is checked into
  49. # subversion, we'll just use the SVN- form of the revision.
  50. MODIFIED=""
  51. SVN_REV=`git log --pretty=full -1 | grep -F "git-svn-id:" | sed -e "s/.*\@\([^\s]*\)\s.*/\1/g"`
  52. if [ -z "$SVN_REV" ]; then
  53. VERSION=`git describe --long --always --tags --dirty=M 2> /dev/null`
  54. if [ $? -ne 0 ]; then
  55. if [ "`git ls-files -m | wc -l`" != "0" ]; then
  56. MODIFIED="M"
  57. fi
  58. # Some older versions of git do not support all the above
  59. # options.
  60. VERSION=GIT-`git rev-parse --short --verify HEAD`${MODIFIED}
  61. fi
  62. echo ${VERSION}
  63. else
  64. PARTS=`LANG=C git log --pretty=full | grep -F "git-svn-id:" | head -1 | awk '{print $2;}' | sed -e s:^.*/svn/$2/:: | sed -e 's:/: :g' | sed -e 's/@.*$//g'`
  65. BRANCH=0
  66. TEAM=0
  67. if [ "`git ls-files -m | wc -l`" != "0" ]; then
  68. MODIFIED="M"
  69. fi
  70. if [ "${PARTS}" = "trunk" ]; then
  71. echo SVN-'trunk'-r${SVN_REV}${MODIFIED}
  72. exit 0
  73. fi
  74. for PART in $PARTS
  75. do
  76. if [ ${BRANCH} != 0 ]; then
  77. RESULT="${RESULT}-${PART}"
  78. break
  79. fi
  80. if [ ${TEAM} != 0 ]; then
  81. RESULT="${RESULT}-${PART}"
  82. continue
  83. fi
  84. if [ "${PART}" = "branches" ]; then
  85. BRANCH=1
  86. RESULT="branch"
  87. continue
  88. fi
  89. if [ "${PART}" = "tags" ]; then
  90. BRANCH=1
  91. RESULT="tag"
  92. continue
  93. fi
  94. if [ "${PART}" = "team" ]; then
  95. TEAM=1
  96. continue
  97. fi
  98. done
  99. echo SVN-${RESULT##-}-r${SVN_REV}${MODIFIED}
  100. fi
  101. fi