xref: /linux/scripts/setlocalversion (revision 4774bb1ced60a94d83b28e5a42d4cf01b83d9b60)
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
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
1556b2f070SSebastian Siewior		if tag=`git describe 2>/dev/null`; then
1656b2f070SSebastian Siewior			echo $tag | awk -F- '{printf("-%05d-%s", $(NF-1),$(NF))}'
17f03b283fSTrent Piepho		else
18f03b283fSTrent Piepho			printf '%s%s' -g $head
1956b2f070SSebastian Siewior		fi
20117a93dbSRene Scharfe	fi
21aaebf433SRyan Anderson
22ff80aa97SPeter Korsgaard	# Is this git on svn?
23ff80aa97SPeter Korsgaard	if git config --get svn-remote.svn.url >/dev/null; then
24*4774bb1cSPeter Korsgaard	        printf -- '-svn%s' "`git svn find-rev $head`"
25ff80aa97SPeter Korsgaard	fi
26ff80aa97SPeter Korsgaard
27117a93dbSRene Scharfe	# Are there uncommitted changes?
284e7434ffSTheodore Ts'o	git update-index --refresh --unmerged > /dev/null
29b052ce4cSTheodore Ts'o	if git diff-index --name-only HEAD | grep -v "^scripts/package" \
30b052ce4cSTheodore Ts'o	    | read dummy; then
3124d49756SRyan Anderson		printf '%s' -dirty
32117a93dbSRene Scharfe	fi
333dce174cSAron Griffis
343dce174cSAron Griffis	# All done with git
353dce174cSAron Griffis	exit
363dce174cSAron Griffisfi
373dce174cSAron Griffis
383dce174cSAron Griffis# Check for mercurial and a mercurial repo.
393dce174cSAron Griffisif hgid=`hg id 2>/dev/null`; then
403dce174cSAron Griffis	tag=`printf '%s' "$hgid" | cut -d' ' -f2`
413dce174cSAron Griffis
423dce174cSAron Griffis	# Do we have an untagged version?
433dce174cSAron Griffis	if [ -z "$tag" -o "$tag" = tip ]; then
443dce174cSAron Griffis		id=`printf '%s' "$hgid" | sed 's/[+ ].*//'`
453dce174cSAron Griffis		printf '%s%s' -hg "$id"
463dce174cSAron Griffis	fi
473dce174cSAron Griffis
483dce174cSAron Griffis	# Are there uncommitted changes?
493dce174cSAron Griffis	# These are represented by + after the changeset id.
503dce174cSAron Griffis	case "$hgid" in
513dce174cSAron Griffis		*+|*+\ *) printf '%s' -dirty ;;
523dce174cSAron Griffis	esac
533dce174cSAron Griffis
543dce174cSAron Griffis	# All done with mercurial
553dce174cSAron Griffis	exit
56117a93dbSRene Scharfefi
57ba3d05fbSBryan Wu
58ba3d05fbSBryan Wu# Check for svn and a svn repo.
59167d6a02SPeter Korsgaardif rev=`svn info 2>/dev/null | grep '^Last Changed Rev'`; then
60ba3d05fbSBryan Wu	rev=`echo $rev | awk '{print $NF}'`
61ba3d05fbSBryan Wu	printf -- '-svn%s' "$rev"
62ba3d05fbSBryan Wu
63ba3d05fbSBryan Wu	# All done with svn
64ba3d05fbSBryan Wu	exit
65ba3d05fbSBryan Wufi
66