chris yo
chris yo

Reputation: 1277

Hg Mercurial's Revision History logs in source code

I have just migrated my source codes from SVN to HG Mercurial.

With SVN, it is possible to add the commit message in your source codes if you put certain keywords as a comment. Usually, this is added at the top or bottom of the source codes. Example: /* * Revisions: $Revision$ */

What is the HG equivalent of such feature?

I would prefer to have the revision history inside the files, instead of having to go to Hg to view the history. Is this possible?

Upvotes: 2

Views: 144

Answers (1)

Lasse V. Karlsen
Lasse V. Karlsen

Reputation: 391276

To answer your question:

You can use the KeywordExtension extension. It allows you to use CVS-like keyword expansion in files.


Advice: Don't do it.

It makes merging a headache, and in Mercurial you're (probably) going to merge all the time.

Additionally, the keyword for the history will expand to a linear history dump, whereas your real Mercurial history is not linear, it's parallel, which makes the history dump in the file misleading. It can lead to a history that apparently fixed a bug before the feature it is in was implemented.

So again, I would advise against using that extension.

As an example of the kind of headache you're going to get, you're going to have an area that will be in conflict in every merge and that needs manual resolution in every file.

However, if you still want to enable it, the page above has the following details:


To enable this extension add it to the '[extensions]' stanza in the hgrc file:

[extensions]
keyword=
#or, if keyword.py is not in the hgext folder:
#keyword=/path/to/keyword.py

Additional configuration is done in the [keyword] and [keywordmaps] sections in your configuration file:

# filename patterns for expansion are configured in this section
[keyword]
# expand keywords in all python files in working dir
**.py =
# do not expand keywords in files matching "x*" in working dir
x* = ignore
...
# override the cvs-like default mappings with customized keyword = expansion pairs,
# where expansion values contain Mercurial templates and filters
[keywordmaps]
HGdate = {date|rfc822date}
lastlog = {desc}
checked in by = {author}
  • For speed and security reasons (avoidance of inadvertently expanded keywords) it is recommended to enable the extension per repo only in repo/.hg/hgrc, not globally, and to fine tune the [keyword] filename patterns with great care.

(the above was copied from KeywordExtension documentation.

Upvotes: 4

Related Questions