[PATCH 4 of 5] convert: tests, coding style
Yury Sulsky
yury.sulsky at gmail.com
Sat Nov 26 21:26:49 UTC 2011
# HG changeset patch
# User Yury Sulsky <yury.sulsky at gmail.com>
# Date 1322302263 18000
# Branch stable
# Node ID 74583e9f7f75bfa7b1a3c46ed3f81454e509a731
# Parent 2df534369f9638116ceb745155096b2dfe9c2cb2
convert: tests, coding style
diff -r 2df534369f96 -r 74583e9f7f75 hgext/convert/__init__.py
--- a/hgext/convert/__init__.py Sat Nov 26 01:35:38 2011 -0500
+++ b/hgext/convert/__init__.py Sat Nov 26 05:11:03 2011 -0500
@@ -108,9 +108,9 @@
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 (possibly renamed) file name as a
- command-line argument and the contents of the file piped into its
- standard input.
+ command is invoked with the FNAME environment variable set to the
+ (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
@@ -148,7 +148,7 @@
The includerevs and excluderevs options allow you to choose which
revisions you would like to appear in the converted repository.
The arguments to these commands are files with a revision from the
- source repository on each line. Note that these directives are
+ source repository on each line. Note that these directives are
only advisory, and in certain situations (i.e. merge nodes and
branch endings) the revisions will be converted regardless.
diff -r 2df534369f96 -r 74583e9f7f75 hgext/convert/filtermap.py
--- a/hgext/convert/filtermap.py Sat Nov 26 01:35:38 2011 -0500
+++ b/hgext/convert/filtermap.py Sat Nov 26 05:11:03 2011 -0500
@@ -257,28 +257,42 @@
class filtermap_source(filtermap_base):
def __init__(self, ui, base, inrevs = None, outrevs = None, filemap = None):
super(filtermap_source, self).__init__(ui, base)
- self.inrevs = self.read_revset(inrevs) if inrevs else None
- self.outrevs = self.read_revset(outrevs) if outrevs else None
- self.filemapper = filemapper(ui, filemap) if filemap else None
-
- def read_revset(self, fname):
+ if inrevs:
+ self.inrevs = self.parserevset(inrevs)
+ else:
+ self.inrevs = None
+
+ if outrevs:
+ self.outrevs = self.parserevset(outrevs)
+ else:
+ self.outrevs = None
+
+ if filemap is not None:
+ self.filemapper = filemapper(ui, filemap)
+ else:
+ self.filemapper = None
+
+ def parserevset(self, fname):
def parse(line):
line = line.strip()
ret = self.base.lookuprev(line)
if ret is None:
self.ui.warn(_("Can't find revision %s." % line))
return ret
- with open(fname, 'r') as fp:
+ fp = open(fname, 'r')
+ try:
return set([parse(line) for line in fp])
-
- def want_rev(self, rev):
+ finally:
+ fp.close()
+
+ def wantrev(self, rev):
if self.inrevs is not None and rev not in self.inrevs:
return False
if self.outrevs is not None and rev in self.outrevs:
return False
return True
- def want_files(self, rev, i):
+ def wantfiles(self, rev, i):
if self.filemapper is None:
return True
try:
@@ -291,9 +305,9 @@
return False
def wanted(self, rev, i):
- return self.want_rev(rev) and self.want_files(rev, i)
-
- def filemap_changes(self, changes):
+ return self.wantrev(rev) and self.wantfiles(rev, i)
+
+ def filemapchanges(self, changes):
if self.filemapper is None:
return changes
@@ -323,18 +337,15 @@
changes = super(filtermap_source, self).getchanges(rev)
if isinstance(changes, basestring):
return changes
- return self.filemap_changes(changes)
+ return self.filemapchanges(changes)
def getfile(self, name, rev):
- source_name = name
+ sourcename = name
if self.filemapper is not None:
- source_name, rev = rev
- file = super(filtermap_source, self).getfile(source_name, rev)
- preprocess = self.filemapper.preprocessor(source_name)
+ sourcename, rev = rev
+ data, mode = super(filtermap_source, self).getfile(sourcename, rev)
+ preprocess = self.filemapper.preprocessor(sourcename)
if preprocess is not None:
- cmd = preprocess + ' ' + util.shellquote(name)
- data, mode = file
- data = util.pipefilter(data, cmd)
- file = data, mode
- return file
-
+ data = util.pipefilter(data, preprocess, env={'FNAME': name})
+ return data, mode
+
diff -r 2df534369f96 -r 74583e9f7f75 mercurial/util.py
--- a/mercurial/util.py Sat Nov 26 01:35:38 2011 -0500
+++ b/mercurial/util.py Sat Nov 26 05:11:03 2011 -0500
@@ -237,9 +237,9 @@
setattr(obj, self.name, result)
return result
-def pipefilter(s, cmd):
+def pipefilter(s, cmd, env=None):
'''filter string S through command CMD, returning its output'''
- p = subprocess.Popen(cmd, shell=True, close_fds=closefds,
+ p = subprocess.Popen(cmd, shell=True, close_fds=closefds, env=env,
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
pout, perr = p.communicate(s)
return pout
diff -r 2df534369f96 -r 74583e9f7f75 tests/test-convert-filemap.t
--- a/tests/test-convert-filemap.t Sat Nov 26 01:35:38 2011 -0500
+++ b/tests/test-convert-filemap.t Sat Nov 26 05:11:03 2011 -0500
@@ -232,36 +232,38 @@
> rename dir dir2
> include foo
> include copied
+ > preprocess copied "sh -c 'echo == \$FNAME ==; sed -e s/foo/goo/'"
> rename foo foo2
> rename copied copied2
> exclude dir/subdir
> include dir/subdir/file3
> EOF
+ $ cat > excludes <<EOF
+ > 2
+ > EOF
$ rm source/.hg/store/data/dir/file3.i
$ rm source/.hg/store/data/dir/file4.i
$ hg -q convert --filemap renames.fmap --datesort source dummydest
abort: data/dir/file3.i at e96dce0bc6a2: no match found!
[255]
- $ hg -q convert --filemap renames.fmap --datesort --config convert.hg.ignoreerrors=1 source renames.repo
+ $ hg -q convert --filemap renames.fmap --datesort --excluderevs excludes --config convert.hg.ignoreerrors=1 source renames.repo
ignoring: data/dir/file3.i at e96dce0bc6a2: no match found
ignoring: data/dir/file4.i at 6edd55f559cd: no match found
$ hg up -q -R renames.repo
$ glog -R renames.repo
- @ 4 "8: change foo" files: foo2
- |
- o 3 "6: change foo baz" files: foo2
- |
- o 2 "2: change foo" files: foo2
+ @ 3 "8: change foo" files: foo2
+ |
+ o 2 "6: change foo baz" files: foo2
|
o 1 "1: add bar quux; copy foo to copied" files: copied2
|
o 0 "0: add foo baz dir/" files: dir2/file dir2/subdir/file3 foo2
$ hg -R renames.repo manifest --debug
- d43feacba7a4f1f2080dde4a4b985bd8a0236d46 644 copied2
+ 69fe3a26aa7ad8afbe05fbf0fe79022def79a065 644 copied2
3e20847584beff41d7cd16136b7331ab3d754be0 644 dir2/file
5fe139720576e18e34bcc9f79174db8897c8afe9 644 dir2/subdir/file3
- 9a7b52012991e4873687192c3e17e61ba3e837a3 644 foo2
+ e6d67dcac8d3a55a337bef9def344d7d339d45ae 644 foo2
$ hg --cwd renames.repo debugrename copied2
copied2 renamed from foo2:2ed2a3912a0b24502043eae84ee4b279c18b90dd
@@ -273,7 +275,8 @@
copied2:
$ hg --cwd renames.repo cat copied2
- foo
+ == copied2 ==
+ goo
filemap errors
diff -r 2df534369f96 -r 74583e9f7f75 tests/test-convert.t
--- a/tests/test-convert.t Sat Nov 26 01:35:38 2011 -0500
+++ b/tests/test-convert.t Sat Nov 26 05:11:03 2011 -0500
@@ -77,6 +77,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 longest matching path applies,
@@ -89,6 +91,13 @@
a file or directory if 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 (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 graft two disconnected
@@ -120,6 +129,13 @@
can be used to (for instance) move code in one repository from "default"
to a named branch.
+ The includerevs and excluderevs options allow you to choose which
+ revisions you would like to appear in the converted repository. The
+ arguments to these commands are files with a revision from the source
+ repository on each line. Note that these directives are only advisory, and
+ in certain situations (i.e. merge nodes and branch endings) the revisions
+ will be converted regardless.
+
Mercurial Source
''''''''''''''''
@@ -256,6 +272,8 @@
--filemap FILE remap file names using contents of file
--splicemap FILE splice synthesized history into place
--branchmap FILE change branch names while converting
+ --includerevs FILE convert only these revisions
+ --excluderevs FILE exclude these revsisions from the conversion
--branchsort try to sort changesets by branches
--datesort try to sort changesets by date
--sourcesort preserve source changesets order
More information about the Mercurial-devel
mailing list