xref: /openbmc/linux/scripts/setlocalversion (revision b052ce4c)
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
15d882421fSTheodore Ts'o	        git describe | awk -F- '{printf("-%05d-%s", $(NF-1),$(NF))}'
16117a93dbSRene Scharfe	fi
17aaebf433SRyan Anderson
18117a93dbSRene Scharfe	# Are there uncommitted changes?
194e7434ffSTheodore Ts'o	git update-index --refresh --unmerged > /dev/null
20b052ce4cSTheodore Ts'o	if git diff-index --name-only HEAD | grep -v "^scripts/package" \
21b052ce4cSTheodore Ts'o	    | read dummy; then
2224d49756SRyan Anderson		printf '%s' -dirty
23117a93dbSRene Scharfe	fi
243dce174cSAron Griffis
253dce174cSAron Griffis	# All done with git
263dce174cSAron Griffis	exit
273dce174cSAron Griffisfi
283dce174cSAron Griffis
293dce174cSAron Griffis# Check for mercurial and a mercurial repo.
303dce174cSAron Griffisif hgid=`hg id 2>/dev/null`; then
313dce174cSAron Griffis	tag=`printf '%s' "$hgid" | cut -d' ' -f2`
323dce174cSAron Griffis
333dce174cSAron Griffis	# Do we have an untagged version?
343dce174cSAron Griffis	if [ -z "$tag" -o "$tag" = tip ]; then
353dce174cSAron Griffis		id=`printf '%s' "$hgid" | sed 's/[+ ].*//'`
363dce174cSAron Griffis		printf '%s%s' -hg "$id"
373dce174cSAron Griffis	fi
383dce174cSAron Griffis
393dce174cSAron Griffis	# Are there uncommitted changes?
403dce174cSAron Griffis	# These are represented by + after the changeset id.
413dce174cSAron Griffis	case "$hgid" in
423dce174cSAron Griffis		*+|*+\ *) printf '%s' -dirty ;;
433dce174cSAron Griffis	esac
443dce174cSAron Griffis
453dce174cSAron Griffis	# All done with mercurial
463dce174cSAron Griffis	exit
47117a93dbSRene Scharfefi
48