setlocalversion 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. # If we are at a tagged commit (like "v2.6.30-rc6"), we ignore it,
  19. # because this version is defined in the top level Makefile.
  20. if [ -z "`git describe --exact-match 2>/dev/null`" ]; then
  21. # If we are past a tagged commit (like "v2.6.30-rc5-302-g72357d5"),
  22. # we pretty print it.
  23. if atag="`git describe 2>/dev/null`"; then
  24. echo "$atag" | awk -F- '{printf("-%05d-%s", $(NF-1),$(NF))}'
  25. # If we don't have a tag at all we print -g{commitish}.
  26. else
  27. printf '%s%s' -g $head
  28. fi
  29. fi
  30. # Is this git on svn?
  31. if git config --get svn-remote.svn.url >/dev/null; then
  32. printf -- '-svn%s' "`git svn find-rev $head`"
  33. fi
  34. # Update index only on r/w media
  35. [ -w . ] && git update-index --refresh --unmerged > /dev/null
  36. # Check for uncommitted changes
  37. if git diff-index --name-only HEAD | grep -v "^scripts/package" \
  38. | read dummy; then
  39. printf '%s' -dirty
  40. fi
  41. # All done with git
  42. exit
  43. fi
  44. # Check for mercurial and a mercurial repo.
  45. if hgid=`hg id 2>/dev/null`; then
  46. tag=`printf '%s' "$hgid" | cut -d' ' -f2 --only-delimited`
  47. # Do we have an untagged version?
  48. if [ -z "$tag" -o "$tag" = tip ]; then
  49. id=`printf '%s' "$hgid" | sed 's/[+ ].*//'`
  50. printf '%s%s' -hg "$id"
  51. fi
  52. # Are there uncommitted changes?
  53. # These are represented by + after the changeset id.
  54. case "$hgid" in
  55. *+|*+\ *) printf '%s' -dirty ;;
  56. esac
  57. # All done with mercurial
  58. exit
  59. fi
  60. # Check for svn and a svn repo.
  61. if rev=`LC_ALL=C svn info 2>/dev/null | grep '^Last Changed Rev'`; then
  62. rev=`echo $rev | awk '{print $NF}'`
  63. printf -- '-svn%s' "$rev"
  64. # All done with svn
  65. exit
  66. fi