make_version 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. cd ${1}
  82. # If the first log commit messages indicates that this is checked into
  83. # subversion, we'll just use the SVN- form of the revision.
  84. MODIFIED=""
  85. SVN_REV=`${GIT} log --pretty=full -1 | ${GREP} -F "git-svn-id:" | sed -e "s/.*\@\([^\s]*\)\s.*/\1/g"`
  86. if [ -z "$SVN_REV" ]; then
  87. MAINLINE_BRANCH=$(git config -f .gitreview --get gerrit.defaultbranch)
  88. VERSION=`${GIT} describe --long --always --tags --dirty=M 2> /dev/null`
  89. if [ $? -ne 0 ]; then
  90. if [ "`${GIT} ls-files -m | wc -l`" != "0" ]; then
  91. MODIFIED="M"
  92. fi
  93. # Some older versions of git do not support all the above
  94. # options.
  95. VERSION=`${GIT} rev-parse --short --verify HEAD`${MODIFIED}
  96. fi
  97. echo GIT-${MAINLINE_BRANCH}-${VERSION}
  98. else
  99. 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'`
  100. BRANCH=0
  101. TEAM=0
  102. TAG=0
  103. FEATURE=0
  104. if [ "`${GIT} ls-files -m | wc -l`" != "0" ]; then
  105. MODIFIED="M"
  106. fi
  107. for PART in $PARTS ; do
  108. if [ ${TAG} != 0 ] ; then
  109. if [ "${PART}" = "autotag_for_be" ] ; then
  110. continue
  111. fi
  112. if [ "${PART}" = "autotag_for_sx00i" ] ; then
  113. continue
  114. fi
  115. RESULT="${PART}"
  116. break
  117. fi
  118. if [ ${BRANCH} != 0 ] ; then
  119. RESULT="${RESULT}-${PART}"
  120. if [ ${FEATURE} != 0 ] ; then
  121. RESULT="${RESULT}-${FEATURE_NAME}"
  122. fi
  123. break
  124. fi
  125. if [ ${TEAM} != 0 ] ; then
  126. if [ -z "${RESULT}" ] ; then
  127. RESULT="${PART}"
  128. else
  129. RESULT="${RESULT}-${PART}"
  130. fi
  131. continue
  132. fi
  133. if [ "${PART}" = "certified" ] ; then
  134. FEATURE=1
  135. FEATURE_NAME="cert"
  136. continue
  137. fi
  138. if [ "${PART}" = "branches" ] ; then
  139. BRANCH=1
  140. RESULT="branch"
  141. continue
  142. fi
  143. if [ "${PART}" = "tags" ] ; then
  144. TAG=1
  145. continue
  146. fi
  147. if [ "${PART}" = "team" ] ; then
  148. TEAM=1
  149. continue
  150. fi
  151. if [ "${PART}" = "trunk" ]; then
  152. echo SVN-trunk-r${SVN_REV}${MODIFIED}
  153. exit 0
  154. fi
  155. done
  156. if [ ${TAG} != 0 ] ; then
  157. echo ${RESULT}
  158. else
  159. echo SVN-${RESULT##-}-r${SVN_REV}${MODIFIED}
  160. fi
  161. fi
  162. else
  163. echo "UNKNOWN__and_probably_unsupported"
  164. fi