Differences between revisions 37 and 38
Revision 37 as of 2009-10-24 11:17:01
Size: 4193
Comment: update kwdemo output according to current version
Revision 38 as of 2009-11-29 11:12:23
Size: 4246
Comment: update kwdemo output
Deletions are marked like this. Additions are marked like this.
Line 78: Line 78:
Author = {author|user}
Date = {date|utcdate}
Header = {root}/{file},v {node|short} {date|utcdate} {author|user}
Id = {file|basename},v {node|short} {date|utcdate} {author|user}
Line 79: Line 83:
Author = {author|user}
Header = {root}/{file},v {node|short} {date|utcdate} {author|user}
RCSfile = {file|basename},v
Revision = {node|short}
Line 82: Line 86:
Date = {date|utcdate}
Id = {file|basename},v {node|short} {date|utcdate} {author|user}
Revision = {node|short}
Line 87: Line 88:
$Author: blacktrash $
$Date: 2007/07/17 12:00:47 $
$Header: /tmp/kwdemo.Oz46E2/demo.txt,v 2ad3dcb8d811 2007/07/17 12:00:47 blacktrash $
$Id: demo.txt,v 2ad3dcb8d811 2007/07/17 12:00:47 blacktrash $
Line 88: Line 93:
$Author: blacktrash $
$Header: /tmp/kwdemo.Oz46E2/demo.txt,v 2ad3dcb8d811 2007/07/17 12:00:47 blacktrash $
$RCSfile: demo.txt,v $
$Revision: 2ad3dcb8d811 $
Line 91: Line 96:
$Date: 2007/07/17 12:00:47 $
$Id: demo.txt,v 2ad3dcb8d811 2007/07/17 12:00:47 blacktrash $
$Revision: 2ad3dcb8d811 $

Keyword Extension

This extension is distributed with Mercurial.

Author: Christian Ebert

Download site: keyword extension repository including backwards compatible branch for use with Mercurial 0.9.2 to 1.0.2.

Overview

This extension allows the expansion of RCS/CVS-like and user defined keys in text files tracked by Mercurial. Expansion takes place in the working directory or/and when creating a distribution using "hg archive".

<!> If you just want to version your entire repo, do not use this extension but let your build system take care of it. Something along the lines of

hg -q id > version

before distribution might be well enough if file-wise keyword expansion in the source is not absolutely required. See also: Why You Don't Need It.

Configuration

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

[extensions]
hgext.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.

Usage

The main functionality of the extension is done in background by automatically expanding the defined keys (or default ones), without user interaction. An additional template filter "utcdate" is provided to get %Y/%m/%d %H:%M:%S date format.

Before expansion keywords should appear in the source files delimited by $ signs:

This is a $Keyword$ awaiting expansion.

As keywords are freely configurable, take care that they differ from potential $-delimited patterns in the actual source to avoid accidental expansion.

The extension provides the following convenience commands:

kwdemo, kwfiles

To get an idea what the extension actually does and/or to test your customizations (templates are rather sparsely documented), run "hg kwdemo".

Example output of "hg kwdemo --default":

        configuration using default keyword template maps
[keyword]
demo.txt =
[keywordmaps]
Author = {author|user}
Date = {date|utcdate}
Header = {root}/{file},v {node|short} {date|utcdate} {author|user}
Id = {file|basename},v {node|short} {date|utcdate} {author|user}
RCSFile = {file|basename},v
RCSfile = {file|basename},v
Revision = {node|short}
Source = {root}/{file},v

        keywords expanded
$Author: blacktrash $
$Date: 2007/07/17 12:00:47 $
$Header: /tmp/kwdemo.Oz46E2/demo.txt,v 2ad3dcb8d811 2007/07/17 12:00:47 blacktrash $
$Id: demo.txt,v 2ad3dcb8d811 2007/07/17 12:00:47 blacktrash $
$RCSFile: demo.txt,v $
$RCSfile: demo.txt,v $
$Revision: 2ad3dcb8d811 $
$Source: /tmp/kwdemo.Oz46E2/demo.txt,v $

To crosscheck which files in your working directory are matched by the current [keyword] patterns, use "hg kwfiles".

kwshrink, kwexpand

Run "hg kwshrink" before changing or disabling currently active keywords.

<!> Do not forget to "hg kwshrink" in the above cases! Otherwise the currently expanded keywords become part of change history.

Run "hg kwexpand" to force expansion in the working directory after enabling it, or after a keyword configuration change.


CategoryExtension

KeywordExtension (last edited 2024-03-06 12:11:11 by ChristianEbert)