xref: /linux/scripts/setlocalversion (revision 3dce174cfcba11026b028d33bed0438b80e37124)
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
15117a93dbSRene Scharfe		printf '%s%s' -g `echo "$head" | cut -c1-8`
16117a93dbSRene Scharfe	fi
17aaebf433SRyan Anderson
18117a93dbSRene Scharfe	# Are there uncommitted changes?
19216b2f1fSUwe Zeisberger	if git diff-index HEAD | read dummy; then
2024d49756SRyan Anderson		printf '%s' -dirty
21117a93dbSRene Scharfe	fi
22*3dce174cSAron Griffis
23*3dce174cSAron Griffis	# All done with git
24*3dce174cSAron Griffis	exit
25*3dce174cSAron Griffisfi
26*3dce174cSAron Griffis
27*3dce174cSAron Griffis# Check for mercurial and a mercurial repo.
28*3dce174cSAron Griffisif hgid=`hg id 2>/dev/null`; then
29*3dce174cSAron Griffis	tag=`printf '%s' "$hgid" | cut -d' ' -f2`
30*3dce174cSAron Griffis
31*3dce174cSAron Griffis	# Do we have an untagged version?
32*3dce174cSAron Griffis	if [ -z "$tag" -o "$tag" = tip ]; then
33*3dce174cSAron Griffis		id=`printf '%s' "$hgid" | sed 's/[+ ].*//'`
34*3dce174cSAron Griffis		printf '%s%s' -hg "$id"
35*3dce174cSAron Griffis	fi
36*3dce174cSAron Griffis
37*3dce174cSAron Griffis	# Are there uncommitted changes?
38*3dce174cSAron Griffis	# These are represented by + after the changeset id.
39*3dce174cSAron Griffis	case "$hgid" in
40*3dce174cSAron Griffis		*+|*+\ *) printf '%s' -dirty ;;
41*3dce174cSAron Griffis	esac
42*3dce174cSAron Griffis
43*3dce174cSAron Griffis	# All done with mercurial
44*3dce174cSAron Griffis	exit
45117a93dbSRene Scharfefi
46