[PATCH] fix for convert extension issue3469

Lawrence Stewart lstewart at room52.net
Mon Aug 20 00:06:04 CDT 2012


Hi Pierre-Yves,

Thanks for the feedback and apologies for the very long delay in coming 
back to this.

On 05/29/12 20:33, Pierre-Yves David wrote:
> On Mon, May 28, 2012 at 11:21:02AM +1000, Lawrence Stewart wrote:
>> Hi all,
>>
>> Caveat: first time contributor with essentially no working knowledge
>> of the Mercurial code base, so please go easy on me :)
>>
>> Attached is a tested patch which addresses issue3469 as far as my
>> needs are concerned. The bug description [1] has all the relevant
>> background which I won't repeat here.
>
> submitted patch should be inlined in the message commit, not attached. You
> probably want to use the patchbomb extension:
>
> http://mercurial.selenic.com/wiki/ContributingChanges

I believe I've managed to configure Thunderbird to send the patch with 
"Content-Disposition: inline". If that's still not what you had in mind, 
does anyone have a pointer how to make Thunderbird do the right thing? 
I'd prefer not to use patchbomb as the emails won't end up in my sent 
history.

>> It's unclear to me if this patch should be accompanied by specific
>> tweaks to the test suite or whether the existing tests which cover
>> converting branches via the branchmap are sufficient.
>
> If the breakage introduced by issue2653 fixes is not caught by the testsuite,
> you better add a new test for it.

Ok, I think I've done that in the revised patch.

>> Feedback welcomed.
>>
>> Cheers,
>> Lawrence
>>
>> [1] http://bz.selenic.com/show_bug.cgi?id=3469
>
>> # HG changeset patch
>> # User lstewart
>> # Date 1338167428 -36000
>> # Node ID 18f05159a4fb2fbc1c6c07e7ef0e8009a5f2d86d
>> # Parent  2ac08d8b21aa7b6e0a062afed5a3f357ccef67f9
>> convert: allow branchmap to map trunk to arbitrary named branch (issue3469)
>>
>> The fix for issue2653 broke the ability to convert the trunk branch of a source
>> repository to a named branch other than "default" in the destination repository.
>> Leave the default behaviour as is, but allow the branchmap to be used to specify
>> a non-default name for the branch in the destination repository to which
>> converted revisions from trunk will be applied.
>>
>> diff -r 2ac08d8b21aa -r 18f05159a4fb hgext/convert/convcmd.py
>> --- a/hgext/convert/convcmd.py	Tue May 22 14:37:20 2012 -0500
>> +++ b/hgext/convert/convcmd.py	Mon May 28 11:10:28 2012 +1000
>> @@ -340,6 +340,18 @@
>>                       self.cachecommit(prev)
>>                   pbranches.append((self.map[prev],
>>                                     self.commitcache[prev].branch))
>> +
>> +        # If no destination branch is set, this commit is destined for the
>> +        # default branch in the destination repository. If a suitable entry
>> +        # exists in the branchmap, map the trunk branch name in the source
>> +        # repository to the branchmap-defined name in the destination
>> +        # repository.
>> +        try:
>> +            if not commit.branch:
>> +                commit.branch = self.branchmap[self.source.trunkname]
>> +        except KeyError:
>> +            pass
>
> You should considerer using `self.branchmap.get(self.source.trunkname)` instead
> of a try, except construct.

Done.

Cheers,
Lawrence
-------------- next part --------------
# HG changeset patch
# User lstewart
# Date 1345434904 -36000
# Node ID 7759929129f7896b7e131d6e160ce8ef68585d5d
# Parent  c6f88e7f95b764e23b7e0b4353c5a6458bbc3cc4
convert: allow branchmap to map trunk to arbitrary named branch (issue3469)

The fix for issue2653 broke the ability to convert the trunk branch of a source
repository to a named branch other than "default" in the destination repository.
Leave the default behaviour as is, but allow the branchmap to be used to specify
a non-default name for the branch in the destination repository to which
converted revisions from trunk will be applied.

diff -r c6f88e7f95b7 -r 7759929129f7 hgext/convert/convcmd.py
--- a/hgext/convert/convcmd.py	Sat Aug 11 12:45:53 2012 -0500
+++ b/hgext/convert/convcmd.py	Mon Aug 20 13:55:04 2012 +1000
@@ -340,6 +340,15 @@
                     self.cachecommit(prev)
                 pbranches.append((self.map[prev],
                                   self.commitcache[prev].branch))
+
+        # If no destination branch is set, this commit is destined for the
+        # default branch in the destination repository. If a suitable entry
+        # exists in the branchmap, map the trunk branch name in the source
+        # repository to the branchmap-defined name in the destination
+        # repository.
+        if not commit.branch:
+            commit.branch = self.branchmap.get(self.source.trunkname)
+
         self.dest.setbranch(commit.branch, pbranches)
         try:
             parents = self.splicemap[rev]
diff -r c6f88e7f95b7 -r 7759929129f7 tests/test-convert-svn-branches.t
--- a/tests/test-convert-svn-branches.t	Sat Aug 11 12:45:53 2012 -0500
+++ b/tests/test-convert-svn-branches.t	Mon Aug 20 13:55:04 2012 +1000
@@ -101,3 +101,34 @@
   abort: Mercurial failed to run itself, check hg executable is in PATH
   [255]
 
+Convert 'trunk' to branch other than 'default'
+
+  $ cat > branchmap <<EOF
+  > trunk 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 ..
+



More information about the Mercurial-devel mailing list