RobertLuptonTheGood/eups — pull request #10 by mjuric (2014-03-11 02:42:32+00:00)
Title: Adjust auto-version computation

(note: will be asking Paul Price for a review)

This patch set changes (simplifies) the ways versions are auto-computed by 'pkgautoversion' (an utility living in $EUPS_DIR/bin) for a git-managed package. The basic logic is now:

```
usage()
{
cat 1>&2 <<-EOF
$(basename $0): construct a version string using git

usage: $(basename $0) [--dirty] [ref=HEAD] [tag_pattern='[0-9]*']

Applies the following logic:
* If ref is a tag, returns the ref
* Otherwise, return an annotated tag attached to ref
* Otherwise, returns [branch-g][-dirty]

If multiple tags are elegible to describe the ref, uses the
one that's the lowest when compared per-component (i.e.,
given tags "1.2.3", "1.2.4", and "1.12" it will use 1.2.3).

If --dirty is given, ref must be empty or HEAD.
EOF
}
```

which implements the first part of the proposal described at: https://jira.lsstcorp.org/browse/DM-75 (the https://jira.lsstcorp.org/browse/DM-76 subtask). The key point is that thusly generated versions are all directly resolvable to SHAs with:

```
git rev-parse
```

The output of the unit tests is as follows:

```
[mjuric@lsst-dev [eupspkg] /ssd/mjuric/eupspkg/sources/eups]$ RUN_UNIT=1 pkgautoversion -h
======== unit tests for _earliest_version() ========
$(_earliest_version 1.1 1.1.0) == '1.1': ok.
$(_earliest_version 1.1.0 1.1.0) == '1.1.0': ok.
$(_earliest_version 1.2.3 1.2.2) == '1.2.2': ok.
$(_earliest_version 1.2.2 1.2.3) == '1.2.2': ok.
$(_earliest_version 1.2 1.2.3) == '1.2': ok.
$(_earliest_version 1.2.2 1.2.3 1.3) == '1.2.2': ok.
$(_earliest_version 1.2 1.2a) == '1.2': ok.
$(_earliest_version 1.2.1 1.2a.2) == '1.2.1': ok.
$(_earliest_version 1.2a.2 1.2a.1) == '1.2a.1': ok.
$(_earliest_version 1.2a.2 1.2b.1) == '1.2a.2': ok.

======== unit tests for git_version in /tmp/unittest.WYpoE ========
Version w/o no tag : $(git_version --dirty) == 'master-g49999ed903': ok.
Version on dirty commit : $(git_version --dirty) == 'master-g49999ed903-dirty': ok.
Version for commit on branch : $(git_version --dirty) == 'next-g19ba9b2db6': ok.
Version for commit on two branches : $(git_version --dirty) == 'master-g49999ed903': ok.
Version for commit on branch (2) : $(git_version --dirty) == 'next2-ge234a0c0cf': ok.
Branch name with reserved characters : $(git_version --dirty) == 'a.b.c.d-g8d68ef8244': ok.
Prefer branch with closest tip : $(git_version --dirty) == 'next-g19ba9b2db6': ok.
Version on dirty commit : $(git_version --dirty) == 'next-g19ba9b2db6-dirty': ok.
Ver from branch name : $(git_version next) == 'next-g19ba9b2db6': ok.
Ver from SHA1, non-tip : $(git_version 7280d0c84b) == 'master-g7280d0c84b': ok.
Ver from SHA1, tip : $(git_version 8d68ef8244) == 'a.b.c.d-g8d68ef8244': ok.
Ver from SHA1 on merge pt (HEAD is next2) : $(git_version b8345f460a) == 'next2-gb8345f460a': ok.
Ver from SHA1 on merge pt (HEAD is a/b/c/d) : $(git_version b8345f460a) == 'a.b.c.d-gb8345f460a': ok.
Ver from name on merge pt (HEAD is a/b/c/d) : $(git_version next2) == 'next2-gb8345f460a': ok.
Single non-annotated tag on HEAD : $(git_version --dirty) == 'master-g49999ed903': ok.
Annotated and non-annotated tags on HEAD : $(git_version --dirty) == '2.0': ok.
Added lower version tag on the same commit : $(git_version --dirty) == '1.1': ok.
Added higher version tag on the same commit : $(git_version --dirty) == '1.1': ok.
Requesting version for tag returns tag : $(git_version 2.1) == '2.1': ok.
Dirty commit on the tag : $(git_version --dirty) == '1.1-dirty': ok.
Commit away from the tag : $(git_version --dirty) == 'master-gb0a4e1ba30': ok.
Commit away from the tag : $(git_version --dirty) == 'master-g9eed521384': ok.
Dirty commit away from the tag : $(git_version --dirty) == 'master-g9eed521384-dirty': ok.
Tag on a side-branch : $(git_version --dirty) == '3.0': ok.
Version of orphaned commit : $(git_version acf63ba868) == 'acf63ba868': ok.
Where --first-parent makes a difference : $(git_version --dirty) == 'master-g64eb751c60': ok.

all unit tests passed.
```

The diff below is a little hard to follow -- it's better to just look at the code in the file (the git_version() subroutine).