[PATCH 05 of 10] Add name map file support

Edouard Gomez ed.gomez at free.fr
Sun Dec 17 15:31:51 UTC 2006


# HG changeset patch
# User Edouard Gomez <ed.gomez at free.fr>
# Date 1166365118 -3600
# Node ID 6381ed11ed68270bff3c0a0eb85cc9df33327aca
# Parent  a0f26709c4cfd1128afe70fa013d82cb300bef42
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 a0f26709c4cf -r 6381ed11ed68 hg-cvs-import
--- a/hg-cvs-import	Sun Dec 17 15:18:38 2006 +0100
+++ b/hg-cvs-import	Sun Dec 17 15:18:38 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(
@@ -40,6 +43,10 @@ Optional options:
  -m mapfile: file where (cvs,hg) node couples are saved (default: map)
  -k: disable CVS keyword expansion when checking out files (default: disabled)
  -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
@@ -60,6 +67,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)
@@ -87,6 +96,7 @@ if map:
 
 err = 0
 
+namemap = {}
 branches = {}
 ancestorbranches = {}
 ancestorpatches = {}
@@ -164,7 +174,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())))
 
@@ -251,6 +262,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()
@@ -267,6 +279,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