changeset 5173:6b4c332f241b

convert: hg: optionally create branches as clones If convert.hg.clonebranches is set, branches will be created as clones of their parent revisions. All clones will be subdirectories of the destination path.
author Brendan Cully <brendan@kublai.com>
date Wed, 15 Aug 2007 13:21:23 -0700
parents f53d97d651f4
children 090ef15e1a03 7e05bdeee7de
files hgext/convert/__init__.py hgext/convert/common.py hgext/convert/hg.py
diffstat 3 files changed, 40 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/convert/__init__.py	Wed Aug 15 17:27:51 2007 +0200
+++ b/hgext/convert/__init__.py	Wed Aug 15 13:21:23 2007 -0700
@@ -194,6 +194,12 @@
         filenames = []
 
         files, copies = self.source.getchanges(rev)
+        parents = [self.map[r] for r in commit.parents]
+        if commit.parents:
+            pbranch = self.commitcache[commit.parents[0]].branch
+        else:
+            pbranch = None
+        self.dest.setbranch(commit.branch, pbranch, parents)
         for f, v in files:
             newf = self.mapfile(f)
             if not newf:
@@ -213,7 +219,6 @@
                             # Merely marks that a copy happened.
                             self.dest.copyfile(copyf, newf)
 
-        parents = [self.map[r] for r in commit.parents]
         newnode = self.dest.putcommit(filenames, parents, commit)
         self.mapentry(rev, newnode)
 
--- a/hgext/convert/common.py	Wed Aug 15 17:27:51 2007 +0200
+++ b/hgext/convert/common.py	Wed Aug 15 13:21:23 2007 -0700
@@ -134,3 +134,10 @@
         tags: {tagname: sink_rev_id, ...}"""
         raise NotImplementedError()
 
+    def setbranch(self, branch, pbranch, parents):
+        """Set the current branch name. Called before the first putfile
+        on the branch.
+        branch: branch name for subsequent commits
+        pbranch: branch name of parent commit
+        parents: destination revisions of parent"""
+        pass
--- a/hgext/convert/hg.py	Wed Aug 15 17:27:51 2007 +0200
+++ b/hgext/convert/hg.py	Wed Aug 15 13:21:23 2007 -0700
@@ -18,13 +18,15 @@
     def __init__(self, ui, path):
         self.path = path
         self.ui = ui
+        self.branchnames = ui.configbool('convert', 'hg.usebranchnames', True)
+        self.clonebranches = ui.configbool('convert', 'hg.clonebranches', False)
+        self.lastbranch = None
         try:
             self.repo = hg.repository(self.ui, path)
         except:
             raise NoRepo("could not open hg repo %s as sink" % path)
         self.lock = None
         self.wlock = None
-        self.branchnames = ui.configbool('convert', 'hg.usebranchnames', True)
 
     def before(self):
         self.wlock = self.repo.wlock()
@@ -59,6 +61,30 @@
         except:
             pass
 
+    def setbranch(self, branch, pbranch, parents):
+        if (not self.clonebranches) or (branch == self.lastbranch):
+            return
+
+        self.lastbranch = branch
+        self.after()
+        if not branch:
+            branch = 'default'
+        if not pbranch:
+            pbranch = 'default'
+
+        branchpath = os.path.join(self.path, branch)
+        try:
+            self.repo = hg.repository(self.ui, branchpath)
+        except:
+            if not parents:
+                self.repo = hg.repository(self.ui, branchpath, create=True)
+            else:
+                self.ui.note(_('cloning branch %s to %s\n') % (pbranch, branch))
+                hg.clone(self.ui, os.path.join(self.path, pbranch),
+                         branchpath, rev=parents, update=False,
+                         stream=True)
+                self.repo = hg.repository(self.ui, branchpath)
+
     def putcommit(self, files, parents, commit):
         if not files:
             return hex(self.repo.changelog.tip())