[PATCH 2 of 8] convert: add the "preprocess" directive to --filemap
Patrick Mézard
pmezard at gmail.com
Tue Nov 29 10:59:35 CST 2011
Le 28/11/11 07:25, Yury Sulsky a écrit :
> # HG changeset patch
> # User Yury Sulsky <yury.sulsky at gmail.com>
> # Date 1322458620 18000
> # Node ID a193b88653a7483488a781b5d34dc9482330452b
> # Parent 3e13ade423f08031045c2d5a2ef2a87a863a2614
> convert: add the "preprocess" directive to --filemap
What about "edit"?
Again, we should have a base version of this for python hooks, editing commit objects, then an implementation as an external command. But it can be done later.
> diff -r 3e13ade423f0 -r a193b88653a7 hgext/convert/__init__.py
> --- a/hgext/convert/__init__.py Mon Nov 21 01:49:20 2011 +0100
> +++ b/hgext/convert/__init__.py Mon Nov 28 00:37:00 2011 -0500
> @@ -89,6 +89,8 @@
>
> rename path/to/source path/to/destination
>
> + preprocess path/to/file-or-dir "preprocess-command"
> +
> Comment lines start with ``#``. A specified path matches if it
> equals the full relative name of a file or one of its parent
> directories. The ``include`` or ``exclude`` directive with the
> @@ -102,6 +104,14 @@
> it is converted. To rename from a subdirectory into the root of
> the repository, use ``.`` as the path to rename to.
>
> + The ``preprocess`` directive replaces the contents of specified
> + files with the output from an external command. This allows you to
> + e.g. insert a copyright statement at the beginning of every
> + document or to strip out sensitive data from a repository. The
> + command is invoked with the FNAME environment variable set to the
HG_FNAME really. What about HG_PATH?
I am tempted to pass the HG_SOURCEREV as well.
> + (possibly renamed) file name and the contents of the file piped
> + into its standard input.
> +
> The splicemap is a file that allows insertion of synthetic
> history, letting you specify the parents of a revision. This is
> useful if you want to e.g. give a Subversion merge two parents, or
> diff -r 3e13ade423f0 -r a193b88653a7 hgext/convert/filemap.py
> --- a/hgext/convert/filemap.py Mon Nov 21 01:49:20 2011 +0100
> +++ b/hgext/convert/filemap.py Mon Nov 28 00:37:00 2011 -0500
> @@ -26,6 +26,7 @@
> self.include = {}
> self.exclude = {}
> self.rename = {}
> + self.preprocess = {}
> if path:
> if self.parse(path):
> raise util.Abort(_('errors in filemap'))
> @@ -68,6 +69,11 @@
> self.rename[src] = dest
> elif cmd == 'source':
> errs += self.parse(lex.get_token())
> + elif cmd == 'preprocess':
> + name = lex.get_token()
> + prog = lex.get_token()
> + errs += check(name, self.exclude, 'exclude')
If you check "exclude" why not check "rename"?
> + self.preprocess[name] = prog
> else:
> self.ui.warn(_('%s:%d: unknown directive %r\n') %
> (lex.infile, lex.lineno, cmd))
> @@ -108,6 +114,9 @@
> def active(self):
> return bool(self.include or self.exclude or self.rename)
>
> + def preprocessor(self, name):
> + return self.lookup(name, self.preprocess)[0] or None
> +
> # This class does two additional things compared to a regular source:
> #
> # - Filter and rename files. This is mostly wrapped by the filemapper
> @@ -367,7 +376,12 @@
>
> def getfile(self, name, rev):
> realname, realrev = rev
> - return self.base.getfile(realname, realrev)
> + data, mode = self.base.getfile(realname, realrev)
> + preprocess = self.filemapper.preprocessor(realname)
> + if preprocess is not None:
> + env = {'HG_FNAME': name}
> + data = util.pipefilter(data, preprocess, env=env)
> + return data, mode
>
> def gettags(self):
> return self.base.gettags()
[...]
--
Patrick Mézard
More information about the Mercurial-devel
mailing list