xref: /openbmc/linux/scripts/setlocalversion (revision 167d6a02)
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
22117a93dbSRene Scharfe	# Are there uncommitted changes?
234e7434ffSTheodore Ts'o	git update-index --refresh --unmerged > /dev/null
24b052ce4cSTheodore Ts'o	if git diff-index --name-only HEAD | grep -v "^scripts/package" \
25b052ce4cSTheodore Ts'o	    | read dummy; then
2624d49756SRyan Anderson		printf '%s' -dirty
27117a93dbSRene Scharfe	fi
283dce174cSAron Griffis
293dce174cSAron Griffis	# All done with git
303dce174cSAron Griffis	exit
313dce174cSAron Griffisfi
323dce174cSAron Griffis
333dce174cSAron Griffis# Check for mercurial and a mercurial repo.
343dce174cSAron Griffisif hgid=`hg id 2>/dev/null`; then
353dce174cSAron Griffis	tag=`printf '%s' "$hgid" | cut -d' ' -f2`
363dce174cSAron Griffis
373dce174cSAron Griffis	# Do we have an untagged version?
383dce174cSAron Griffis	if [ -z "$tag" -o "$tag" = tip ]; then
393dce174cSAron Griffis		id=`printf '%s' "$hgid" | sed 's/[+ ].*//'`
403dce174cSAron Griffis		printf '%s%s' -hg "$id"
413dce174cSAron Griffis	fi
423dce174cSAron Griffis
433dce174cSAron Griffis	# Are there uncommitted changes?
443dce174cSAron Griffis	# These are represented by + after the changeset id.
453dce174cSAron Griffis	case "$hgid" in
463dce174cSAron Griffis		*+|*+\ *) printf '%s' -dirty ;;
473dce174cSAron Griffis	esac
483dce174cSAron Griffis
493dce174cSAron Griffis	# All done with mercurial
503dce174cSAron Griffis	exit
51117a93dbSRene Scharfefi
52ba3d05fbSBryan Wu
53ba3d05fbSBryan Wu# Check for svn and a svn repo.
54167d6a02SPeter Korsgaardif rev=`svn info 2>/dev/null | grep '^Last Changed Rev'`; then
55ba3d05fbSBryan Wu	rev=`echo $rev | awk '{print $NF}'`
56ba3d05fbSBryan Wu	changes=`svn status 2>/dev/null | grep '^[AMD]' | wc -l`
57ba3d05fbSBryan Wu
58ba3d05fbSBryan Wu	# Are there uncommitted changes?
59ba3d05fbSBryan Wu	if [ $changes != 0 ]; then
60e3da2fb7SMike Frysinger		printf -- '-svn%s%s' "$rev" -dirty
61ba3d05fbSBryan Wu	else
62ba3d05fbSBryan Wu		printf -- '-svn%s' "$rev"
63ba3d05fbSBryan Wu	fi
64ba3d05fbSBryan Wu
65ba3d05fbSBryan Wu	# All done with svn
66ba3d05fbSBryan Wu	exit
67ba3d05fbSBryan Wufi
68