[PATCH 1 of 2] Add user names mapping
Edouard Gomez
ed.gomez at free.fr
Mon Feb 5 23:40:43 UTC 2007
# HG changeset patch
# User Edouard Gomez <ed.gomez at free.fr>
# Date 1170718579 -3600
# Node ID e34b962f3d8580151ca306ac74e005fb02e668b2
# Parent 82eb0fafb56d5767af52ed60cd272311675b547f
Add user names mapping
Allows mapping usernames to new ones during conversion process.
- Use -A option for first import
- Then at the end of the conversion process and if the destination
repo supports authorfile attribute, author map content is copied
to the file pointed by the authorfile call.
- On incremental conversions w/o any -A option specified, the
destination authorfile, if any, gets read automatically.
EG: This allows mapping unix system usernames used in CVS accounts
to a more typical "Firstname Lastname <address at server.org>" pair.
diff -r 82eb0fafb56d -r e34b962f3d85 contrib/convert-repo
--- a/contrib/convert-repo Tue Jan 30 21:11:10 2007 -0200
+++ b/contrib/convert-repo Tue Feb 06 00:36:19 2007 +0100
@@ -381,6 +381,9 @@ class convert_mercurial:
def mapfile(self):
return os.path.join(self.path, ".hg", "shamap")
+ def authorsfile(self):
+ return os.path.join(self.path, ".hg", "authorsmap")
+
def getheads(self):
h = self.repo.changelog.heads()
return [ hg.hex(x) for x in h ]
@@ -474,12 +477,30 @@ class convert:
self.mapfile = mapfile
self.opts = opts
self.commitcache = {}
+ self.authors = {}
self.map = {}
try:
for l in file(self.mapfile):
sv, dv = l[:-1].split()
self.map[sv] = dv
+ except IOError:
+ pass
+
+ authorsfile = None
+ if 'authors' in opts:
+ authorsfile = opts.get('authors')
+ elif hasattr(dest, 'authorsfile'):
+ authorsfile = dest.authorsfile()
+
+ try:
+ afile = open(authorsfile, 'rb')
+ for line in afile:
+ try:
+ self.authors[line.split('=')[0].strip()] = line.split('=')[1].strip()
+ except IndexError:
+ pass
+ afile.close()
except IOError:
pass
@@ -589,6 +610,9 @@ class convert:
if "\n" in desc:
desc = desc.splitlines()[0]
status("%d %s\n" % (num, desc))
+ author = self.commitcache[c].author
+ if author in self.authors:
+ self.commitcache[c].author = self.authors[author]
self.copy(c)
tags = self.source.gettags()
@@ -604,6 +628,13 @@ class convert:
# one so we don't end up with extra tag heads
if nrev:
file(self.mapfile, "a").write("%s %s\n" % (c, nrev))
+
+ # save authors file if any author given
+ if len(self.authors) > 0 and hasattr(self.dest, 'authorsfile'):
+ ofile = open(self.dest.authorsfile(), 'w+')
+ for author in self.authors:
+ ofile.write("%s=%s\n" % (author, self.authors[author]))
+ ofile.close()
def command(src, dest=None, mapfile=None, **opts):
srcc = converter(src)
@@ -630,6 +661,7 @@ def command(src, dest=None, mapfile=None
c.convert()
options = [('q', 'quiet', None, 'suppress output'),
+ ('A', 'authors', '', 'User name mapping file'),
('', 'datesort', None, 'try to sort changesets by date')]
opts = {}
args = fancyopts.fancyopts(sys.argv[1:], options, opts)
More information about the Mercurial-devel
mailing list