xref: /linux/scripts/setlocalversion (revision a182ad3d0f858f50bb719a48bb35a013e12366c5)
1117a93dbSRene Scharfe#!/bin/sh
2117a93dbSRene Scharfe# Print additional version information for non-release trees.
3aaebf433SRyan Anderson
4117a93dbSRene Scharfeusage() {
5117a93dbSRene Scharfe	echo "Usage: $0 [srctree]" >&2
6117a93dbSRene Scharfe	exit 1
7aaebf433SRyan Anderson}
8aaebf433SRyan Anderson
9117a93dbSRene Scharfecd "${1:-.}" || usage
10aaebf433SRyan Anderson
11117a93dbSRene Scharfe# Check for git and a git repo.
12f03b283fSTrent Piephoif head=`git rev-parse --verify --short HEAD 2>/dev/null`; then
13*a182ad3dSNico Schottelius	# Do we have an untagged tag?
14*a182ad3dSNico Schottelius	if atag=`git describe 2>/dev/null`; then
15*a182ad3dSNico Schottelius		echo "$atag" | awk -F- '{printf("-%05d-%s", $(NF-1),$(NF))}'
16*a182ad3dSNico Schottelius	# add -g${head}, if there is no usable tag
17f03b283fSTrent Piepho	else
18f03b283fSTrent Piepho		printf '%s%s' -g $head
1956b2f070SSebastian Siewior	fi
20aaebf433SRyan Anderson
21ff80aa97SPeter Korsgaard	# Is this git on svn?
22ff80aa97SPeter Korsgaard	if git config --get svn-remote.svn.url >/dev/null; then
234774bb1cSPeter Korsgaard	        printf -- '-svn%s' "`git svn find-rev $head`"
24ff80aa97SPeter Korsgaard	fi
25ff80aa97SPeter Korsgaard
26117a93dbSRene Scharfe	# Are there uncommitted changes?
274e7434ffSTheodore Ts'o	git update-index --refresh --unmerged > /dev/null
28b052ce4cSTheodore Ts'o	if git diff-index --name-only HEAD | grep -v "^scripts/package" \
29b052ce4cSTheodore Ts'o	    | read dummy; then
3024d49756SRyan Anderson		printf '%s' -dirty
31117a93dbSRene Scharfe	fi
323dce174cSAron Griffis
333dce174cSAron Griffis	# All done with git
343dce174cSAron Griffis	exit
353dce174cSAron Griffisfi
363dce174cSAron Griffis
373dce174cSAron Griffis# Check for mercurial and a mercurial repo.
383dce174cSAron Griffisif hgid=`hg id 2>/dev/null`; then
393dce174cSAron Griffis	tag=`printf '%s' "$hgid" | cut -d' ' -f2`
403dce174cSAron Griffis
413dce174cSAron Griffis	# Do we have an untagged version?
423dce174cSAron Griffis	if [ -z "$tag" -o "$tag" = tip ]; then
433dce174cSAron Griffis		id=`printf '%s' "$hgid" | sed 's/[+ ].*//'`
443dce174cSAron Griffis		printf '%s%s' -hg "$id"
453dce174cSAron Griffis	fi
463dce174cSAron Griffis
473dce174cSAron Griffis	# Are there uncommitted changes?
483dce174cSAron Griffis	# These are represented by + after the changeset id.
493dce174cSAron Griffis	case "$hgid" in
503dce174cSAron Griffis		*+|*+\ *) printf '%s' -dirty ;;
513dce174cSAron Griffis	esac
523dce174cSAron Griffis
533dce174cSAron Griffis	# All done with mercurial
543dce174cSAron Griffis	exit
55117a93dbSRene Scharfefi
56ba3d05fbSBryan Wu
57ba3d05fbSBryan Wu# Check for svn and a svn repo.
58167d6a02SPeter Korsgaardif rev=`svn info 2>/dev/null | grep '^Last Changed Rev'`; then
59ba3d05fbSBryan Wu	rev=`echo $rev | awk '{print $NF}'`
60ba3d05fbSBryan Wu	printf -- '-svn%s' "$rev"
61ba3d05fbSBryan Wu
62ba3d05fbSBryan Wu	# All done with svn
63ba3d05fbSBryan Wu	exit
64ba3d05fbSBryan Wufi
65