You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.0KB

  1. #!/bin/sh
  2. #
  3. # This scripts adds local version information from the version
  4. # control systems git, mercurial (hg) and subversion (svn).
  5. #
  6. # Copied from Linux 2.6.32 scripts/setlocalversion and modified
  7. # slightly to work better for OpenOCD.
  8. #
  9. usage() {
  10. echo "Usage: $0 [srctree]" >&2
  11. exit 1
  12. }
  13. cd "${1:-.}" || usage
  14. # Check for git and a git repo.
  15. if head=`git rev-parse --verify --short HEAD 2>/dev/null`; then
  16. # If we are at a tagged commit (like "v2.6.30-rc6"), we ignore it,
  17. # because this version is defined in the top level Makefile.
  18. if [ -z "`git describe --exact-match 2>/dev/null`" ]; then
  19. # If we are past a tagged commit (like "v2.6.30-rc5-302-g72357d5"),
  20. # we pretty print it.
  21. if atag="`git describe 2>/dev/null`"; then
  22. echo "$atag" | awk -F- '{printf("-%05d-%s", $(NF-1),$(NF))}'
  23. # If we don't have a tag at all we print -g{commitish}.
  24. else
  25. printf '%s%s' -g $head
  26. fi
  27. fi
  28. # Is this git on svn?
  29. if git config --get svn-remote.svn.url >/dev/null; then
  30. printf -- '-svn%s' "`git svn find-rev $head`"
  31. fi
  32. # Update index only on r/w media
  33. [ -w . ] && git update-index --refresh --unmerged > /dev/null
  34. # Check for uncommitted changes
  35. if git diff-index --name-only HEAD | grep -v "^scripts/package" \
  36. | read dummy; then
  37. printf '%s' -dirty
  38. fi
  39. # All done with git
  40. exit
  41. fi
  42. # Check for mercurial and a mercurial repo.
  43. if hgid=`hg id 2>/dev/null`; then
  44. tag=`printf '%s' "$hgid" | cut -d' ' -f2`
  45. # Do we have an untagged version?
  46. if [ -z "$tag" -o "$tag" = tip ]; then
  47. id=`printf '%s' "$hgid" | sed 's/[+ ].*//'`
  48. printf '%s%s' -hg "$id"
  49. fi
  50. # Are there uncommitted changes?
  51. # These are represented by + after the changeset id.
  52. case "$hgid" in
  53. *+|*+\ *) printf '%s' -dirty ;;
  54. esac
  55. # All done with mercurial
  56. exit
  57. fi
  58. # Check for svn and a svn repo.
  59. if rev=`svn info 2>/dev/null | grep '^Last Changed Rev'`; then
  60. rev=`echo $rev | awk '{print $NF}'`
  61. printf -- '-svn%s' "$rev"
  62. # All done with svn
  63. exit
  64. fi
  65. # There's no recognized repository; we must be a snapshot.
  66. printf -- '-snapshot'