1117a93dbSRene Scharfe#!/bin/sh 2*33252572SNico Schottelius# 3*33252572SNico Schottelius# This scripts adds local version information from the version 4*33252572SNico Schottelius# control systems git, mercurial (hg) and subversion (svn). 5*33252572SNico Schottelius# 6*33252572SNico Schottelius# If something goes wrong, send a mail the kernel build mailinglist 7*33252572SNico Schottelius# (see MAINTAINERS) and CC Nico Schottelius 8*33252572SNico Schottelius# <nico-linuxsetlocalversion -at- schottelius.org>. 9*33252572SNico Schottelius# 10*33252572SNico Schottelius# 11aaebf433SRyan Anderson 12117a93dbSRene Scharfeusage() { 13117a93dbSRene Scharfe echo "Usage: $0 [srctree]" >&2 14117a93dbSRene Scharfe exit 1 15aaebf433SRyan Anderson} 16aaebf433SRyan Anderson 17117a93dbSRene Scharfecd "${1:-.}" || usage 18aaebf433SRyan Anderson 19117a93dbSRene Scharfe# Check for git and a git repo. 20f03b283fSTrent Piephoif head=`git rev-parse --verify --short HEAD 2>/dev/null`; then 21*33252572SNico Schottelius 22*33252572SNico Schottelius # If we are at a tagged commit (like "v2.6.30-rc6"), we ignore it, 23*33252572SNico Schottelius # because this version is defined in the top level Makefile. 24*33252572SNico Schottelius if [ -z "`git describe --exact-match 2>/dev/null`" ]; then 25*33252572SNico Schottelius 26*33252572SNico Schottelius # If we are past a tagged commit (like "v2.6.30-rc5-302-g72357d5"), 27*33252572SNico Schottelius # we pretty print it. 28*33252572SNico Schottelius if atag="`git describe 2>/dev/null`"; then 29a182ad3dSNico Schottelius echo "$atag" | awk -F- '{printf("-%05d-%s", $(NF-1),$(NF))}' 30*33252572SNico Schottelius 31*33252572SNico Schottelius # If we don't have a tag at all we print -g{commitish}. 32f03b283fSTrent Piepho else 33f03b283fSTrent Piepho printf '%s%s' -g $head 3456b2f070SSebastian Siewior fi 35*33252572SNico Schottelius fi 36aaebf433SRyan Anderson 37ff80aa97SPeter Korsgaard # Is this git on svn? 38ff80aa97SPeter Korsgaard if git config --get svn-remote.svn.url >/dev/null; then 394774bb1cSPeter Korsgaard printf -- '-svn%s' "`git svn find-rev $head`" 40ff80aa97SPeter Korsgaard fi 41ff80aa97SPeter Korsgaard 42117a93dbSRene Scharfe # Are there uncommitted changes? 434e7434ffSTheodore Ts'o git update-index --refresh --unmerged > /dev/null 44b052ce4cSTheodore Ts'o if git diff-index --name-only HEAD | grep -v "^scripts/package" \ 45b052ce4cSTheodore Ts'o | read dummy; then 4624d49756SRyan Anderson printf '%s' -dirty 47117a93dbSRene Scharfe fi 483dce174cSAron Griffis 493dce174cSAron Griffis # All done with git 503dce174cSAron Griffis exit 513dce174cSAron Griffisfi 523dce174cSAron Griffis 533dce174cSAron Griffis# Check for mercurial and a mercurial repo. 543dce174cSAron Griffisif hgid=`hg id 2>/dev/null`; then 553dce174cSAron Griffis tag=`printf '%s' "$hgid" | cut -d' ' -f2` 563dce174cSAron Griffis 573dce174cSAron Griffis # Do we have an untagged version? 583dce174cSAron Griffis if [ -z "$tag" -o "$tag" = tip ]; then 593dce174cSAron Griffis id=`printf '%s' "$hgid" | sed 's/[+ ].*//'` 603dce174cSAron Griffis printf '%s%s' -hg "$id" 613dce174cSAron Griffis fi 623dce174cSAron Griffis 633dce174cSAron Griffis # Are there uncommitted changes? 643dce174cSAron Griffis # These are represented by + after the changeset id. 653dce174cSAron Griffis case "$hgid" in 663dce174cSAron Griffis *+|*+\ *) printf '%s' -dirty ;; 673dce174cSAron Griffis esac 683dce174cSAron Griffis 693dce174cSAron Griffis # All done with mercurial 703dce174cSAron Griffis exit 71117a93dbSRene Scharfefi 72ba3d05fbSBryan Wu 73ba3d05fbSBryan Wu# Check for svn and a svn repo. 74167d6a02SPeter Korsgaardif rev=`svn info 2>/dev/null | grep '^Last Changed Rev'`; then 75ba3d05fbSBryan Wu rev=`echo $rev | awk '{print $NF}'` 76ba3d05fbSBryan Wu printf -- '-svn%s' "$rev" 77ba3d05fbSBryan Wu 78ba3d05fbSBryan Wu # All done with svn 79ba3d05fbSBryan Wu exit 80ba3d05fbSBryan Wufi 81