Debian Codegraph @

scripts/setlocalversion

raw
1 #!/bin/sh
2 #
3 # Copyright (c) 2005-2006 Ryan Anderson <[email protected]>
4 # Copyright (c) 2006 Rene Scharfe <[email protected]>
5 # Copyright (c) 2006 Uwe Zeisberger <[email protected]>
6 # Copyright (c) 2007 Aron Griffis <[email protected]>
7 # Copyright (c) 2007 Theodore Ts'o <[email protected]>
8 # Copyright (c) 2008 Bryan Wu <[email protected]>
9 # Copyright (c) 2008 Mike Frysinger <[email protected]>
10 # Copyright (c) 2008 Peter Korsgaard <[email protected]>
11 # Copyright (c) 2008 Sebastian Siewior <[email protected]>
12 # Copyright (c) 2008 Trent Piepho <[email protected]>
13 # Copyright (c) 2009 Mike Frysinger <[email protected]>
14 # Copyright (c) 2009 Nico Schottelius <[email protected]>
15 # Copyright (c) 2009 Peter Korsgaard <[email protected]>
16 # Copyright (c) 2010 Linus Torvalds <[email protected]>
17 # Copyright (c) 2010 Michael Prokop <[email protected]>
18 # Copyright (c) 2010 Michał Górny <[email protected]>
19 # Copyright (c) 2010 Michal Marek <[email protected]>
20 # Copyright (c) 2010 Milton Miller <[email protected]>
21 # Copyright (c) 2011 Mike Crowe <[email protected]>
22 # Copyright (c) 2012 Roland Dreier <[email protected]>
23 # Copyright (c) 2013 Christian Kujau <[email protected]>
24 # Copyright (c) 2013 Christophe Leroy <[email protected]>
25 # Copyright (c) 2013 Franck Bui-Huu <[email protected]>
26 # Copyright (c) 2015 Luis R. Rodriguez <[email protected]>
27 #
28 # This file is released under the GPLv2.
29 #
30 # Taken from the Linux kernel as of v4.2-rc2 with a few modifications
31 # described below.
32 #
33 # This scripts adds local version information from the version
34 # control systems. It was taken from the Linux kernel as of v4.2-rc2
35 # and simplified for use on Coccinelle by mcgrof. The version info
36 # was hard coded to use long version. The svn postfix details were
37 # also removed. I also added the option to enable this script to
38 # work well for trees that do not use PGP signed tags or annotated
39 # tags (git tag -s or git tag -a), git describe by default will only
40 # look for these tags. If you do not use these you will want to set
41 # the below variable to TAGS="--tags". If you requires --tags, consider
42 # to start signing your releases "git tag -s" and use a subkey for that.
43 # If you do that, consider also using another PGP subkey for annotating
44 # releases as deprecated.
45 #
46 # Set to empty variable if you use properly signed tags. You should do this!
47 TAGS="--tags"
48
49 srctree=.
50
51 scm_version()
52 {
53 local short
54 short=false
55
56
57 # Check for git and a git repo.
58 if test -z "$(git rev-parse --show-cdup 2>/dev/null)" &&
59 head=`git rev-parse --verify --short HEAD 2>/dev/null`; then
60
61 # If we are at a tagged commit (like "v2.6.30-rc6"), we ignore
62 # it, because this version is defined in the top level Makefile.
63 if [ -z "`git describe $TAGS --exact-match 2>/dev/null`" ]; then
64
65 # If only the short version is requested, don't bother
66 # running further git commands
67 if $short; then
68 echo "+"
69 return
70 fi
71 # If we are past a tagged commit (like
72 # "v2.6.30-rc5-302-g72357d5"), we pretty print it.
73 if atag="`git describe $TAGS 2>/dev/null`"; then
74 echo "$atag" | awk -F- '{printf("-%05d-%s", $(NF-1),$(NF))}'
75
76 # If we don't have a tag at all we print -g{commitish}.
77 else
78 printf '%s%s' -g $head
79 fi
80 fi
81
82 # Check for uncommitted changes
83 if git diff-index --name-only HEAD | grep -qv "^scripts/package"; then
84 printf '%s' -dirty
85 fi
86
87 # All done with git
88 return
89 fi
90
91 # Check for mercurial and a mercurial repo.
92 if test -d .hg && hgid=`hg id 2>/dev/null`; then
93 # Do we have an tagged version? If so, latesttagdistance == 1
94 if [ "`hg log -r . --template '{latesttagdistance}'`" == "1" ]; then
95 id=`hg log -r . --template '{latesttag}'`
96 printf '%s%s' -hg "$id"
97 else
98 tag=`printf '%s' "$hgid" | cut -d' ' -f2`
99 if [ -z "$tag" -o "$tag" = tip ]; then
100 id=`printf '%s' "$hgid" | sed 's/[+ ].*//'`
101 printf '%s%s' -hg "$id"
102 fi
103 fi
104
105 # Are there uncommitted changes?
106 # These are represented by + after the changeset id.
107 case "$hgid" in
108 *+|*+\ *) printf '%s' -dirty ;;
109 esac
110
111 # All done with mercurial
112 return
113 fi
114 }
115
116 res="$res$(scm_version)"
117 echo "$res"