How to identify the source's revision?

Marcin Kasperski Marcin.Kasperski at softax.com.pl
Tue Jul 8 16:53:14 UTC 2008


""Daniel(原志)"" <dlin.tw at gmail.com> writes:

> Case 1: Executable file need to identify which revision
> I build an executable file from my source which is version controlled by hg.
> I release the executable file, and some one told me there exist a bug.
> Unfortunely, I forgot which revision I release.

You were already suggested to embed version info extraction into the
build process. Not to mention, "hg tag" would make sense when you
release something.

But ... let me also mention simple trick I use to have a file with a
current version info always present in my working directory (my use
case is that I manage scripting code, and sometimes run straight out
of mercurial clone, so I do not have any build process as such):

a) in .hg/hgrc

  [hooks]
  update.version = `hg root`/.hg/update_version_info.sh $HG_PARENT1 $HG_PARENT2
  commit.version = `hg root`/.hg/update_version_info.sh $HG_NODE

b) in .hg/update_version_info.sh

  #!/bin/bash
  if [ -n "$2" ]
  then
    echo "Merge - skipping VersionInfo.py rebuild"
    exit 0
  fi

  echo "Rebuilding VersionInfo.py (rev $1)"
  hg log -r $1 --template "# File generated by update_version_info.sh\nREVISION='{node|short}'\nDATE='{date|shortdate}'\n" > `hg root`/VersionInfo.py


(my script generates VersionInfo.py in the root project directory,
patching it to generate something differently named or of different
syntax should not be difficult)


-- 
----------------------------------------------------------------------
| Marcin Kasperski   |  For waterfall, milestones are commitments.
| http://mekk.waw.pl | For iterative development, they are decision
|                    |               points. (Martin)
----------------------------------------------------------------------




More information about the Mercurial mailing list