[PATCH 05 of 12] Add name map file support

Edouard Gomez ed.gomez at free.fr
Tue Dec 19 00:05:46 CST 2006


# HG changeset patch
# User Edouard Gomez <ed.gomez at free.fr>
# Date 1166511815 -3600
# Node ID bd6c8e93a7ab4a3a4abcecccef3b4f68218d8856
# Parent  4390635f31ce67052228a76f6c66383c0cde9cf2
Add name map file support

This allow an easy way to do a one way conversion of the user names
used in CVS to transform them into a more hg'ism 'Real Name <who at server.org>'
user name.

diff -r 4390635f31ce -r bd6c8e93a7ab hg-cvs-import
--- a/hg-cvs-import	Tue Dec 19 08:03:35 2006 +0100
+++ b/hg-cvs-import	Tue Dec 19 08:03:35 2006 +0100
@@ -4,12 +4,13 @@ from mercurial import ui, hg, revlog, co
 from mercurial import ui, hg, revlog, commands, util
 
 version = 0.7
-optlist, args = getopt.getopt(sys.argv[1:], 'd:M:C:m:kl')
+optlist, args = getopt.getopt(sys.argv[1:], 'd:M:C:m:klA:')
 
 cvsroot = None
 module = None
 hgpath = None
 mapfile = None
+namemapfile = None
 expandkeyword = ''
 addcvsinfotolog = False
 for name, value in optlist:
@@ -25,6 +26,8 @@ for name, value in optlist:
         expandkeyword = '-kk'
     elif name == '-l':
         addcvsinfotolog = True
+    elif name == '-A':
+        namemapfile = value
 
 if not cvsroot or not module or not hgpath:
     sys.stderr.write(
@@ -41,6 +44,10 @@ Optional options:
  -k: disable CVS keyword expansion when checking out files
      (default: keywords expanded)
  -l: add some CVS information to the commit log message (default: disabled)
+ -A mapfile: file for CVS user mapping. The format is a mapping per line like
+             the following example:
+             cvsuser=Real Name <who at server.org>
+             (default: none)
 
 Inline manual
 1. Use cvsps to generate patchset information
@@ -61,6 +68,8 @@ cvsroot = os.path.abspath(cvsroot)
 cvsroot = os.path.abspath(cvsroot)
 hgpatch = os.path.abspath(hgpath)
 mapfile = os.path.abspath(mapfile)
+if namemapfile:
+    namemapfile = os.path.abspath(namemapfile)
 
 u = ui.ui()
 repo = hg.repository(ui = u, path=hgpath)
@@ -88,6 +97,7 @@ if map:
 
 err = 0
 
+namemap = {}
 branches = {}
 ancestorbranches = {}
 ancestorpatches = {}
@@ -165,7 +175,8 @@ def committags(patchset):
         f.close()
 
         date = "%s 0" % int(time.mktime(time.gmtime()))
-        n = repo.rawcommit([".hgtags"], "update tags", "convert-repo",
+        user = namemap.get('convert-repo', 'convert-repo')
+        n = repo.rawcommit([".hgtags"], "Update tags", user,
                         date, repo.changelog.tip(), hg.nullid)
         mapf.write("%d %s\n" % (patchset, hg.hex(repo.changelog.tip())))
 
@@ -252,6 +263,7 @@ def addrev(branch, tag, r, user, date, l
             log.append("CVS date: %s" % date)
             log.append("")
         llog = "\n".join(log)
+        user = namemap.get(user, user)
         repo.rawcommit(filelist, llog, user, dateconv, hg.bin(node),
                        wlock=wlock)
         n = repo.changelog.tip()
@@ -268,6 +280,21 @@ def addrev(branch, tag, r, user, date, l
         if not branchdone:
             addtag(branch, hg.hex(n))
         addtag(tag, hg.hex(n))
+
+def readnamemap(filename):
+    try:
+        namemapfile = open(filename, "r")
+        for line in namemapfile:
+            cvsname = line.split('=')[0].strip()
+            hgname = line.split('=')[1].strip()
+            namemap[cvsname] = hgname
+        namemapfile.close()
+    except IOError:
+        sys.stderr.write("Could not read the name map file\n")
+        pass
+
+if namemapfile:
+    readnamemap(namemapfile)
 
 if args is None or len(args) == 0:
     args = ['-']


More information about the Mercurial-devel mailing list