Andy Wingo wrote: > On Fri 06 Jul 2012 17:45, Jim Meyering <j...@meyering.net> writes: > >> How about writing a function -- with description similar to the comments >> you've added below -- and doing something like the following? >> Then we should be able to avoid that duplication. >> >> elif test "`git log -1 --pretty=format:x . 2>&1`" = x \ >> - && v=`git describe --abbrev=4 --match="$prefix*" HEAD 2>/dev/null \ >> - || git describe --abbrev=4 HEAD 2>/dev/null` \ >> + && v=`git_desc "$prefix" "$match"` \ >> ... > > Good suggestion. Attached. ... > Subject: [PATCH] git-version-gen: add --match argument. > > * build-aux/git-version-gen (Options): Add --match argument. > (match): > (tag_sed_script): > (tarball_version_file): Protect against ambient values of these > variables. > (git_describe, massage_git_version): New helper functions. Require a > match in the --match case, and otherwise have our previous behavior. > > Using --match can prevent a merge from e.g. a version 2 branch to a 3 > branch from causing the 3 branch to show a 2 version, if the 2 version > tagged more recently than the 3 version.
Thanks. We're almost there. ... > - --prefix prefix of git tags (default 'v') > + --prefix prefix of git tags to strip from version (default 'v') > + --match pattern for git tags to match Please mention that it's a "glob" pattern, so people don't think it's a regexp. > - --help display this help and exit > - --version output version information and exit > + --help display this help and exit > + --version output version information and exit > ... > +function massage_git_version() { > + local v=$1 Using the "function" and "local" keywords would make this script fail for some older shells. I'd like to remain portable to those. > # Is this a new git that lists number of commits since the last > # tag or the previous older version that did not? > # Newer: v6.10-77-g0f8faeb > @@ -182,7 +176,44 @@ then > > # Change the first '-' to a '.', so version-comparing tools work > properly. > # Remove the "g" in git describe's output string, to save a byte. > - v=`echo "$v" | sed 's/-/./;s/\(.*\)-g/\1-/'`; > + echo "$v" | sed 's/-/./;s/\(.*\)-g/\1-/' > +} > + > +function git_describe() { > + local prefix=$1 > + local match=$2 > + local v ... Oh, and your patch added at least one trailing blank.