Mercurial > hg
comparison hgext/convert/convcmd.py @ 25805:584044e5ad57
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.
author | Eugene Baranov <eug.baranov@gmail.com> |
---|---|
date | Tue, 14 Jul 2015 14:40:56 +0100 |
parents | baea47cafe75 |
children | 86598f4fe1cf |
comparison
equal
deleted
inserted
replaced
25804:f0a77cb6316a | 25805:584044e5ad57 |
---|---|
26 def recode(s): | 26 def recode(s): |
27 if isinstance(s, unicode): | 27 if isinstance(s, unicode): |
28 return s.encode(orig_encoding, 'replace') | 28 return s.encode(orig_encoding, 'replace') |
29 else: | 29 else: |
30 return s.decode('utf-8').encode(orig_encoding, 'replace') | 30 return s.decode('utf-8').encode(orig_encoding, 'replace') |
31 | |
32 def mapbranch(branch, branchmap): | |
33 ''' | |
34 >>> bmap = {'default': 'branch1'} | |
35 >>> for i in ['', None]: | |
36 ... mapbranch(i, bmap) | |
37 'branch1' | |
38 'branch1' | |
39 >>> bmap = {'None': 'branch2'} | |
40 >>> for i in ['', None]: | |
41 ... mapbranch(i, bmap) | |
42 'branch2' | |
43 'branch2' | |
44 >>> bmap = {'None': 'branch3', 'default': 'branch4'} | |
45 >>> for i in ['None', '', None, 'default', 'branch5']: | |
46 ... mapbranch(i, bmap) | |
47 'branch3' | |
48 'branch4' | |
49 'branch4' | |
50 'branch4' | |
51 'branch5' | |
52 ''' | |
53 # If branch is None or empty, this commit is coming from the source | |
54 # repository's default branch and destined for the default branch in the | |
55 # destination repository. For such commits, using a literal "default" | |
56 # in branchmap below allows the user to map "default" to an alternate | |
57 # default branch in the destination repository. | |
58 branch = branchmap.get(branch or 'default', branch) | |
59 # At some point we used "None" literal to denote the default branch, | |
60 # attempt to use that for backward compatibility. | |
61 if (not branch): | |
62 branch = branchmap.get(str(None), branch) | |
63 return branch | |
31 | 64 |
32 source_converters = [ | 65 source_converters = [ |
33 ('cvs', convert_cvs, 'branchsort'), | 66 ('cvs', convert_cvs, 'branchsort'), |
34 ('git', convert_git, 'branchsort'), | 67 ('git', convert_git, 'branchsort'), |
35 ('svn', svn_source, 'branchsort'), | 68 ('svn', svn_source, 'branchsort'), |
375 afile.close() | 408 afile.close() |
376 | 409 |
377 def cachecommit(self, rev): | 410 def cachecommit(self, rev): |
378 commit = self.source.getcommit(rev) | 411 commit = self.source.getcommit(rev) |
379 commit.author = self.authors.get(commit.author, commit.author) | 412 commit.author = self.authors.get(commit.author, commit.author) |
380 # If commit.branch is None, this commit is coming from the source | 413 commit.branch = mapbranch(commit.branch, self.branchmap) |
381 # repository's default branch and destined for the default branch in the | |
382 # destination repository. For such commits, passing a literal "None" | |
383 # string to branchmap.get() below allows the user to map "None" to an | |
384 # alternate default branch in the destination repository. | |
385 commit.branch = self.branchmap.get(str(commit.branch), commit.branch) | |
386 self.commitcache[rev] = commit | 414 self.commitcache[rev] = commit |
387 return commit | 415 return commit |
388 | 416 |
389 def copy(self, rev): | 417 def copy(self, rev): |
390 commit = self.commitcache[rev] | 418 commit = self.commitcache[rev] |