How to identify the source's revision?

Matt Mackall mpm at selenic.com
Fri Jun 27 10:52:36 CDT 2008


On Fri, 2008-06-27 at 19:12 +0800, Daniel(原志) wrote:
> 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.
> 
> Is there any method to identify what is the executable file's version?
> 
> As I think the only method is:
> 
> for every revision in that subdirectory:
>      hg up -C <rev> 
>      make
>      # compare the executable file to the just build executable file.

If your project has a build process, then the usual thing is to have the
build process ask hg what the version is and incorporate that into the
build. If you have a Makefile, that's something like:

version.o:
	cc -DVERSION="`hg id`" version.c -o version.o

This is overwhelmingly the most common use of tags and it's trivially
replaced.

> Case 2: source code files need to identify which revision.
> I release an archive of source code without revision information(eg.
> $Id$).
> I need to identify which revision.
> 
> As I think the method is:
> 
> for every revision in that subdirectory:
>       hg up -C <rev>
>       compare all files with the target source code.

hg archive bundles a file containing the version in the archive by
default.

> Is there possible provide some simple command of hg to do such thing?
> Or, the command already exist?

There's no good shortcut for "compare a given file with all revisions of
a file", no. That would make for a clever little extension.

In the open source world, it's quite common for one project to copy
modules from another project. And then to substantially change those
modules, even while occassionally copying new changes from the original.
The $Id$ may or may not get updated, deleted, or replaced by a revision
number from other projects, etc. Thus, a file's $Id$ tag is probably
wrong unless the file is actually in its original repo, at which point
it's redundant. If it's outside the repo, it's by definition no longer a
controlled document.

ps: If the lack of $Id$ tags discourages people from printing, all the
better!
-- 
Mathematics is the supreme nostalgia of our time.



More information about the Mercurial mailing list