setlocalversion 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. # Are there uncommitted changes?
  35. git update-index --refresh --unmerged > /dev/null
  36. if git diff-index --name-only HEAD | grep -v "^scripts/package" \
  37. | read dummy; then
  38. printf '%s' -dirty
  39. fi
  40. # All done with git
  41. exit
  42. fi
  43. # Check for mercurial and a mercurial repo.
  44. if hgid=`hg id 2>/dev/null`; then
  45. tag=`printf '%s' "$hgid" | cut -d' ' -f2`
  46. # Do we have an untagged version?
  47. if [ -z "$tag" -o "$tag" = tip ]; then
  48. id=`printf '%s' "$hgid" | sed 's/[+ ].*//'`
  49. printf '%s%s' -hg "$id"
  50. fi
  51. # Are there uncommitted changes?
  52. # These are represented by + after the changeset id.
  53. case "$hgid" in
  54. *+|*+\ *) printf '%s' -dirty ;;
  55. esac
  56. # All done with mercurial
  57. exit
  58. fi
  59. # Check for svn and a svn repo.
  60. if rev=`svn info 2>/dev/null | grep '^Last Changed Rev'`; then
  61. rev=`echo $rev | awk '{print $NF}'`
  62. printf -- '-svn%s' "$rev"
  63. # All done with svn
  64. exit
  65. fi