make_version 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. #!/bin/sh
  2. AWK=${AWK:-awk}
  3. GIT=${GIT:-git}
  4. GREP=${GREP:-grep}
  5. if [ -f ${1}/.version ]; then
  6. cat ${1}/.version
  7. elif [ -d ${1}/.svn ]; then
  8. PARTS=`LANG=C svn info ${1} | ${GREP} URL | ${AWK} '{print $2;}' | sed -e 's:^.*/svn/asterisk/::' | sed -e 's:/: :g'`
  9. BRANCH=0
  10. TEAM=0
  11. TAG=0
  12. FEATURE=0
  13. REV=`svnversion -c ${1} | cut -d: -f2`
  14. INTEGRATED=`LANG=C svn pg automerge-propname ${1}`
  15. if [ -z "${INTEGRATED}" ] ; then
  16. INTEGRATED=svnmerge-integrated
  17. fi
  18. BASE=`LANG=C svn pg ${INTEGRATED} ${1} | cut -d: -f1`
  19. if [ "${PARTS}" = "trunk" ] ; then
  20. echo SVN-trunk-r${REV}
  21. exit 0
  22. fi
  23. for PART in $PARTS ; do
  24. if [ ${TAG} != 0 ] ; then
  25. if [ "${PART}" = "autotag_for_be" ] ; then
  26. continue
  27. fi
  28. if [ "${PART}" = "autotag_for_sx00i" ] ; then
  29. continue
  30. fi
  31. RESULT="${PART}"
  32. break
  33. fi
  34. if [ ${BRANCH} != 0 ] ; then
  35. RESULT="${RESULT}-${PART}"
  36. if [ ${FEATURE} != 0 ] ; then
  37. RESULT="${RESULT}-${FEATURE_NAME}"
  38. fi
  39. break
  40. fi
  41. if [ ${TEAM} != 0 ] ; then
  42. if [ -z "${RESULT}" ] ; then
  43. RESULT="${PART}"
  44. else
  45. RESULT="${RESULT}-${PART}"
  46. fi
  47. continue
  48. fi
  49. if [ "${PART}" = "certified" ] ; then
  50. FEATURE=1
  51. FEATURE_NAME="cert"
  52. continue
  53. fi
  54. if [ "${PART}" = "branches" ] ; then
  55. BRANCH=1
  56. RESULT="branch"
  57. continue
  58. fi
  59. if [ "${PART}" = "tags" ] ; then
  60. TAG=1
  61. continue
  62. fi
  63. if [ "${PART}" = "team" ] ; then
  64. TEAM=1
  65. continue
  66. fi
  67. done
  68. if [ ${TAG} != 0 ] ; then
  69. echo ${RESULT}
  70. else
  71. echo SVN-${RESULT}-r${REV}${BASE:+-${BASE}}
  72. fi
  73. elif [ -d ${1}/.git ]; then
  74. if [ -z ${GIT} ]; then
  75. GIT="git"
  76. fi
  77. if ! command -v ${GIT} >/dev/null 2>&1; then
  78. echo "UNKNOWN__and_probably_unsupported"
  79. exit 1
  80. fi
  81. # If the first log commit messages indicates that this is checked into
  82. # subversion, we'll just use the SVN- form of the revision.
  83. MODIFIED=""
  84. SVN_REV=`${GIT} log --pretty=full -1 | ${GREP} -F "git-svn-id:" | sed -e "s/.*\@\([^\s]*\)\s.*/\1/g"`
  85. if [ -z "$SVN_REV" ]; then
  86. VERSION=GIT-`${GIT} describe --long --always --tags --dirty=M 2> /dev/null`
  87. if [ $? -ne 0 ]; then
  88. if [ "`${GIT} ls-files -m | wc -l`" != "0" ]; then
  89. MODIFIED="M"
  90. fi
  91. # Some older versions of git do not support all the above
  92. # options.
  93. VERSION=GIT-`${GIT} rev-parse --short --verify HEAD`${MODIFIED}
  94. fi
  95. echo ${VERSION}
  96. else
  97. 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'`
  98. BRANCH=0
  99. TEAM=0
  100. TAG=0
  101. FEATURE=0
  102. if [ "`${GIT} ls-files -m | wc -l`" != "0" ]; then
  103. MODIFIED="M"
  104. fi
  105. for PART in $PARTS ; do
  106. if [ ${TAG} != 0 ] ; then
  107. if [ "${PART}" = "autotag_for_be" ] ; then
  108. continue
  109. fi
  110. if [ "${PART}" = "autotag_for_sx00i" ] ; then
  111. continue
  112. fi
  113. RESULT="${PART}"
  114. break
  115. fi
  116. if [ ${BRANCH} != 0 ] ; then
  117. RESULT="${RESULT}-${PART}"
  118. if [ ${FEATURE} != 0 ] ; then
  119. RESULT="${RESULT}-${FEATURE_NAME}"
  120. fi
  121. break
  122. fi
  123. if [ ${TEAM} != 0 ] ; then
  124. if [ -z "${RESULT}" ] ; then
  125. RESULT="${PART}"
  126. else
  127. RESULT="${RESULT}-${PART}"
  128. fi
  129. continue
  130. fi
  131. if [ "${PART}" = "certified" ] ; then
  132. FEATURE=1
  133. FEATURE_NAME="cert"
  134. continue
  135. fi
  136. if [ "${PART}" = "branches" ] ; then
  137. BRANCH=1
  138. RESULT="branch"
  139. continue
  140. fi
  141. if [ "${PART}" = "tags" ] ; then
  142. TAG=1
  143. continue
  144. fi
  145. if [ "${PART}" = "team" ] ; then
  146. TEAM=1
  147. continue
  148. fi
  149. if [ "${PART}" = "trunk" ]; then
  150. echo SVN-trunk-r${SVN_REV}${MODIFIED}
  151. exit 0
  152. fi
  153. done
  154. if [ ${TAG} != 0 ] ; then
  155. echo ${RESULT}
  156. else
  157. echo SVN-${RESULT##-}-r${SVN_REV}${MODIFIED}
  158. fi
  159. fi
  160. else
  161. echo "UNKNOWN__and_probably_unsupported"
  162. fi