[PATCH] convert: Add support for complex branch schemes in Subversion repositories

Juan Wajnerman juan.wajnerman at gmail.com
Wed Nov 10 08:45:00 CST 2010


# HG changeset patch
# User Juan Wajnerman <juan.wajnerman at gmail.com>
# Date 1289400047 10800
# Node ID 95907a0d55181145a6706f96949d914cc28418c7
# Parent  9f2ac318b92e3bde06108bf8493b7d71219ad13e
convert: Add support for complex branch schemes in Subversion repositories.

Many Subversion repositories have many folders containing branches (ie: features, releases, personal).
This change allows to specify a list of branch paths separated by colons. Those paths ending
with slash '/' will be interpreted as a folder that contains branches. Otherwise, the path itself is used
as a new branch.

diff -r 9f2ac318b92e -r 95907a0d5518 hgext/convert/subversion.py
--- a/hgext/convert/subversion.py	Tue Nov 09 13:43:35 2010 +0900
+++ b/hgext/convert/subversion.py	Wed Nov 10 11:40:47 2010 -0300
@@ -321,11 +321,42 @@
             self.ui.note(_('found %s at %r\n') % (name, path))
             return path
 
+        def getcfgpaths(name, rev):
+            cfgpaths = self.ui.config('convert', 'svn.' + name)
+            if cfgpaths is not None and cfgpaths.strip() == '':
+                return None
+            paths = (cfgpaths or name).split(':')
+            for path in paths:
+                if not self.exists(path.strip('/'), rev):
+                    if cfgpaths:
+                        raise util.Abort(_('expected %s to be at %r, but not found')
+                                    % (name, path))
+                    return None
+                self.ui.note(_('found %s at %r\n') % (name, path))
+            return paths
+
+        def generatebranches(branches):
+            for cfgbranch in branches:
+                if cfgbranch.endswith('/'):
+                    cfgbranch = cfgbranch.rstrip('/')
+                    branchnames = svn.client.ls(rpath + '/' + urllib.quote(cfgbranch),
+                                                rev, False, self.ctx)
+                    for branch in branchnames.keys():
+                        if ('%s/%s/' % (cfgbranch, branch)) in branches:
+                            self.ui.note('ignoring branch %s\n' % branch)
+                            continue
+                        module = '%s/%s/%s' % (oldmodule, cfgbranch, branch)
+                        yield branch, module
+                else:
+                    module = '%s/%s' % (oldmodule, cfgbranch)
+                    branch = cfgbranch.rpartition('/')[-1]
+                    yield branch, module
+
         rev = optrev(self.last_changed)
         oldmodule = ''
         trunk = getcfgpath('trunk', rev)
         self.tags = getcfgpath('tags', rev)
-        branches = getcfgpath('branches', rev)
+        branches = getcfgpaths('branches', rev)
 
         # If the project has a trunk or branches, we will extract heads
         # from them. We keep the project root otherwise.
@@ -345,10 +376,8 @@
         # Check if branches bring a few more heads to the list
         if branches:
             rpath = self.url.strip('/')
-            branchnames = svn.client.ls(rpath + '/' + urllib.quote(branches),
-                                        rev, False, self.ctx)
-            for branch in branchnames.keys():
-                module = '%s/%s/%s' % (oldmodule, branches, branch)
+
+            for (branch, module) in generatebranches(branches):
                 if not isdir(module, self.last_changed):
                     continue
                 brevid = self.latest(module, self.last_changed)


More information about the Mercurial-devel mailing list