[PATCH] convert: add --authormapsuffix to append set text to author names (issue4171)
lstewart at room52.net
lstewart at room52.net
Thu Feb 13 18:30:50 CST 2014
# HG changeset patch
# User lstewart
# Date 1392337372 -39600
# Fri Feb 14 11:22:52 2014 +1100
# Node ID 2b6fdac02ea3ae0fdefa8d0738f7df679a80dcfd
# Parent 80628d4069be724089ea487a300d62f4cbd8970d
convert: add --authormapsuffix to append set text to author names (issue4171)
The --authormap option to convert does not provide a mechanism to template how
author names should be mapped from the source to destination repository. In the
absence of a more complete templating like feature, this new option allows some
set text to be appended to every author name during the conversion. This is
particularly useful for changing project-local usernames into globally
distinguishable author identifiers e.g. by mapping "lstewart" ->
"lstewart at FreeBSD.org", without first having to obtain a list of all authors in
the source repository and create an authormap from that list.
If --authormapsuffix is used concurrently with --authormap, the suffix is
appended to post-authormap-translated names as well as non-authormap-translated
names.
diff -r 80628d4069be -r 2b6fdac02ea3 hgext/convert/__init__.py
--- a/hgext/convert/__init__.py Fri Jan 31 01:12:35 2014 -0800
+++ b/hgext/convert/__init__.py Fri Feb 14 11:22:52 2014 +1100
@@ -85,6 +85,9 @@
Empty lines and lines starting with a ``#`` are ignored.
+ The authormapsuffix can be used to append set text to each
+ post-authormap-translated author name.
+
The filemap is a file that allows filtering and remapping of files
and directories. Each line can contain one of the following
directives::
@@ -321,6 +324,8 @@
_('import up to source revision REV'), _('REV')),
('A', 'authormap', '',
_('remap usernames using this file'), _('FILE')),
+ ('', 'authormapsuffix', '',
+ _('append this suffix to remapped author names'), _('SUFFIX')),
('', 'filemap', '',
_('remap file names using contents of file'), _('FILE')),
('', 'splicemap', '',
diff -r 80628d4069be -r 2b6fdac02ea3 hgext/convert/convcmd.py
--- a/hgext/convert/convcmd.py Fri Jan 31 01:12:35 2014 -0800
+++ b/hgext/convert/convcmd.py Fri Feb 14 11:22:52 2014 +1100
@@ -103,12 +103,15 @@
self.commitcache = {}
self.authors = {}
self.authorfile = None
+ self.authormapsuffix = ''
# Record converted revisions persistently: maps source revision
# ID to target revision ID (both strings). (This is how
# incremental conversions work.)
self.map = mapfile(ui, revmapfile)
+ if opts.get('authormapsuffix'):
+ self.authormapsuffix = opts.get('authormapsuffix')
# Read first the dst author map if any
authorfile = self.dest.authorfile()
if authorfile and os.path.exists(authorfile):
@@ -393,7 +396,7 @@
continue
srcauthor = srcauthor.strip()
- dstauthor = dstauthor.strip()
+ dstauthor = dstauthor.strip() + self.authormapsuffix
if self.authors.get(srcauthor) in (None, dstauthor):
msg = _('mapping author %s to %s\n')
self.ui.debug(msg % (srcauthor, dstauthor))
@@ -407,7 +410,8 @@
def cachecommit(self, rev):
commit = self.source.getcommit(rev)
- commit.author = self.authors.get(commit.author, commit.author)
+ commit.author = self.authors.get(commit.author,
+ commit.author + self.authormapsuffix)
# If commit.branch is None, this commit is coming from the source
# repository's default branch and destined for the default branch in the
# destination repository. For such commits, passing a literal "None"
diff -r 80628d4069be -r 2b6fdac02ea3 tests/test-convert-authormap.t
--- a/tests/test-convert-authormap.t Fri Jan 31 01:12:35 2014 -0800
+++ b/tests/test-convert-authormap.t Fri Feb 14 11:22:52 2014 +1100
@@ -10,6 +10,8 @@
$ cd orig
$ echo foo > foo
$ HGUSER='user name' hg ci -qAm 'foo'
+ $ echo bar > bar
+ $ HGUSER='user name 2' hg ci -qAm 'bar'
$ cd ..
Explicit --authors
@@ -26,13 +28,19 @@
scanning source...
sorting...
converting...
- 0 foo
+ 1 foo
+ 0 bar
writing author map file $TESTTMP/new/.hg/authormap (glob)
$ cat new/.hg/authormap
user name=Long User Name
$ hg -Rnew log
+ changeset: 1:263e7765e4b7
+ tag: tip
+ user: user name 2
+ date: Thu Jan 01 00:00:00 1970 +0000
+ summary: bar
+
changeset: 0:d89716e88087
- tag: tip
user: Long User Name
date: Thu Jan 01 00:00:00 1970 +0000
summary: foo
@@ -48,11 +56,73 @@
scanning source...
sorting...
converting...
- 0 foo
+ 1 foo
+ 0 bar
$ hg -Rnew log
+ changeset: 1:263e7765e4b7
+ tag: tip
+ user: user name 2
+ date: Thu Jan 01 00:00:00 1970 +0000
+ summary: bar
+
changeset: 0:d89716e88087
- tag: tip
user: Long User Name
date: Thu Jan 01 00:00:00 1970 +0000
summary: foo
+ $ rm -rf new
+
+Use authormapsuffix together with authormap
+
+ $ cat > authormap.txt <<EOF
+ > user name = username
+ > user name 2 = username2
+ > EOF
+ $ hg convert --authormap authormap.txt --authormapsuffix '@test.org' orig new
+ initializing destination new repository
+ scanning source...
+ sorting...
+ converting...
+ 1 foo
+ 0 bar
+ writing author map file $TESTTMP/new/.hg/authormap
+ $ cat new/.hg/authormap
+ user name=username at test.org
+ user name 2=username2 at test.org
+ $ hg -Rnew log
+ changeset: 1:aeeaab422b32
+ tag: tip
+ user: username2 at test.org
+ date: Thu Jan 01 00:00:00 1970 +0000
+ summary: bar
+
+ changeset: 0:51317d63da9e
+ user: username at test.org
+ date: Thu Jan 01 00:00:00 1970 +0000
+ summary: foo
+
+ $ rm -rf new
+
+Use authormapsuffix stand alone
+
+ $ hg convert --authormapsuffix '@test.org' orig new
+ initializing destination new repository
+ scanning source...
+ sorting...
+ converting...
+ 1 foo
+ 0 bar
+ $ hg -Rnew log
+ changeset: 1:94e0dcfe3b0d
+ tag: tip
+ user: user name 2 at test.org
+ date: Thu Jan 01 00:00:00 1970 +0000
+ summary: bar
+
+ changeset: 0:e2ff155c86b8
+ user: user name at test.org
+ date: Thu Jan 01 00:00:00 1970 +0000
+ summary: foo
+
+ $ rm -rf new
+
More information about the Mercurial-devel
mailing list