[PATCH] Adding branchmap functionality to convert extension

Michael J. Pedersen m.pedersen at icelus.org
Wed May 13 00:08:28 CDT 2009


# HG changeset patch
# User Michael J. Pedersen <m.pedersen at icelus.org>
# Date 1242190948 14400
# Node ID 98cf07877cbd06ee96730edf51e08fbc37d4b36c
# Parent  94e91205d9b6f7272d6a1b61c39de4c2555df240
Adding branchmap functionality to convert extension.

This patch adds the ability to rename a branch on import. It turns out it
was very simple and straightforward. Much more so than I thought it would
be, honestly.

So much so, in fact, that I can't really think of an explanation to put in
here that will be clearer than the code itself.

diff -r 94e91205d9b6 -r 98cf07877cbd hgext/convert/__init__.py
--- a/hgext/convert/__init__.py	Tue May 12 10:03:36 2009 -0400
+++ b/hgext/convert/__init__.py	Wed May 13 01:02:28 2009 -0400
@@ -85,6 +85,17 @@
     format as a key in .hg/shamap). The values are the revision IDs
     (in either the source or destination revision control system) that
     should be used as the new parents for that node.
+    
+    The branchmap is a file that allows you to rename a branch when it is
+    being brought in from whatever external repository. When used in
+    conjunction with a splicemap, it allows for a powerful combination
+    to help fix even the most badly mismanaged repositories and turn them
+    into nicely structured Mercurial repositories. The branchmap contains
+    lines of the form "original_branch_name new_branch_name".
+    "original_branch_name" is the name of the branch in the source
+    repository, and "new_branch_name" is the name of the branch is the
+    destination repository. This can be used to (for instance) move code
+    in one repository from "default" to a named branch.
 
     Mercurial Source
     -----------------
@@ -235,6 +246,7 @@
           ('r', 'rev', '', _('import up to target revision REV')),
           ('s', 'source-type', '', _('source repository type')),
           ('', 'splicemap', '', _('splice synthesized history into place')),
+          ('', 'branchmap', '', _('change branch names while converting')),
           ('', 'datesort', None, _('try to sort changesets by date'))],
          _('hg convert [OPTION]... SOURCE [DEST [REVMAP]]')),
     "debugsvnlog":
diff -r 94e91205d9b6 -r 98cf07877cbd hgext/convert/convcmd.py
--- a/hgext/convert/convcmd.py	Tue May 12 10:03:36 2009 -0400
+++ b/hgext/convert/convcmd.py	Wed May 13 01:02:28 2009 -0400
@@ -91,6 +91,7 @@
             self.authorfile = self.dest.authorfile()
 
         self.splicemap = mapfile(ui, opts.get('splicemap'))
+        self.branchmap = mapfile(ui, opts.get('branchmap'))
 
     def walktree(self, heads):
         '''Return a mapping that identifies the uncommitted parents of every
@@ -230,6 +231,7 @@
 
     def copy(self, rev):
         commit = self.commitcache[rev]
+        commit.branch = self.branchmap.get(commit.branch, 'default').replace(',', ' ').split()[0]
 
         changes = self.source.getchanges(rev)
         if isinstance(changes, basestring):
@@ -250,6 +252,7 @@
         self.dest.setbranch(commit.branch, pbranches)
         try:
             parents = self.splicemap[rev].replace(',', ' ').split()
+            parents.extend(self.branchmap.get(commit.branch, '').replace(',', ' ').split()[1:])
             self.ui.status(_('spliced in %s as parents of %s\n') %
                            (parents, rev))
             parents = [self.map.get(p, p) for p in parents]


More information about the Mercurial-devel mailing list