Mercurial > gnulib
annotate build-aux/git-version-gen @ 19036:125fe2f313c6
git-version-gen: Fix for tags containing '-'
Really old versions of git-describe (before v1.5.0, Feb 2007) don't
have the number of commits in their long format output, i.e. where
modern 'git describe --abbrev=4 --match="v*"' prints
"v0.1-1494-g124b9", they print "v0.1-1494-g124b9". git-version-gen
recognizes both patterns, and normalizes the old format to the new
one.
Unfortunately, this normalization code gets confused when the tag
contains '-'. Reproducer:
$ git-tag -m test v0.2-rc1
$ build-aux/git-version-gen .tarball-version; echo
build-aux/git-version-gen: WARNING: git rev-list failed
UNKNOWN
We take exact tag "v0.2-rc1" for the old format, extract the presumed
tag "v0.2" from it, then run "git rev-list v0.2..HEAD" to count
commits since tha tag. Fails, because tag "v0.2" does not exist.
* git-version-gen: We could perhaps drop support for versions from more
than a decade ago. But tightening the pattern match is easy enough,
so do that. Still breaks when you use version tags ending in something
matching -g????, but you arguably get what you deserve then.
author | Markus Armbruster <armbru@pond.sub.org> |
---|---|
date | Sun, 06 Aug 2017 08:26:03 +0200 |
parents | caf9d6314c8f |
children | b19c2e91a4c8 |
rev | line source |
---|---|
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
1 #!/bin/sh |
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
2 # Print a version string. |
19036
125fe2f313c6
git-version-gen: Fix for tags containing '-'
Markus Armbruster <armbru@pond.sub.org>
parents:
18663
diff
changeset
|
3 scriptversion=2017-08-06.05; # UTC |
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
4 |
18626 | 5 # Copyright (C) 2007-2017 Free Software Foundation, Inc. |
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
6 # |
11986
ff87a690cd47
Fix copyright header in build-aux scripts.
Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
parents:
9877
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
8 # it under the terms of the GNU General Public License as published by |
11986
ff87a690cd47
Fix copyright header in build-aux scripts.
Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
parents:
9877
diff
changeset
|
9 # the Free Software Foundation; either version 3 of the License, or |
ff87a690cd47
Fix copyright header in build-aux scripts.
Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
parents:
9877
diff
changeset
|
10 # (at your option) any later version. |
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
11 # |
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
15 # GNU General Public License for more details. |
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
16 # |
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
17 # You should have received a copy of the GNU General Public License |
11986
ff87a690cd47
Fix copyright header in build-aux scripts.
Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
parents:
9877
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
19 |
9452
595a77da32de
git-version-gen: sync from coreutils.
Jim Meyering <meyering@redhat.com>
parents:
9175
diff
changeset
|
20 # This script is derived from GIT-VERSION-GEN from GIT: http://git.or.cz/. |
595a77da32de
git-version-gen: sync from coreutils.
Jim Meyering <meyering@redhat.com>
parents:
9175
diff
changeset
|
21 # It may be run two ways: |
9677
54e86898dd7d
* build-aux/git-version-gen: Use "git status", not "git-status".
Jim Meyering <meyering@redhat.com>
parents:
9452
diff
changeset
|
22 # - from a git repository in which the "git describe" command below |
9452
595a77da32de
git-version-gen: sync from coreutils.
Jim Meyering <meyering@redhat.com>
parents:
9175
diff
changeset
|
23 # produces useful output (thus requiring at least one signed tag) |
9748
c0c8409cb7a2
* build-aux/git-version-gen: Adjust a comment and the Usage string.
Jim Meyering <meyering@redhat.com>
parents:
9719
diff
changeset
|
24 # - from a non-git-repo directory containing a .tarball-version file, which |
9677
54e86898dd7d
* build-aux/git-version-gen: Use "git status", not "git-status".
Jim Meyering <meyering@redhat.com>
parents:
9452
diff
changeset
|
25 # presumes this script is invoked like "./git-version-gen .tarball-version". |
9452
595a77da32de
git-version-gen: sync from coreutils.
Jim Meyering <meyering@redhat.com>
parents:
9175
diff
changeset
|
26 |
9869 | 27 # In order to use intra-version strings in your project, you will need two |
28 # separate generated version string files: | |
29 # | |
30 # .tarball-version - present only in a distribution tarball, and not in | |
31 # a checked-out repository. Created with contents that were learned at | |
32 # the last time autoconf was run, and used by git-version-gen. Must not | |
33 # be present in either $(srcdir) or $(builddir) for git-version-gen to | |
34 # give accurate answers during normal development with a checked out tree, | |
35 # but must be present in a tarball when there is no version control system. | |
36 # Therefore, it cannot be used in any dependencies. GNUmakefile has | |
37 # hooks to force a reconfigure at distribution time to get the value | |
38 # correct, without penalizing normal development with extra reconfigures. | |
39 # | |
40 # .version - present in a checked-out repository and in a distribution | |
41 # tarball. Usable in dependencies, particularly for files that don't | |
42 # want to depend on config.h but do want to track version changes. | |
43 # Delete this file prior to any autoconf run where you want to rebuild | |
44 # files to pick up a version string change; and leave it stale to | |
45 # minimize rebuild time after unrelated changes to configure sources. | |
46 # | |
15511
52b887a92a8c
git-version-gen: correct the advice in a comment
Jim Meyering <meyering@redhat.com>
parents:
15492
diff
changeset
|
47 # As with any generated file in a VC'd directory, you should add |
52b887a92a8c
git-version-gen: correct the advice in a comment
Jim Meyering <meyering@redhat.com>
parents:
15492
diff
changeset
|
48 # /.version to .gitignore, so that you don't accidentally commit it. |
52b887a92a8c
git-version-gen: correct the advice in a comment
Jim Meyering <meyering@redhat.com>
parents:
15492
diff
changeset
|
49 # .tarball-version is never generated in a VC'd directory, so needn't |
52b887a92a8c
git-version-gen: correct the advice in a comment
Jim Meyering <meyering@redhat.com>
parents:
15492
diff
changeset
|
50 # be listed there. |
9869 | 51 # |
52 # Use the following line in your configure.ac, so that $(VERSION) will | |
53 # automatically be up-to-date each time configure is run (and note that | |
54 # since configure.ac no longer includes a version string, Makefile rules | |
55 # should not depend on configure.ac for version updates). | |
56 # | |
57 # AC_INIT([GNU project], | |
58 # m4_esyscmd([build-aux/git-version-gen .tarball-version]), | |
59 # [bug-project@example]) | |
60 # | |
61 # Then use the following lines in your Makefile.am, so that .version | |
15492
b54bff314db1
git-version-gen: document that EXTRA_DIST must include .version
Iain Nicol <iain@iainnicol.com>
parents:
14372
diff
changeset
|
62 # will be present for dependencies, and so that .version and |
b54bff314db1
git-version-gen: document that EXTRA_DIST must include .version
Iain Nicol <iain@iainnicol.com>
parents:
14372
diff
changeset
|
63 # .tarball-version will exist in distribution tarballs. |
9869 | 64 # |
15492
b54bff314db1
git-version-gen: document that EXTRA_DIST must include .version
Iain Nicol <iain@iainnicol.com>
parents:
14372
diff
changeset
|
65 # EXTRA_DIST = $(top_srcdir)/.version |
9869 | 66 # BUILT_SOURCES = $(top_srcdir)/.version |
67 # $(top_srcdir)/.version: | |
68 # echo $(VERSION) > $@-t && mv $@-t $@ | |
69 # dist-hook: | |
70 # echo $(VERSION) > $(distdir)/.tarball-version | |
71 | |
16082
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
72 |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
73 me=$0 |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
74 |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
75 version="git-version-gen $scriptversion |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
76 |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
77 Copyright 2011 Free Software Foundation, Inc. |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
78 There is NO warranty. You may redistribute this software |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
79 under the terms of the GNU General Public License. |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
80 For more information about these matters, see the files named COPYING." |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
81 |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
82 usage="\ |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
83 Usage: $me [OPTION]... \$srcdir/.tarball-version [TAG-NORMALIZATION-SED-SCRIPT] |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
84 Print a version string. |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
85 |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
86 Options: |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
87 |
17711
bbf6398214e1
git-version-gen: improve option descriptions
Alfred M. Szmidt <ams@gnu.org>
parents:
17576
diff
changeset
|
88 --prefix PREFIX prefix of git tags (default 'v') |
bbf6398214e1
git-version-gen: improve option descriptions
Alfred M. Szmidt <ams@gnu.org>
parents:
17576
diff
changeset
|
89 --fallback VERSION |
bbf6398214e1
git-version-gen: improve option descriptions
Alfred M. Szmidt <ams@gnu.org>
parents:
17576
diff
changeset
|
90 fallback version to use if \"git --version\" fails |
16083
1b52ba2f7e83
git-version-gen: Add --prefix.
Simon Josefsson <simon@josefsson.org>
parents:
16082
diff
changeset
|
91 |
16082
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
92 --help display this help and exit |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
93 --version output version information and exit |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
94 |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
95 Running without arguments will suffice in most cases." |
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
96 |
16706
bd179cf2c9ea
git-version-gen: don't let "prefix" envvar cause trouble
Andreas Oberritter <obi@opendreambox.org>
parents:
16234
diff
changeset
|
97 prefix=v |
17245
179b150e5256
git-version-gen: add --fallback option to use if git is not present
Peter Rosin <peda@lysator.liu.se>
parents:
16706
diff
changeset
|
98 fallback= |
16706
bd179cf2c9ea
git-version-gen: don't let "prefix" envvar cause trouble
Andreas Oberritter <obi@opendreambox.org>
parents:
16234
diff
changeset
|
99 |
16082
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
100 while test $# -gt 0; do |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
101 case $1 in |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
102 --help) echo "$usage"; exit 0;; |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
103 --version) echo "$version"; exit 0;; |
18311
79b2ca5b5982
git-version-gen: avoid undefined shift
Paul Eggert <eggert@cs.ucla.edu>
parents:
18195
diff
changeset
|
104 --prefix) shift; prefix=${1?};; |
79b2ca5b5982
git-version-gen: avoid undefined shift
Paul Eggert <eggert@cs.ucla.edu>
parents:
18195
diff
changeset
|
105 --fallback) shift; fallback=${1?};; |
16082
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
106 -*) |
16234
f9b906545e2f
Use ', not `, for quoting output.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
107 echo "$0: Unknown option '$1'." >&2 |
f9b906545e2f
Use ', not `, for quoting output.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
108 echo "$0: Try '--help' for more information." >&2 |
16082
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
109 exit 1;; |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
110 *) |
17246
7d2aa4fc02ab
git-version-gen: avoid test -z portability glitch
Eric Blake <eblake@redhat.com>
parents:
17245
diff
changeset
|
111 if test "x$tarball_version_file" = x; then |
16082
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
112 tarball_version_file="$1" |
17246
7d2aa4fc02ab
git-version-gen: avoid test -z portability glitch
Eric Blake <eblake@redhat.com>
parents:
17245
diff
changeset
|
113 elif test "x$tag_sed_script" = x; then |
16082
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
114 tag_sed_script="$1" |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
115 else |
16234
f9b906545e2f
Use ', not `, for quoting output.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
116 echo "$0: extra non-option argument '$1'." >&2 |
16082
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
117 exit 1 |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
118 fi;; |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
119 esac |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
120 shift |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
121 done |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
122 |
17246
7d2aa4fc02ab
git-version-gen: avoid test -z portability glitch
Eric Blake <eblake@redhat.com>
parents:
17245
diff
changeset
|
123 if test "x$tarball_version_file" = x; then |
16082
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
124 echo "$usage" |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
125 exit 1 |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
126 fi |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
127 |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
128 tag_sed_script="${tag_sed_script:-s/x/x/}" |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
129 |
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
130 nl=' |
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
131 ' |
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
132 |
13423
ba0385f65ed2
git-version-gen: init shell var to avoid env var influence
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
13379
diff
changeset
|
133 # Avoid meddling by environment variable of the same name. |
ba0385f65ed2
git-version-gen: init shell var to avoid env var influence
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
13379
diff
changeset
|
134 v= |
14372
b894b1646164
git-version-gen: skip "-dirty" check when appropriate
Jim Meyering <meyering@redhat.com>
parents:
14133
diff
changeset
|
135 v_from_git= |
13423
ba0385f65ed2
git-version-gen: init shell var to avoid env var influence
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
13379
diff
changeset
|
136 |
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
137 # First see if there is a tarball-only version file. |
9677
54e86898dd7d
* build-aux/git-version-gen: Use "git status", not "git-status".
Jim Meyering <meyering@redhat.com>
parents:
9452
diff
changeset
|
138 # then try "git describe", then default. |
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
139 if test -f $tarball_version_file |
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
140 then |
14093
bae3b310c970
git-version-gen: include command name in one more diagnostic
Jim Meyering <meyering@redhat.com>
parents:
14079
diff
changeset
|
141 v=`cat $tarball_version_file` || v= |
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
142 case $v in |
14095
a6c3d8a0de24
git-version-gen: convert leading TABs to spaces
Jim Meyering <meyering@redhat.com>
parents:
14094
diff
changeset
|
143 *$nl*) v= ;; # reject multi-line output |
a6c3d8a0de24
git-version-gen: convert leading TABs to spaces
Jim Meyering <meyering@redhat.com>
parents:
14094
diff
changeset
|
144 [0-9]*) ;; |
a6c3d8a0de24
git-version-gen: convert leading TABs to spaces
Jim Meyering <meyering@redhat.com>
parents:
14094
diff
changeset
|
145 *) v= ;; |
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
146 esac |
17246
7d2aa4fc02ab
git-version-gen: avoid test -z portability glitch
Eric Blake <eblake@redhat.com>
parents:
17245
diff
changeset
|
147 test "x$v" = x \ |
14095
a6c3d8a0de24
git-version-gen: convert leading TABs to spaces
Jim Meyering <meyering@redhat.com>
parents:
14094
diff
changeset
|
148 && echo "$0: WARNING: $tarball_version_file is missing or damaged" 1>&2 |
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
149 fi |
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
150 |
17246
7d2aa4fc02ab
git-version-gen: avoid test -z portability glitch
Eric Blake <eblake@redhat.com>
parents:
17245
diff
changeset
|
151 if test "x$v" != x |
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
152 then |
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
153 : # use $v |
13803
112326beb7c3
git-version-gen: do require git-VC'd files in cwd
Jim Meyering <meyering@redhat.com>
parents:
13800
diff
changeset
|
154 # Otherwise, if there is at least one git commit involving the working |
112326beb7c3
git-version-gen: do require git-VC'd files in cwd
Jim Meyering <meyering@redhat.com>
parents:
13800
diff
changeset
|
155 # directory, and "git describe" output looks sensible, use that to |
112326beb7c3
git-version-gen: do require git-VC'd files in cwd
Jim Meyering <meyering@redhat.com>
parents:
13800
diff
changeset
|
156 # derive a version string. |
112326beb7c3
git-version-gen: do require git-VC'd files in cwd
Jim Meyering <meyering@redhat.com>
parents:
13800
diff
changeset
|
157 elif test "`git log -1 --pretty=format:x . 2>&1`" = x \ |
16083
1b52ba2f7e83
git-version-gen: Add --prefix.
Simon Josefsson <simon@josefsson.org>
parents:
16082
diff
changeset
|
158 && v=`git describe --abbrev=4 --match="$prefix*" HEAD 2>/dev/null \ |
14095
a6c3d8a0de24
git-version-gen: convert leading TABs to spaces
Jim Meyering <meyering@redhat.com>
parents:
14094
diff
changeset
|
159 || git describe --abbrev=4 HEAD 2>/dev/null` \ |
13379
d62002e5d9f4
git-version-gen: take a sed script to transform the git tag
Ludovic Courtès <ludo@gnu.org>
parents:
13273
diff
changeset
|
160 && v=`printf '%s\n' "$v" | sed "$tag_sed_script"` \ |
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
161 && case $v in |
16084
8c88dd7eb4fb
Fix for last commit.
Simon Josefsson <simon@josefsson.org>
parents:
16083
diff
changeset
|
162 $prefix[0-9]*) ;; |
14095
a6c3d8a0de24
git-version-gen: convert leading TABs to spaces
Jim Meyering <meyering@redhat.com>
parents:
14094
diff
changeset
|
163 *) (exit 1) ;; |
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
164 esac |
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
165 then |
9719
ec87f62b97b8
Enable use of older two part flavor 'git describe'.
Bob Proulx <bob@proulx.com>
parents:
9677
diff
changeset
|
166 # Is this a new git that lists number of commits since the last |
ec87f62b97b8
Enable use of older two part flavor 'git describe'.
Bob Proulx <bob@proulx.com>
parents:
9677
diff
changeset
|
167 # tag or the previous older version that did not? |
ec87f62b97b8
Enable use of older two part flavor 'git describe'.
Bob Proulx <bob@proulx.com>
parents:
9677
diff
changeset
|
168 # Newer: v6.10-77-g0f8faeb |
ec87f62b97b8
Enable use of older two part flavor 'git describe'.
Bob Proulx <bob@proulx.com>
parents:
9677
diff
changeset
|
169 # Older: v6.10-g0f8faeb |
ec87f62b97b8
Enable use of older two part flavor 'git describe'.
Bob Proulx <bob@proulx.com>
parents:
9677
diff
changeset
|
170 case $v in |
19036
125fe2f313c6
git-version-gen: Fix for tags containing '-'
Markus Armbruster <armbru@pond.sub.org>
parents:
18663
diff
changeset
|
171 *-*-g????) : git describe is okay three part flavor ;; |
125fe2f313c6
git-version-gen: Fix for tags containing '-'
Markus Armbruster <armbru@pond.sub.org>
parents:
18663
diff
changeset
|
172 *-g????) |
14095
a6c3d8a0de24
git-version-gen: convert leading TABs to spaces
Jim Meyering <meyering@redhat.com>
parents:
14094
diff
changeset
|
173 : git describe is older two part flavor |
a6c3d8a0de24
git-version-gen: convert leading TABs to spaces
Jim Meyering <meyering@redhat.com>
parents:
14094
diff
changeset
|
174 # Recreate the number of commits and rewrite such that the |
a6c3d8a0de24
git-version-gen: convert leading TABs to spaces
Jim Meyering <meyering@redhat.com>
parents:
14094
diff
changeset
|
175 # result is the same as if we were using the newer version |
a6c3d8a0de24
git-version-gen: convert leading TABs to spaces
Jim Meyering <meyering@redhat.com>
parents:
14094
diff
changeset
|
176 # of git describe. |
a6c3d8a0de24
git-version-gen: convert leading TABs to spaces
Jim Meyering <meyering@redhat.com>
parents:
14094
diff
changeset
|
177 vtag=`echo "$v" | sed 's/-.*//'` |
a6c3d8a0de24
git-version-gen: convert leading TABs to spaces
Jim Meyering <meyering@redhat.com>
parents:
14094
diff
changeset
|
178 commit_list=`git rev-list "$vtag"..HEAD 2>/dev/null` \ |
a6c3d8a0de24
git-version-gen: convert leading TABs to spaces
Jim Meyering <meyering@redhat.com>
parents:
14094
diff
changeset
|
179 || { commit_list=failed; |
a6c3d8a0de24
git-version-gen: convert leading TABs to spaces
Jim Meyering <meyering@redhat.com>
parents:
14094
diff
changeset
|
180 echo "$0: WARNING: git rev-list failed" 1>&2; } |
a6c3d8a0de24
git-version-gen: convert leading TABs to spaces
Jim Meyering <meyering@redhat.com>
parents:
14094
diff
changeset
|
181 numcommits=`echo "$commit_list" | wc -l` |
a6c3d8a0de24
git-version-gen: convert leading TABs to spaces
Jim Meyering <meyering@redhat.com>
parents:
14094
diff
changeset
|
182 v=`echo "$v" | sed "s/\(.*\)-\(.*\)/\1-$numcommits-\2/"`; |
a6c3d8a0de24
git-version-gen: convert leading TABs to spaces
Jim Meyering <meyering@redhat.com>
parents:
14094
diff
changeset
|
183 test "$commit_list" = failed && v=UNKNOWN |
a6c3d8a0de24
git-version-gen: convert leading TABs to spaces
Jim Meyering <meyering@redhat.com>
parents:
14094
diff
changeset
|
184 ;; |
9719
ec87f62b97b8
Enable use of older two part flavor 'git describe'.
Bob Proulx <bob@proulx.com>
parents:
9677
diff
changeset
|
185 esac |
ec87f62b97b8
Enable use of older two part flavor 'git describe'.
Bob Proulx <bob@proulx.com>
parents:
9677
diff
changeset
|
186 |
9452
595a77da32de
git-version-gen: sync from coreutils.
Jim Meyering <meyering@redhat.com>
parents:
9175
diff
changeset
|
187 # Change the first '-' to a '.', so version-comparing tools work properly. |
9677
54e86898dd7d
* build-aux/git-version-gen: Use "git status", not "git-status".
Jim Meyering <meyering@redhat.com>
parents:
9452
diff
changeset
|
188 # Remove the "g" in git describe's output string, to save a byte. |
9452
595a77da32de
git-version-gen: sync from coreutils.
Jim Meyering <meyering@redhat.com>
parents:
9175
diff
changeset
|
189 v=`echo "$v" | sed 's/-/./;s/\(.*\)-g/\1-/'`; |
14372
b894b1646164
git-version-gen: skip "-dirty" check when appropriate
Jim Meyering <meyering@redhat.com>
parents:
14133
diff
changeset
|
190 v_from_git=1 |
17246
7d2aa4fc02ab
git-version-gen: avoid test -z portability glitch
Eric Blake <eblake@redhat.com>
parents:
17245
diff
changeset
|
191 elif test "x$fallback" = x || git --version >/dev/null 2>&1; then |
17960
1c04e5182252
git-version-gen: revert "detect untagged revisions"
Mats Erik Andersson <mats.andersson@gisladisker.se>
parents:
17958
diff
changeset
|
192 v=UNKNOWN |
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
193 else |
17245
179b150e5256
git-version-gen: add --fallback option to use if git is not present
Peter Rosin <peda@lysator.liu.se>
parents:
16706
diff
changeset
|
194 v=$fallback |
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
195 fi |
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
196 |
17960
1c04e5182252
git-version-gen: revert "detect untagged revisions"
Mats Erik Andersson <mats.andersson@gisladisker.se>
parents:
17958
diff
changeset
|
197 v=`echo "$v" |sed "s/^$prefix//"` |
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
198 |
14372
b894b1646164
git-version-gen: skip "-dirty" check when appropriate
Jim Meyering <meyering@redhat.com>
parents:
14133
diff
changeset
|
199 # Test whether to append the "-dirty" suffix only if the version |
b894b1646164
git-version-gen: skip "-dirty" check when appropriate
Jim Meyering <meyering@redhat.com>
parents:
14133
diff
changeset
|
200 # string we're using came from git. I.e., skip the test if it's "UNKNOWN" |
b894b1646164
git-version-gen: skip "-dirty" check when appropriate
Jim Meyering <meyering@redhat.com>
parents:
14133
diff
changeset
|
201 # or if it came from .tarball-version. |
17246
7d2aa4fc02ab
git-version-gen: avoid test -z portability glitch
Eric Blake <eblake@redhat.com>
parents:
17245
diff
changeset
|
202 if test "x$v_from_git" != x; then |
18663
caf9d6314c8f
maint: time stamp -> timestamp
Paul Eggert <eggert@cs.ucla.edu>
parents:
18626
diff
changeset
|
203 # Don't declare a version "dirty" merely because a timestamp has changed. |
14372
b894b1646164
git-version-gen: skip "-dirty" check when appropriate
Jim Meyering <meyering@redhat.com>
parents:
14133
diff
changeset
|
204 git update-index --refresh > /dev/null 2>&1 |
9452
595a77da32de
git-version-gen: sync from coreutils.
Jim Meyering <meyering@redhat.com>
parents:
9175
diff
changeset
|
205 |
14372
b894b1646164
git-version-gen: skip "-dirty" check when appropriate
Jim Meyering <meyering@redhat.com>
parents:
14133
diff
changeset
|
206 dirty=`exec 2>/dev/null;git diff-index --name-only HEAD` || dirty= |
b894b1646164
git-version-gen: skip "-dirty" check when appropriate
Jim Meyering <meyering@redhat.com>
parents:
14133
diff
changeset
|
207 case "$dirty" in |
b894b1646164
git-version-gen: skip "-dirty" check when appropriate
Jim Meyering <meyering@redhat.com>
parents:
14133
diff
changeset
|
208 '') ;; |
b894b1646164
git-version-gen: skip "-dirty" check when appropriate
Jim Meyering <meyering@redhat.com>
parents:
14133
diff
changeset
|
209 *) # Append the suffix only if there isn't one already. |
b894b1646164
git-version-gen: skip "-dirty" check when appropriate
Jim Meyering <meyering@redhat.com>
parents:
14133
diff
changeset
|
210 case $v in |
b894b1646164
git-version-gen: skip "-dirty" check when appropriate
Jim Meyering <meyering@redhat.com>
parents:
14133
diff
changeset
|
211 *-dirty) ;; |
b894b1646164
git-version-gen: skip "-dirty" check when appropriate
Jim Meyering <meyering@redhat.com>
parents:
14133
diff
changeset
|
212 *) v="$v-dirty" ;; |
b894b1646164
git-version-gen: skip "-dirty" check when appropriate
Jim Meyering <meyering@redhat.com>
parents:
14133
diff
changeset
|
213 esac ;; |
b894b1646164
git-version-gen: skip "-dirty" check when appropriate
Jim Meyering <meyering@redhat.com>
parents:
14133
diff
changeset
|
214 esac |
b894b1646164
git-version-gen: skip "-dirty" check when appropriate
Jim Meyering <meyering@redhat.com>
parents:
14133
diff
changeset
|
215 fi |
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
216 |
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
217 # Omit the trailing newline, so that m4_esyscmd can use the result directly. |
17813
11bf208f2615
git-version-gen: do not print new line characters
KO Myung-Hun <komh78@gmail.com>
parents:
17711
diff
changeset
|
218 printf %s "$v" |
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
219 |
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
220 # Local variables: |
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
221 # eval: (add-hook 'write-file-hooks 'time-stamp) |
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
222 # time-stamp-start: "scriptversion=" |
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
223 # time-stamp-format: "%:y-%02m-%02d.%02H" |
18195
6ee445128d2a
Port Universal Time settings to strict POSIX
Paul Eggert <eggert@cs.ucla.edu>
parents:
18189
diff
changeset
|
224 # time-stamp-time-zone: "UTC0" |
12902
74f6f4021fe0
bootstrap, git-version-gen: use timestamp
Eric Blake <eblake@redhat.com>
parents:
12825
diff
changeset
|
225 # time-stamp-end: "; # UTC" |
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
226 # End: |