setlocalversion 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. # If something goes wrong, send a mail the kernel build mailinglist
  7. # (see MAINTAINERS) and CC Nico Schottelius
  8. # <nico-linuxsetlocalversion -at- schottelius.org>.
  9. #
  10. #
  11. usage() {
  12. echo "Usage: $0 [srctree]" >&2
  13. exit 1
  14. }
  15. cd "${1:-.}" || usage
  16. # Check for git and a git repo.
  17. if head=`git rev-parse --verify --short HEAD 2>/dev/null`; then
  18. atag="`git describe 2>/dev/null`"
  19. # Show -g<commit> if we have no tag, or just the tag
  20. # otherwise.
  21. if [ -z "${atag}" ] ; then
  22. printf "%s%s" -g ${head}
  23. else
  24. printf ${atag}
  25. fi
  26. # Is this git on svn?
  27. if git config --get svn-remote.svn.url >/dev/null; then
  28. printf -- '-svn%s' "`git svn find-rev $head`"
  29. fi
  30. # Update index only on r/w media
  31. [ -w . ] && git update-index --refresh --unmerged > /dev/null
  32. # Check for uncommitted changes
  33. if git diff-index --name-only HEAD | grep -v "^scripts/package" \
  34. | read dummy; then
  35. printf '%s' -dirty
  36. fi
  37. # All done with git
  38. exit
  39. fi
  40. # Check for mercurial and a mercurial repo.
  41. if hgid=`HGRCPATH= hg id --id --tags 2>/dev/null`; then
  42. tag=`printf '%s' "$hgid" | cut -d' ' -f2 --only-delimited`
  43. # Do we have an untagged version?
  44. if [ -z "$tag" -o "$tag" = tip ]; then
  45. id=`printf '%s' "$hgid" | sed 's/[+ ].*//'`
  46. printf '%s%s' -hg "$id"
  47. else
  48. printf ${tag}
  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=`LC_ALL=C 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