1117a93dbSRene Scharfe#!/bin/sh 233252572SNico Schottelius# 333252572SNico Schottelius# This scripts adds local version information from the version 433252572SNico Schottelius# control systems git, mercurial (hg) and subversion (svn). 533252572SNico Schottelius# 633252572SNico Schottelius# If something goes wrong, send a mail the kernel build mailinglist 733252572SNico Schottelius# (see MAINTAINERS) and CC Nico Schottelius 833252572SNico Schottelius# <nico-linuxsetlocalversion -at- schottelius.org>. 933252572SNico Schottelius# 1033252572SNico 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 2133252572SNico Schottelius 2233252572SNico Schottelius # If we are at a tagged commit (like "v2.6.30-rc6"), we ignore it, 2333252572SNico Schottelius # because this version is defined in the top level Makefile. 2433252572SNico Schottelius if [ -z "`git describe --exact-match 2>/dev/null`" ]; then 2533252572SNico Schottelius 2633252572SNico Schottelius # If we are past a tagged commit (like "v2.6.30-rc5-302-g72357d5"), 2733252572SNico Schottelius # we pretty print it. 2833252572SNico Schottelius if atag="`git describe 2>/dev/null`"; then 29a182ad3dSNico Schottelius echo "$atag" | awk -F- '{printf("-%05d-%s", $(NF-1),$(NF))}' 3033252572SNico Schottelius 3133252572SNico 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 3533252572SNico 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 42*a2bb90a0SNico Schottelius # Update index only on r/w media 43*a2bb90a0SNico Schottelius [ -w . ] && git update-index --refresh --unmerged > /dev/null 44*a2bb90a0SNico Schottelius 45*a2bb90a0SNico Schottelius # Check for uncommitted changes 46b052ce4cSTheodore Ts'o if git diff-index --name-only HEAD | grep -v "^scripts/package" \ 47b052ce4cSTheodore Ts'o | read dummy; then 4824d49756SRyan Anderson printf '%s' -dirty 49117a93dbSRene Scharfe fi 503dce174cSAron Griffis 513dce174cSAron Griffis # All done with git 523dce174cSAron Griffis exit 533dce174cSAron Griffisfi 543dce174cSAron Griffis 553dce174cSAron Griffis# Check for mercurial and a mercurial repo. 563dce174cSAron Griffisif hgid=`hg id 2>/dev/null`; then 573dce174cSAron Griffis tag=`printf '%s' "$hgid" | cut -d' ' -f2` 583dce174cSAron Griffis 593dce174cSAron Griffis # Do we have an untagged version? 603dce174cSAron Griffis if [ -z "$tag" -o "$tag" = tip ]; then 613dce174cSAron Griffis id=`printf '%s' "$hgid" | sed 's/[+ ].*//'` 623dce174cSAron Griffis printf '%s%s' -hg "$id" 633dce174cSAron Griffis fi 643dce174cSAron Griffis 653dce174cSAron Griffis # Are there uncommitted changes? 663dce174cSAron Griffis # These are represented by + after the changeset id. 673dce174cSAron Griffis case "$hgid" in 683dce174cSAron Griffis *+|*+\ *) printf '%s' -dirty ;; 693dce174cSAron Griffis esac 703dce174cSAron Griffis 713dce174cSAron Griffis # All done with mercurial 723dce174cSAron Griffis exit 73117a93dbSRene Scharfefi 74ba3d05fbSBryan Wu 75ba3d05fbSBryan Wu# Check for svn and a svn repo. 76167d6a02SPeter Korsgaardif rev=`svn info 2>/dev/null | grep '^Last Changed Rev'`; then 77ba3d05fbSBryan Wu rev=`echo $rev | awk '{print $NF}'` 78ba3d05fbSBryan Wu printf -- '-svn%s' "$rev" 79ba3d05fbSBryan Wu 80ba3d05fbSBryan Wu # All done with svn 81ba3d05fbSBryan Wu exit 82ba3d05fbSBryan Wufi 83