Patchwork [1,of,1] convert: use branchmap to change default branch in destination (issue3469)

login
register
mail settings
Submitter lstewart@room52.net
Date Jan. 28, 2014, 3:20 a.m.
Message ID <949bb5bb56b5340e87cb.1390879250@lstewart-laptop.caia.swin.edu.au>
Download mbox | patch
Permalink /patch/3417/
State Accepted
Commit 1d155582a8eaadd4da3f0186654d5836b2a1f8a7
Headers show

Comments

lstewart@room52.net - Jan. 28, 2014, 3:20 a.m.
# HG changeset patch
# User lstewart
# Date 1390878023 -39600
#      Tue Jan 28 14:00:23 2014 +1100
# Branch stable
# Node ID 949bb5bb56b5340e87cbcb8097dfa4e4be73db11
# Parent  427d672c0e4e07642d2400a28946cefde11e04ff
convert: use branchmap to change default branch in destination (issue3469)

The fix for issue2653 broke the ability to map the default branch of a source
repository to a non-default named branch in the destination repository.  Leave
the default behaviour as is, but allow the branch name "None" to be used to map
to a non-default named branch in the destination repository.
Matt Mackall - Jan. 30, 2014, 8:36 p.m.
On Tue, 2014-01-28 at 14:20 +1100, lstewart@room52.net wrote:
> # HG changeset patch
> # User lstewart
> # Date 1390878023 -39600
> #      Tue Jan 28 14:00:23 2014 +1100
> # Branch stable
> # Node ID 949bb5bb56b5340e87cbcb8097dfa4e4be73db11
> # Parent  427d672c0e4e07642d2400a28946cefde11e04ff
> convert: use branchmap to change default branch in destination (issue3469)

Queued for stable, thanks.

Patch

diff -r 427d672c0e4e -r 949bb5bb56b5 hgext/convert/convcmd.py
--- a/hgext/convert/convcmd.py	Sun Nov 24 02:17:17 2013 +0100
+++ b/hgext/convert/convcmd.py	Tue Jan 28 14:00:23 2014 +1100
@@ -371,7 +371,12 @@ 
     def cachecommit(self, rev):
         commit = self.source.getcommit(rev)
         commit.author = self.authors.get(commit.author, commit.author)
-        commit.branch = self.branchmap.get(commit.branch, commit.branch)
+        # If commit.branch is None, this commit is coming from the source
+        # repository's default branch and destined for the default branch in the
+        # destination repository. For such commits, passing a literal "None"
+        # string to branchmap.get() below allows the user to map "None" to an
+        # alternate default branch in the destination repository.
+        commit.branch = self.branchmap.get(str(commit.branch), commit.branch)
         self.commitcache[rev] = commit
         return commit
 
diff -r 427d672c0e4e -r 949bb5bb56b5 tests/test-convert-svn-branches.t
--- a/tests/test-convert-svn-branches.t	Sun Nov 24 02:17:17 2013 +0100
+++ b/tests/test-convert-svn-branches.t	Tue Jan 28 14:00:23 2014 +1100
@@ -96,3 +96,35 @@ 
 
   $ HG=foobar hg convert svn-repo B-hg 2>&1 | grep abort
   abort: Mercurial failed to run itself, check hg executable is in PATH
+
+Convert 'trunk' to branch other than 'default'
+
+  $ cat > branchmap <<EOF
+  > None hgtrunk
+  > 
+  > 
+  > EOF
+  $ hg convert --branchmap=branchmap --datesort -r 10 svn-repo C-hg
+  initializing destination C-hg repository
+  scanning source...
+  sorting...
+  converting...
+  10 init projA
+  9 hello
+  8 branch trunk, remove c and dir
+  7 change a
+  6 change b
+  5 move and update c
+  4 move and update c
+  3 change b again
+  2 move to old2
+  1 move back to old
+  0 last change to a
+
+  $ cd C-hg
+  $ hg branches
+  hgtrunk                       10:745f063703b4
+  old                            9:aa50d7b8d922
+  old2                           8:c85a22267b6e (inactive)
+  $ cd ..
+