make_version 4.8 KB

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