Differences between revisions 1 and 51 (spanning 50 versions)
Revision 1 as of 2007-01-17 20:41:39
Size: 1330
Comment: Add keyword expansion page
Revision 51 as of 2024-03-06 12:11:11
Size: 4619
Comment: way backwards compatible repo not hosted anymore
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
== Keyword Expansion extension ==
'''This extension is not being distributed along with Mercurial.'''
#format wiki
#language en
## page was renamed from KeywordExpansionExtension
== Keyword Extension ==
<!> This is considered a [[FeaturesOfLastResort|feature of last resort]].
Line 4: Line 7:
It's being developed by Christian Ebert and can be downloaded from its [http://www.blacktrash.org/cgi-bin/hgwebdir.cgi/hgkeyword/ keyword expansion repository]. '''This extension is distributed with Mercurial.'''

''Author: [[ChristianEbert|Christian Ebert]]''
Line 7: Line 12:
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".
Line 8: Line 14:
This extension allows the expansion of RCS/CVS-like and user defined keys in Mercurial repositories. Keywords expand to the changeset data pertaining to the latest change relative to the working directory parent of each file.

<!> 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: VersioningWithMake.
Line 15: Line 28:
hgext.keyword = path/to/keyword.py
#or, if keyword.py is in the hgext folder:
#hgext.keyword=
keyword=
#or, if keyword.py is not in the hgext folder:
#keyword=/path/to/keyword.py
Line 19: Line 32:
Additional configuration is done in the [keyword] and [keywordmaps] sections in your configuration file:
Line 20: Line 34:
Additional configuration is dones in they [keyword] and [keywordmaps] sections in your configuration file:
Line 23: Line 36:
# files matching patterns with value 'ignore' are ignored
Line 25: Line 37:
# expand keywords in all python files in working dir
Line 26: Line 39:
# do not expand keywords in files matching "x*" in working dir
Line 28: Line 42:
# in case you prefer your own keyword maps over the cvs-like defaults:
#
using {{{key-to-be-expanded = value}}} lines, where values are taken from the avaliable Mercurial template names.
# override the cvs-like default mappings with customized keyword = expansion pairs,
#
where expansion values contain Mercurial templates and filters
Line 32: Line 46:
lastlog = {desc} ## same as {desc|firstline} in this context lastlog = {desc}
Line 35: Line 49:
<!> 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.
Line 37: Line 52:
The defined keys (or default ones) are automatically expanded, without user interaction. 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"<<FootNote({{{RCSFile}}} is incorrect, but kept for backwards compatibility with previous versions of the extension.)>>:

{{{
        configuration using default keyword template maps
[extensions]
keyword =
[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.

==== Features request ====
 * Custom template filters for keyword expansion... I would like to allow $License$ style expansion to add automatic formatted license preamble to sources files managed by Mercurial and this seems like the perfect extension for this purpose. -- EtienneRobillard <<DateTime(2011-04-27T12:54:31Z)>>

----
CategoryBundledExtension

Keyword Extension

<!> This is considered a feature of last resort.

This extension is distributed with Mercurial.

Author: Christian Ebert

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".

Keywords expand to the changeset data pertaining to the latest change relative to the working directory parent of each file.

<!> 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: VersioningWithMake.

Configuration

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.

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"1:

        configuration using default keyword template maps
[extensions]
keyword =
[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.

Features request

  • Custom template filters for keyword expansion... I would like to allow $License$ style expansion to add automatic formatted license preamble to sources files managed by Mercurial and this seems like the perfect extension for this purpose. -- EtienneRobillard 2011-04-27 12:54:31


CategoryBundledExtension

  1. RCSFile is incorrect, but kept for backwards compatibility with previous versions of the extension. (1)

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