xref: /linux/scripts/setlocalversion (revision 56b2f0706d82535fd8d85503f2dcc0be40c8e55d)
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.
12117a93dbSRene Scharfeif head=`git rev-parse --verify HEAD 2>/dev/null`; then
13117a93dbSRene Scharfe	# Do we have an untagged version?
1429b0c899SUwe Zeisberger	if git name-rev --tags HEAD | grep -E '^HEAD[[:space:]]+(.*~[0-9]*|undefined)$' > /dev/null; then
15*56b2f070SSebastian Siewior		if tag=`git describe 2>/dev/null`; then
16*56b2f070SSebastian Siewior			echo $tag | awk -F- '{printf("-%05d-%s", $(NF-1),$(NF))}'
17*56b2f070SSebastian Siewior		fi
18117a93dbSRene Scharfe	fi
19aaebf433SRyan Anderson
20117a93dbSRene Scharfe	# Are there uncommitted changes?
214e7434ffSTheodore Ts'o	git update-index --refresh --unmerged > /dev/null
22b052ce4cSTheodore Ts'o	if git diff-index --name-only HEAD | grep -v "^scripts/package" \
23b052ce4cSTheodore Ts'o	    | read dummy; then
2424d49756SRyan Anderson		printf '%s' -dirty
25117a93dbSRene Scharfe	fi
263dce174cSAron Griffis
273dce174cSAron Griffis	# All done with git
283dce174cSAron Griffis	exit
293dce174cSAron Griffisfi
303dce174cSAron Griffis
313dce174cSAron Griffis# Check for mercurial and a mercurial repo.
323dce174cSAron Griffisif hgid=`hg id 2>/dev/null`; then
333dce174cSAron Griffis	tag=`printf '%s' "$hgid" | cut -d' ' -f2`
343dce174cSAron Griffis
353dce174cSAron Griffis	# Do we have an untagged version?
363dce174cSAron Griffis	if [ -z "$tag" -o "$tag" = tip ]; then
373dce174cSAron Griffis		id=`printf '%s' "$hgid" | sed 's/[+ ].*//'`
383dce174cSAron Griffis		printf '%s%s' -hg "$id"
393dce174cSAron Griffis	fi
403dce174cSAron Griffis
413dce174cSAron Griffis	# Are there uncommitted changes?
423dce174cSAron Griffis	# These are represented by + after the changeset id.
433dce174cSAron Griffis	case "$hgid" in
443dce174cSAron Griffis		*+|*+\ *) printf '%s' -dirty ;;
453dce174cSAron Griffis	esac
463dce174cSAron Griffis
473dce174cSAron Griffis	# All done with mercurial
483dce174cSAron Griffis	exit
49117a93dbSRene Scharfefi
50ba3d05fbSBryan Wu
51ba3d05fbSBryan Wu# Check for svn and a svn repo.
52ba3d05fbSBryan Wuif rev=`svn info 2>/dev/null | grep '^Revision'`; then
53ba3d05fbSBryan Wu	rev=`echo $rev | awk '{print $NF}'`
54ba3d05fbSBryan Wu	changes=`svn status 2>/dev/null | grep '^[AMD]' | wc -l`
55ba3d05fbSBryan Wu
56ba3d05fbSBryan Wu	# Are there uncommitted changes?
57ba3d05fbSBryan Wu	if [ $changes != 0 ]; then
58ba3d05fbSBryan Wu		printf -- '-svn%s%s%s' "$rev" -dirty "$changes"
59ba3d05fbSBryan Wu	else
60ba3d05fbSBryan Wu		printf -- '-svn%s' "$rev"
61ba3d05fbSBryan Wu	fi
62ba3d05fbSBryan Wu
63ba3d05fbSBryan Wu	# All done with svn
64ba3d05fbSBryan Wu	exit
65ba3d05fbSBryan Wufi
66