Mercurial > hg-stable
annotate hgext/convert/bzr.py @ 18474:e031e10cdc06 stable
help: document '@' bookmark in 'help bookmarks' and 'help clone'
author | Kevin Bullock <kbullock@ringworld.org> |
---|---|
date | Fri, 25 Jan 2013 11:06:30 -0600 |
parents | e7cfe3587ea4 |
children | 650b5b6e75ed |
rev | line source |
---|---|
8250
1b60efdb8bc5
convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents:
8166
diff
changeset
|
1 # bzr.py - bzr support for the convert extension |
1b60efdb8bc5
convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents:
8166
diff
changeset
|
2 # |
1b60efdb8bc5
convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents:
8166
diff
changeset
|
3 # Copyright 2008, 2009 Marek Kubica <marek@xivilization.net> and others |
1b60efdb8bc5
convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents:
8166
diff
changeset
|
4 # |
1b60efdb8bc5
convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents:
8166
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
10263 | 6 # GNU General Public License version 2 or any later version. |
8250
1b60efdb8bc5
convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents:
8166
diff
changeset
|
7 |
7053 | 8 # This module is for handling 'bzr', that was formerly known as Bazaar-NG; |
9 # it cannot access 'bar' repositories, but they were never used very much | |
10 | |
11 import os | |
12 from mercurial import demandimport | |
13 # these do not work with demandimport, blacklist | |
14 demandimport.ignore.extend([ | |
15 'bzrlib.transactions', | |
16 'bzrlib.urlutils', | |
10560
9134725caf1d
Add ElementPath to the list of package ignored by demand import
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
10394
diff
changeset
|
17 'ElementPath', |
7053 | 18 ]) |
19 | |
20 from mercurial.i18n import _ | |
21 from mercurial import util | |
22 from common import NoRepo, commit, converter_source | |
23 | |
24 try: | |
25 # bazaar imports | |
16060
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
26 from bzrlib import bzrdir, revision, errors |
7053 | 27 from bzrlib.revisionspec import RevisionSpec |
28 except ImportError: | |
29 pass | |
30 | |
8045
e09a2f2ef85d
convert/bzr: fix file rename replaced by a dir case (issue1583)
Patrick Mezard <pmezard@gmail.com>
parents:
8035
diff
changeset
|
31 supportedkinds = ('file', 'symlink') |
e09a2f2ef85d
convert/bzr: fix file rename replaced by a dir case (issue1583)
Patrick Mezard <pmezard@gmail.com>
parents:
8035
diff
changeset
|
32 |
7053 | 33 class bzr_source(converter_source): |
34 """Reads Bazaar repositories by using the Bazaar Python libraries""" | |
35 | |
36 def __init__(self, ui, path, rev=None): | |
37 super(bzr_source, self).__init__(ui, path, rev=rev) | |
38 | |
7973
db3a68fd9387
convert: attempt to check repo type before checking for tool
Matt Mackall <mpm@selenic.com>
parents:
7060
diff
changeset
|
39 if not os.path.exists(os.path.join(path, '.bzr')): |
10939
9f6731b03906
convert: mark strings for translation
Martin Geisler <mg@lazybytes.net>
parents:
10938
diff
changeset
|
40 raise NoRepo(_('%s does not look like a Bazaar repository') |
9f6731b03906
convert: mark strings for translation
Martin Geisler <mg@lazybytes.net>
parents:
10938
diff
changeset
|
41 % path) |
7973
db3a68fd9387
convert: attempt to check repo type before checking for tool
Matt Mackall <mpm@selenic.com>
parents:
7060
diff
changeset
|
42 |
7053 | 43 try: |
44 # access bzrlib stuff | |
16060
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
45 bzrdir |
7053 | 46 except NameError: |
10939
9f6731b03906
convert: mark strings for translation
Martin Geisler <mg@lazybytes.net>
parents:
10938
diff
changeset
|
47 raise NoRepo(_('Bazaar modules could not be loaded')) |
7053 | 48 |
49 path = os.path.abspath(path) | |
8470
dd24488cba2d
convert/bzr: warn when source is a lightweight checkout (issue1647)
Patrick Mezard <pmezard@gmail.com>
parents:
8434
diff
changeset
|
50 self._checkrepotype(path) |
16060
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
51 try: |
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
52 self.sourcerepo = bzrdir.BzrDir.open(path).open_repository() |
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
53 except errors.NoRepositoryPresent: |
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
54 raise NoRepo(_('%s does not look like a Bazaar repository') |
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
55 % path) |
7053 | 56 self._parentids = {} |
57 | |
8470
dd24488cba2d
convert/bzr: warn when source is a lightweight checkout (issue1647)
Patrick Mezard <pmezard@gmail.com>
parents:
8434
diff
changeset
|
58 def _checkrepotype(self, path): |
dd24488cba2d
convert/bzr: warn when source is a lightweight checkout (issue1647)
Patrick Mezard <pmezard@gmail.com>
parents:
8434
diff
changeset
|
59 # Lightweight checkouts detection is informational but probably |
dd24488cba2d
convert/bzr: warn when source is a lightweight checkout (issue1647)
Patrick Mezard <pmezard@gmail.com>
parents:
8434
diff
changeset
|
60 # fragile at API level. It should not terminate the conversion. |
dd24488cba2d
convert/bzr: warn when source is a lightweight checkout (issue1647)
Patrick Mezard <pmezard@gmail.com>
parents:
8434
diff
changeset
|
61 try: |
dd24488cba2d
convert/bzr: warn when source is a lightweight checkout (issue1647)
Patrick Mezard <pmezard@gmail.com>
parents:
8434
diff
changeset
|
62 from bzrlib import bzrdir |
dd24488cba2d
convert/bzr: warn when source is a lightweight checkout (issue1647)
Patrick Mezard <pmezard@gmail.com>
parents:
8434
diff
changeset
|
63 dir = bzrdir.BzrDir.open_containing(path)[0] |
dd24488cba2d
convert/bzr: warn when source is a lightweight checkout (issue1647)
Patrick Mezard <pmezard@gmail.com>
parents:
8434
diff
changeset
|
64 try: |
dd24488cba2d
convert/bzr: warn when source is a lightweight checkout (issue1647)
Patrick Mezard <pmezard@gmail.com>
parents:
8434
diff
changeset
|
65 tree = dir.open_workingtree(recommend_upgrade=False) |
dd24488cba2d
convert/bzr: warn when source is a lightweight checkout (issue1647)
Patrick Mezard <pmezard@gmail.com>
parents:
8434
diff
changeset
|
66 branch = tree.branch |
12063
516b000fbb7e
cleanup: remove unused variables
Brodie Rao <brodie@bitheap.org>
parents:
11134
diff
changeset
|
67 except (errors.NoWorkingTree, errors.NotLocalUrl): |
8470
dd24488cba2d
convert/bzr: warn when source is a lightweight checkout (issue1647)
Patrick Mezard <pmezard@gmail.com>
parents:
8434
diff
changeset
|
68 tree = None |
dd24488cba2d
convert/bzr: warn when source is a lightweight checkout (issue1647)
Patrick Mezard <pmezard@gmail.com>
parents:
8434
diff
changeset
|
69 branch = dir.open_branch() |
dd24488cba2d
convert/bzr: warn when source is a lightweight checkout (issue1647)
Patrick Mezard <pmezard@gmail.com>
parents:
8434
diff
changeset
|
70 if (tree is not None and tree.bzrdir.root_transport.base != |
dd24488cba2d
convert/bzr: warn when source is a lightweight checkout (issue1647)
Patrick Mezard <pmezard@gmail.com>
parents:
8434
diff
changeset
|
71 branch.bzrdir.root_transport.base): |
dd24488cba2d
convert/bzr: warn when source is a lightweight checkout (issue1647)
Patrick Mezard <pmezard@gmail.com>
parents:
8434
diff
changeset
|
72 self.ui.warn(_('warning: lightweight checkouts may cause ' |
dd24488cba2d
convert/bzr: warn when source is a lightweight checkout (issue1647)
Patrick Mezard <pmezard@gmail.com>
parents:
8434
diff
changeset
|
73 'conversion failures, try with a regular ' |
dd24488cba2d
convert/bzr: warn when source is a lightweight checkout (issue1647)
Patrick Mezard <pmezard@gmail.com>
parents:
8434
diff
changeset
|
74 'branch instead.\n')) |
16689
f366d4c2ff34
cleanup: replace naked excepts with except Exception: ...
Brodie Rao <brodie@sf.io>
parents:
16099
diff
changeset
|
75 except Exception: |
8470
dd24488cba2d
convert/bzr: warn when source is a lightweight checkout (issue1647)
Patrick Mezard <pmezard@gmail.com>
parents:
8434
diff
changeset
|
76 self.ui.note(_('bzr source type could not be determined\n')) |
dd24488cba2d
convert/bzr: warn when source is a lightweight checkout (issue1647)
Patrick Mezard <pmezard@gmail.com>
parents:
8434
diff
changeset
|
77 |
7053 | 78 def before(self): |
79 """Before the conversion begins, acquire a read lock | |
80 for all the operations that might need it. Fortunately | |
81 read locks don't block other reads or writes to the | |
82 repository, so this shouldn't have any impact on the usage of | |
83 the source repository. | |
84 | |
85 The alternative would be locking on every operation that | |
86 needs locks (there are currently two: getting the file and | |
87 getting the parent map) and releasing immediately after, | |
88 but this approach can take even 40% longer.""" | |
89 self.sourcerepo.lock_read() | |
90 | |
91 def after(self): | |
92 self.sourcerepo.unlock() | |
93 | |
16099
4e4c416a0b1f
convert/bzr: ignore nested repos when listing branches (issue3254)
Patrick Mezard <patrick@mezard.eu>
parents:
16061
diff
changeset
|
94 def _bzrbranches(self): |
4e4c416a0b1f
convert/bzr: ignore nested repos when listing branches (issue3254)
Patrick Mezard <patrick@mezard.eu>
parents:
16061
diff
changeset
|
95 return self.sourcerepo.find_branches(using=True) |
4e4c416a0b1f
convert/bzr: ignore nested repos when listing branches (issue3254)
Patrick Mezard <patrick@mezard.eu>
parents:
16061
diff
changeset
|
96 |
7053 | 97 def getheads(self): |
98 if not self.rev: | |
16099
4e4c416a0b1f
convert/bzr: ignore nested repos when listing branches (issue3254)
Patrick Mezard <patrick@mezard.eu>
parents:
16061
diff
changeset
|
99 # Set using=True to avoid nested repositories (see issue3254) |
4e4c416a0b1f
convert/bzr: ignore nested repos when listing branches (issue3254)
Patrick Mezard <patrick@mezard.eu>
parents:
16061
diff
changeset
|
100 heads = sorted([b.last_revision() for b in self._bzrbranches()]) |
16060
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
101 else: |
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
102 revid = None |
16099
4e4c416a0b1f
convert/bzr: ignore nested repos when listing branches (issue3254)
Patrick Mezard <patrick@mezard.eu>
parents:
16061
diff
changeset
|
103 for branch in self._bzrbranches(): |
16060
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
104 try: |
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
105 r = RevisionSpec.from_string(self.rev) |
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
106 info = r.in_history(branch) |
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
107 except errors.BzrError: |
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
108 pass |
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
109 revid = info.rev_id |
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
110 if revid is None: |
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
111 raise util.Abort(_('%s is not a valid revision') % self.rev) |
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
112 heads = [revid] |
16061
915e06faa8f3
convert/bzr: handle empty bzr repositories (issue3233)
Patrick Mezard <pmezard@gmail.com>
parents:
16060
diff
changeset
|
113 # Empty repositories return 'null:', which cannot be retrieved |
915e06faa8f3
convert/bzr: handle empty bzr repositories (issue3233)
Patrick Mezard <pmezard@gmail.com>
parents:
16060
diff
changeset
|
114 heads = [h for h in heads if h != 'null:'] |
16060
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
115 return heads |
7053 | 116 |
117 def getfile(self, name, rev): | |
118 revtree = self.sourcerepo.revision_tree(rev) | |
8783
6556d4145122
bzr convert: restore paths to source encoding. Closes issue1692.
Brendan Cully <brendan@kublai.com>
parents:
8423
diff
changeset
|
119 fileid = revtree.path2id(name.decode(self.encoding or 'utf-8')) |
8423
eb7be0e752d9
convert/bzr: fix symlinks target (issue1626/2)
Patrick Mezard <pmezard@gmail.com>
parents:
8165
diff
changeset
|
120 kind = None |
eb7be0e752d9
convert/bzr: fix symlinks target (issue1626/2)
Patrick Mezard <pmezard@gmail.com>
parents:
8165
diff
changeset
|
121 if fileid is not None: |
eb7be0e752d9
convert/bzr: fix symlinks target (issue1626/2)
Patrick Mezard <pmezard@gmail.com>
parents:
8165
diff
changeset
|
122 kind = revtree.kind(fileid) |
eb7be0e752d9
convert/bzr: fix symlinks target (issue1626/2)
Patrick Mezard <pmezard@gmail.com>
parents:
8165
diff
changeset
|
123 if kind not in supportedkinds: |
7053 | 124 # the file is not available anymore - was deleted |
125 raise IOError(_('%s is not available in %s anymore') % | |
126 (name, rev)) | |
11134
33010ff1fd6f
convert: merge sources getmode() into getfile()
Patrick Mezard <pmezard@gmail.com>
parents:
10939
diff
changeset
|
127 mode = self._modecache[(name, rev)] |
8423
eb7be0e752d9
convert/bzr: fix symlinks target (issue1626/2)
Patrick Mezard <pmezard@gmail.com>
parents:
8165
diff
changeset
|
128 if kind == 'symlink': |
eb7be0e752d9
convert/bzr: fix symlinks target (issue1626/2)
Patrick Mezard <pmezard@gmail.com>
parents:
8165
diff
changeset
|
129 target = revtree.get_symlink_target(fileid) |
eb7be0e752d9
convert/bzr: fix symlinks target (issue1626/2)
Patrick Mezard <pmezard@gmail.com>
parents:
8165
diff
changeset
|
130 if target is None: |
eb7be0e752d9
convert/bzr: fix symlinks target (issue1626/2)
Patrick Mezard <pmezard@gmail.com>
parents:
8165
diff
changeset
|
131 raise util.Abort(_('%s.%s symlink has no target') |
eb7be0e752d9
convert/bzr: fix symlinks target (issue1626/2)
Patrick Mezard <pmezard@gmail.com>
parents:
8165
diff
changeset
|
132 % (name, rev)) |
11134
33010ff1fd6f
convert: merge sources getmode() into getfile()
Patrick Mezard <pmezard@gmail.com>
parents:
10939
diff
changeset
|
133 return target, mode |
8423
eb7be0e752d9
convert/bzr: fix symlinks target (issue1626/2)
Patrick Mezard <pmezard@gmail.com>
parents:
8165
diff
changeset
|
134 else: |
eb7be0e752d9
convert/bzr: fix symlinks target (issue1626/2)
Patrick Mezard <pmezard@gmail.com>
parents:
8165
diff
changeset
|
135 sio = revtree.get_file(fileid) |
11134
33010ff1fd6f
convert: merge sources getmode() into getfile()
Patrick Mezard <pmezard@gmail.com>
parents:
10939
diff
changeset
|
136 return sio.read(), mode |
7053 | 137 |
138 def getchanges(self, version): | |
139 # set up caches: modecache and revtree | |
140 self._modecache = {} | |
141 self._revtree = self.sourcerepo.revision_tree(version) | |
142 # get the parentids from the cache | |
143 parentids = self._parentids.pop(version) | |
144 # only diff against first parent id | |
145 prevtree = self.sourcerepo.revision_tree(parentids[0]) | |
146 return self._gettreechanges(self._revtree, prevtree) | |
147 | |
148 def getcommit(self, version): | |
149 rev = self.sourcerepo.get_revision(version) | |
150 # populate parent id cache | |
151 if not rev.parent_ids: | |
152 parents = [] | |
153 self._parentids[version] = (revision.NULL_REVISION,) | |
154 else: | |
155 parents = self._filterghosts(rev.parent_ids) | |
156 self._parentids[version] = parents | |
157 | |
16060
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
158 branch = self.recode(rev.properties.get('branch-nick', u'default')) |
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
159 if branch == 'trunk': |
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
160 branch = 'default' |
7053 | 161 return commit(parents=parents, |
8305
7a0fcdd3828f
convert/bzr: handle Bazaar timestamps correctly (issue1652).
Greg Ward <greg-hg@gerg.ca>
parents:
8250
diff
changeset
|
162 date='%d %d' % (rev.timestamp, -rev.timezone), |
7053 | 163 author=self.recode(rev.committer), |
164 desc=self.recode(rev.message), | |
16060
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
165 branch=branch, |
7053 | 166 rev=version) |
167 | |
168 def gettags(self): | |
169 bytetags = {} | |
16099
4e4c416a0b1f
convert/bzr: ignore nested repos when listing branches (issue3254)
Patrick Mezard <patrick@mezard.eu>
parents:
16061
diff
changeset
|
170 for branch in self._bzrbranches(): |
16060
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
171 if not branch.supports_tags(): |
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
172 return {} |
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
173 tagdict = branch.tags.get_tag_dict() |
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
174 for name, rev in tagdict.iteritems(): |
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
175 bytetags[self.recode(name)] = rev |
7053 | 176 return bytetags |
177 | |
178 def getchangedfiles(self, rev, i): | |
179 self._modecache = {} | |
180 curtree = self.sourcerepo.revision_tree(rev) | |
181 if i is not None: | |
8165
78658990c725
convert/bzr: make it work with filemaps (issue1631)
Patrick Mezard <pmezard@gmail.com>
parents:
8148
diff
changeset
|
182 parentid = self._parentids[rev][i] |
7053 | 183 else: |
184 # no parent id, get the empty revision | |
185 parentid = revision.NULL_REVISION | |
186 | |
187 prevtree = self.sourcerepo.revision_tree(parentid) | |
188 changes = [e[0] for e in self._gettreechanges(curtree, prevtree)[0]] | |
189 return changes | |
190 | |
191 def _gettreechanges(self, current, origin): | |
10394
4612cded5176
fix coding style (reported by pylint)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
192 revid = current._revision_id |
7053 | 193 changes = [] |
194 renames = {} | |
15461
6ba2fc0a87ab
convert/bzr: correctly handle divergent nested renames (issue3089)
Patrick Mezard <pmezard@gmail.com>
parents:
12063
diff
changeset
|
195 seen = set() |
6ba2fc0a87ab
convert/bzr: correctly handle divergent nested renames (issue3089)
Patrick Mezard <pmezard@gmail.com>
parents:
12063
diff
changeset
|
196 # Process the entries by reverse lexicographic name order to |
6ba2fc0a87ab
convert/bzr: correctly handle divergent nested renames (issue3089)
Patrick Mezard <pmezard@gmail.com>
parents:
12063
diff
changeset
|
197 # handle nested renames correctly, most specific first. |
6ba2fc0a87ab
convert/bzr: correctly handle divergent nested renames (issue3089)
Patrick Mezard <pmezard@gmail.com>
parents:
12063
diff
changeset
|
198 curchanges = sorted(current.iter_changes(origin), |
6ba2fc0a87ab
convert/bzr: correctly handle divergent nested renames (issue3089)
Patrick Mezard <pmezard@gmail.com>
parents:
12063
diff
changeset
|
199 key=lambda c: c[1][0] or c[1][1], |
6ba2fc0a87ab
convert/bzr: correctly handle divergent nested renames (issue3089)
Patrick Mezard <pmezard@gmail.com>
parents:
12063
diff
changeset
|
200 reverse=True) |
7053 | 201 for (fileid, paths, changed_content, versioned, parent, name, |
15461
6ba2fc0a87ab
convert/bzr: correctly handle divergent nested renames (issue3089)
Patrick Mezard <pmezard@gmail.com>
parents:
12063
diff
changeset
|
202 kind, executable) in curchanges: |
7053 | 203 |
204 if paths[0] == u'' or paths[1] == u'': | |
205 # ignore changes to tree root | |
206 continue | |
207 | |
208 # bazaar tracks directories, mercurial does not, so | |
209 # we have to rename the directory contents | |
210 if kind[1] == 'directory': | |
8126
13b36eb14324
convert/bzr: handle files replaced by directories (issue1623)
Patrick Mezard <pmezard@gmail.com>
parents:
8045
diff
changeset
|
211 if kind[0] not in (None, 'directory'): |
13b36eb14324
convert/bzr: handle files replaced by directories (issue1623)
Patrick Mezard <pmezard@gmail.com>
parents:
8045
diff
changeset
|
212 # Replacing 'something' with a directory, record it |
13b36eb14324
convert/bzr: handle files replaced by directories (issue1623)
Patrick Mezard <pmezard@gmail.com>
parents:
8045
diff
changeset
|
213 # so it can be removed. |
13b36eb14324
convert/bzr: handle files replaced by directories (issue1623)
Patrick Mezard <pmezard@gmail.com>
parents:
8045
diff
changeset
|
214 changes.append((self.recode(paths[0]), revid)) |
13b36eb14324
convert/bzr: handle files replaced by directories (issue1623)
Patrick Mezard <pmezard@gmail.com>
parents:
8045
diff
changeset
|
215 |
15461
6ba2fc0a87ab
convert/bzr: correctly handle divergent nested renames (issue3089)
Patrick Mezard <pmezard@gmail.com>
parents:
12063
diff
changeset
|
216 if kind[0] == 'directory' and None not in paths: |
6ba2fc0a87ab
convert/bzr: correctly handle divergent nested renames (issue3089)
Patrick Mezard <pmezard@gmail.com>
parents:
12063
diff
changeset
|
217 renaming = paths[0] != paths[1] |
7053 | 218 # neither an add nor an delete - a move |
219 # rename all directory contents manually | |
220 subdir = origin.inventory.path2id(paths[0]) | |
221 # get all child-entries of the directory | |
222 for name, entry in origin.inventory.iter_entries(subdir): | |
223 # hg does not track directory renames | |
224 if entry.kind == 'directory': | |
225 continue | |
226 frompath = self.recode(paths[0] + '/' + name) | |
15461
6ba2fc0a87ab
convert/bzr: correctly handle divergent nested renames (issue3089)
Patrick Mezard <pmezard@gmail.com>
parents:
12063
diff
changeset
|
227 if frompath in seen: |
6ba2fc0a87ab
convert/bzr: correctly handle divergent nested renames (issue3089)
Patrick Mezard <pmezard@gmail.com>
parents:
12063
diff
changeset
|
228 # Already handled by a more specific change entry |
6ba2fc0a87ab
convert/bzr: correctly handle divergent nested renames (issue3089)
Patrick Mezard <pmezard@gmail.com>
parents:
12063
diff
changeset
|
229 # This is important when you have: |
6ba2fc0a87ab
convert/bzr: correctly handle divergent nested renames (issue3089)
Patrick Mezard <pmezard@gmail.com>
parents:
12063
diff
changeset
|
230 # a => b |
6ba2fc0a87ab
convert/bzr: correctly handle divergent nested renames (issue3089)
Patrick Mezard <pmezard@gmail.com>
parents:
12063
diff
changeset
|
231 # a/c => a/c |
6ba2fc0a87ab
convert/bzr: correctly handle divergent nested renames (issue3089)
Patrick Mezard <pmezard@gmail.com>
parents:
12063
diff
changeset
|
232 # Here a/c must not be renamed into b/c |
6ba2fc0a87ab
convert/bzr: correctly handle divergent nested renames (issue3089)
Patrick Mezard <pmezard@gmail.com>
parents:
12063
diff
changeset
|
233 continue |
6ba2fc0a87ab
convert/bzr: correctly handle divergent nested renames (issue3089)
Patrick Mezard <pmezard@gmail.com>
parents:
12063
diff
changeset
|
234 seen.add(frompath) |
6ba2fc0a87ab
convert/bzr: correctly handle divergent nested renames (issue3089)
Patrick Mezard <pmezard@gmail.com>
parents:
12063
diff
changeset
|
235 if not renaming: |
6ba2fc0a87ab
convert/bzr: correctly handle divergent nested renames (issue3089)
Patrick Mezard <pmezard@gmail.com>
parents:
12063
diff
changeset
|
236 continue |
7053 | 237 topath = self.recode(paths[1] + '/' + name) |
238 # register the files as changed | |
239 changes.append((frompath, revid)) | |
240 changes.append((topath, revid)) | |
241 # add to mode cache | |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
242 mode = ((entry.executable and 'x') |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
243 or (entry.kind == 'symlink' and 's') |
7053 | 244 or '') |
245 self._modecache[(topath, revid)] = mode | |
246 # register the change as move | |
247 renames[topath] = frompath | |
248 | |
17424
e7cfe3587ea4
fix trivial spelling errors
Mads Kiilerich <mads@kiilerich.com>
parents:
16689
diff
changeset
|
249 # no further changes, go to the next change |
7053 | 250 continue |
251 | |
252 # we got unicode paths, need to convert them | |
16059
f5b6046f6ce8
convert/bzr: expect unicode metadata, encode in UTF-8 (issue3232)
Patrick Mezard <pmezard@gmail.com>
parents:
15461
diff
changeset
|
253 path, topath = paths |
f5b6046f6ce8
convert/bzr: expect unicode metadata, encode in UTF-8 (issue3232)
Patrick Mezard <pmezard@gmail.com>
parents:
15461
diff
changeset
|
254 if path is not None: |
f5b6046f6ce8
convert/bzr: expect unicode metadata, encode in UTF-8 (issue3232)
Patrick Mezard <pmezard@gmail.com>
parents:
15461
diff
changeset
|
255 path = self.recode(path) |
f5b6046f6ce8
convert/bzr: expect unicode metadata, encode in UTF-8 (issue3232)
Patrick Mezard <pmezard@gmail.com>
parents:
15461
diff
changeset
|
256 if topath is not None: |
f5b6046f6ce8
convert/bzr: expect unicode metadata, encode in UTF-8 (issue3232)
Patrick Mezard <pmezard@gmail.com>
parents:
15461
diff
changeset
|
257 topath = self.recode(topath) |
15461
6ba2fc0a87ab
convert/bzr: correctly handle divergent nested renames (issue3089)
Patrick Mezard <pmezard@gmail.com>
parents:
12063
diff
changeset
|
258 seen.add(path or topath) |
7053 | 259 |
260 if topath is None: | |
261 # file deleted | |
262 changes.append((path, revid)) | |
263 continue | |
264 | |
265 # renamed | |
266 if path and path != topath: | |
267 renames[topath] = path | |
8035
cb77c0fbec39
convert: remove renamed source files (issue1505)
Xavier ALT <dex@phoenix-ind.net>
parents:
7060
diff
changeset
|
268 changes.append((path, revid)) |
7053 | 269 |
270 # populate the mode cache | |
271 kind, executable = [e[1] for e in (kind, executable)] | |
8148
adce97d28389
convert/bzr: fix symlink handling (issue1626)
Patrick Mezard <pmezard@gmail.com>
parents:
8126
diff
changeset
|
272 mode = ((executable and 'x') or (kind == 'symlink' and 'l') |
7053 | 273 or '') |
274 self._modecache[(topath, revid)] = mode | |
275 changes.append((topath, revid)) | |
276 | |
277 return changes, renames | |
278 | |
279 def _filterghosts(self, ids): | |
280 """Filters out ghost revisions which hg does not support, see | |
281 <http://bazaar-vcs.org/GhostRevision> | |
282 """ | |
283 parentmap = self.sourcerepo.get_parent_map(ids) | |
7060
972cce34f345
convert: fixed python2.3 incompatibility in bzr source (generator expression)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7053
diff
changeset
|
284 parents = tuple([parent for parent in ids if parent in parentmap]) |
7053 | 285 return parents |