From patchwork Wed Jul 15 11:21:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [v2] convert: use 'default' for specifying branch name in branchmap (issue4753) From: Eugene Baranov X-Patchwork-Id: 9989 Message-Id: <7f1fc20a2a2c5003e8f9.1436959273@ADNADTX6400256.eng.citrite.net> To: mercurial-devel@selenic.com Date: Wed, 15 Jul 2015 12:21:13 +0100 # HG changeset patch # User Eugene Baranov # Date 1436881256 -3600 # Tue Jul 14 14:40:56 2015 +0100 # Node ID 7f1fc20a2a2c5003e8f973248b8049c6f6c9c859 # Parent 528c1d146a0d2f079f01b81771140e3d8ed066e6 convert: use 'default' for specifying branch name in branchmap (issue4753) A fix for issue2653 with 1d155582a8ea introduced a discrepancy how default branch should be denoted when converting with branchmap from different SCM. E.g. for Git and Mercurial you need to use 'default' whilst for Perforce and SVN you had to use 'None'. This changeset unifies 'default' for such purposes whilst falling back to 'None' when no 'default' mapping specified. diff -r 528c1d146a0d -r 7f1fc20a2a2c hgext/convert/convcmd.py --- a/hgext/convert/convcmd.py Tue Jul 14 16:23:57 2015 +0100 +++ b/hgext/convert/convcmd.py Tue Jul 14 14:40:56 2015 +0100 @@ -29,6 +29,39 @@ else: return s.decode('utf-8').encode(orig_encoding, 'replace') +def mapbranch(branch, branchmap): + ''' + >>> bmap = {'default': 'branch1'} + >>> for i in ['', None]: + ... mapbranch(i, bmap) + 'branch1' + 'branch1' + >>> bmap = {'None': 'branch2'} + >>> for i in ['', None]: + ... mapbranch(i, bmap) + 'branch2' + 'branch2' + >>> bmap = {'None': 'branch3', 'default': 'branch4'} + >>> for i in ['None', '', None, 'default', 'branch5']: + ... mapbranch(i, bmap) + 'branch3' + 'branch4' + 'branch4' + 'branch4' + 'branch5' + ''' + # If branch is None or empty, this commit is coming from the source + # repository's default branch and destined for the default branch in the + # destination repository. For such commits, using a literal "default" + # in branchmap below allows the user to map "default" to an alternate + # default branch in the destination repository. + branch = branchmap.get(branch or 'default', branch) + # At some point we used "None" literal to denote the default branch, + # attempt to use that for backward compatibility. + if (not branch): + branch = branchmap.get(str(None), branch) + return branch + source_converters = [ ('cvs', convert_cvs, 'branchsort'), ('git', convert_git, 'branchsort'), @@ -377,12 +410,7 @@ def cachecommit(self, rev): commit = self.source.getcommit(rev) commit.author = self.authors.get(commit.author, commit.author) - # 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) + commit.branch = mapbranch(commit.branch, self.branchmap) self.commitcache[rev] = commit return commit diff -r 528c1d146a0d -r 7f1fc20a2a2c hgext/convert/p4.py --- a/hgext/convert/p4.py Tue Jul 14 16:23:57 2015 +0100 +++ b/hgext/convert/p4.py Tue Jul 14 14:40:56 2015 +0100 @@ -140,7 +140,7 @@ date = (int(d["time"]), 0) # timezone not set c = commit(author=self.recode(d["user"]), date=util.datestr(date, '%Y-%m-%d %H:%M:%S %1%2'), - parents=parents, desc=desc, branch='', + parents=parents, desc=desc, branch=None, extra={"p4": change}) files = [] diff -r 528c1d146a0d -r 7f1fc20a2a2c tests/test-convert-svn-branches.t --- a/tests/test-convert-svn-branches.t Tue Jul 14 16:23:57 2015 +0100 +++ b/tests/test-convert-svn-branches.t Tue Jul 14 14:40:56 2015 +0100 @@ -99,7 +99,7 @@ Convert 'trunk' to branch other than 'default' $ cat > branchmap < None hgtrunk + > default hgtrunk > > > EOF @@ -121,9 +121,8 @@ 0 last change to a $ cd C-hg - $ hg branches - hgtrunk 10:745f063703b4 - old 9:aa50d7b8d922 - old2 8:c85a22267b6e (inactive) - $ cd .. - + $ hg branches --template '{branch}\n' + hgtrunk + old + old2 + $ cd .. \ No newline at end of file diff -r 528c1d146a0d -r 7f1fc20a2a2c tests/test-doctest.py --- a/tests/test-doctest.py Tue Jul 14 16:23:57 2015 +0100 +++ b/tests/test-doctest.py Tue Jul 14 14:40:56 2015 +0100 @@ -31,6 +31,7 @@ testmod('mercurial.url') testmod('mercurial.util') testmod('mercurial.util', testtarget='platform') +testmod('hgext.convert.convcmd') testmod('hgext.convert.cvsps') testmod('hgext.convert.filemap') testmod('hgext.convert.p4')