On 8/4/07, Andreas Fuchs <asf@...> wrote:
> I absolutely agree with you about the niceness of numeric ordering of
> commits. It seems that so do the git gods:
> $ cd ~/dl/git/sbcl/
> $ tail -1 version.lisp-expr
> $ git describe
> The format is <last tag>-<commits since last tag>-<unique substring of
> commit hash>. I think that's pretty neat (-:
What follows is a make-version.sh script, which generates a version number
using the following rules:
0. If there is no .git, there must be a version.txt file -- from
a release tarball.
1. Get last tag, number of commits after it, and a short SHA1
2. The tag name must start with sbcl.<number> or <number>.
3. If the commit the tag refers to is the current HEAD (no
commits after the tag), then the name of the tag is all
Otherwise, if we have a command-line argument, use it as
a descriptive suffix.
Otherwise, use the current branch name as a descriptive
suffix -- unless there is no branch, or if the branch
is "master", in which case us the "anon" suffix.
4. If there are uncommitted changes in the tree, add "dirty"
For the branch I'm currently sitting on this results in
-- 1.0.8 + 33 commits, SHA1 prefix 4f54, branch name is "pending",
no uncommitted changes in tree.
I think "interim" versions like this (esp. in distributed world
where there are many possible 1.0.8 + 33 commits versions) are
always at best descriptive. The SHA1 prefix gives a good shot
at making sure you have the exact same version, but the suffix
is probably more useful for human consumption.
When using something like Git, I think adding
is perfectly sane -- but it's not going to be usefull
all that often at the end, I think.
if test -d .git
# Get base tag, count of commits after it, and a SHA1 prefix
base=$(git describe --abbrev=4 | sed -E "s/^sbcl\.//")
case "$base" in
# tag.n_commits, not tag-n_commits
base=$(echo $base | sed -E "s/-([0-9]+-g)/.\1/")
echo "Bad base tag from git-describe: $base"
echo "(wanted something starting with [0-9], or sbcl.[0-9])"
# If the tag matches the HEAD, it should be all the information we
# need. Otherwise add a descriptive suffix: either the
# command-line -<argument>, or -<branch-name>, or -anon if the branch
# name is uninformative.
tag_commit=$(git cat-file -p $tag | head -n1 | cut -d' ' -f2)
commit=$(git rev-list --max-count=1 HEAD)
if test "$tag_commit" = "$commit"
if ! test -z "$1"
branch=$(git branch | grep "^\*" | cut -c3-)
case "$branch" in
# Is the tree dirty (uncommitted changes)?
if test -z "$(git diff-index --name-only HEAD)"
if test -f version.txt
# No .git, so this must be a release tarball of some sort, which
# should have the version in version.txt
echo "No .git, no version.txt -- could not figure out the version."