Mercurial > hg
annotate hgext/convert/bzr.py @ 47995:e7d0a511965c
dirstate: drop the `_addpath` method
All user have been migrated.
Differential Revision: https://phab.mercurial-scm.org/D11435
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Wed, 15 Sep 2021 12:38:56 +0200 |
parents | 3b2d080f11b5 |
children | 6000f5b25c9b |
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 |
47377
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
8 # This module is for handling Breezy imports or `brz`, but it's also compatible |
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
9 # with Bazaar or `bzr`, that was formerly known as Bazaar-NG; |
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
10 # it cannot access `bar` repositories, but they were never used very much. |
28411
098bb5660580
convert: bzr use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
11 from __future__ import absolute_import |
7053 | 12 |
13 import os | |
29205
a0939666b836
py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents:
28479
diff
changeset
|
14 |
a0939666b836
py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents:
28479
diff
changeset
|
15 from mercurial.i18n import _ |
43105
649d3ac37a12
py3: define and use pycompat.iteritems() for hgext/
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43077
diff
changeset
|
16 from mercurial import ( |
649d3ac37a12
py3: define and use pycompat.iteritems() for hgext/
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43077
diff
changeset
|
17 demandimport, |
649d3ac37a12
py3: define and use pycompat.iteritems() for hgext/
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43077
diff
changeset
|
18 error, |
649d3ac37a12
py3: define and use pycompat.iteritems() for hgext/
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43077
diff
changeset
|
19 pycompat, |
47632
3b2d080f11b5
windows: use abspath in convert.bzr
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47377
diff
changeset
|
20 util, |
43105
649d3ac37a12
py3: define and use pycompat.iteritems() for hgext/
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43077
diff
changeset
|
21 ) |
28411
098bb5660580
convert: bzr use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
22 from . import common |
098bb5660580
convert: bzr use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
23 |
47377
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
24 |
7053 | 25 # these do not work with demandimport, blacklist |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38572
diff
changeset
|
26 demandimport.IGNORES.update( |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43105
diff
changeset
|
27 [ |
47377
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
28 b'breezy.transactions', |
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
29 b'breezy.urlutils', |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43105
diff
changeset
|
30 b'ElementPath', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43105
diff
changeset
|
31 ] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38572
diff
changeset
|
32 ) |
7053 | 33 |
34 try: | |
35 # bazaar imports | |
47377
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
36 import breezy.bzr.bzrdir |
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
37 import breezy.errors |
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
38 import breezy.revision |
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
39 import breezy.revisionspec |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38572
diff
changeset
|
40 |
47377
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
41 bzrdir = breezy.bzr.bzrdir |
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
42 errors = breezy.errors |
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
43 revision = breezy.revision |
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
44 revisionspec = breezy.revisionspec |
34488
6bda8a9d8431
convert: fix the RevisionSpec import in the bzr module
Saurabh Singh <singhsrb@fb.com>
parents:
29612
diff
changeset
|
45 revisionspec.RevisionSpec |
7053 | 46 except ImportError: |
47 pass | |
48 | |
47377
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
49 supportedkinds = ('file', 'symlink') |
8045
e09a2f2ef85d
convert/bzr: fix file rename replaced by a dir case (issue1583)
Patrick Mezard <pmezard@gmail.com>
parents:
8035
diff
changeset
|
50 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38572
diff
changeset
|
51 |
28411
098bb5660580
convert: bzr use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
52 class bzr_source(common.converter_source): |
7053 | 53 """Reads Bazaar repositories by using the Bazaar Python libraries""" |
54 | |
35176
671aba341d90
convert: save an indicator of the repo type for sources and sinks
Matt Harbison <matt_harbison@yahoo.com>
parents:
34488
diff
changeset
|
55 def __init__(self, ui, repotype, path, revs=None): |
671aba341d90
convert: save an indicator of the repo type for sources and sinks
Matt Harbison <matt_harbison@yahoo.com>
parents:
34488
diff
changeset
|
56 super(bzr_source, self).__init__(ui, repotype, path, revs=revs) |
7053 | 57 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
58 if not os.path.exists(os.path.join(path, b'.bzr')): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38572
diff
changeset
|
59 raise common.NoRepo( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
60 _(b'%s does not look like a Bazaar repository') % path |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38572
diff
changeset
|
61 ) |
7973
db3a68fd9387
convert: attempt to check repo type before checking for tool
Matt Mackall <mpm@selenic.com>
parents:
7060
diff
changeset
|
62 |
7053 | 63 try: |
47377
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
64 # access breezy stuff |
16060
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
65 bzrdir |
7053 | 66 except NameError: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
67 raise common.NoRepo(_(b'Bazaar modules could not be loaded')) |
7053 | 68 |
47632
3b2d080f11b5
windows: use abspath in convert.bzr
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47377
diff
changeset
|
69 path = util.abspath(path) |
8470
dd24488cba2d
convert/bzr: warn when source is a lightweight checkout (issue1647)
Patrick Mezard <pmezard@gmail.com>
parents:
8434
diff
changeset
|
70 self._checkrepotype(path) |
16060
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
71 try: |
47377
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
72 bzr_dir = bzrdir.BzrDir.open(path.decode()) |
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
73 self.sourcerepo = bzr_dir.open_repository() |
16060
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
74 except errors.NoRepositoryPresent: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38572
diff
changeset
|
75 raise common.NoRepo( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
76 _(b'%s does not look like a Bazaar repository') % path |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38572
diff
changeset
|
77 ) |
7053 | 78 self._parentids = {} |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
79 self._saverev = ui.configbool(b'convert', b'bzr.saverev') |
7053 | 80 |
8470
dd24488cba2d
convert/bzr: warn when source is a lightweight checkout (issue1647)
Patrick Mezard <pmezard@gmail.com>
parents:
8434
diff
changeset
|
81 def _checkrepotype(self, path): |
dd24488cba2d
convert/bzr: warn when source is a lightweight checkout (issue1647)
Patrick Mezard <pmezard@gmail.com>
parents:
8434
diff
changeset
|
82 # 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
|
83 # 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
|
84 try: |
47377
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
85 dir = bzrdir.BzrDir.open_containing(path.decode())[0] |
8470
dd24488cba2d
convert/bzr: warn when source is a lightweight checkout (issue1647)
Patrick Mezard <pmezard@gmail.com>
parents:
8434
diff
changeset
|
86 try: |
dd24488cba2d
convert/bzr: warn when source is a lightweight checkout (issue1647)
Patrick Mezard <pmezard@gmail.com>
parents:
8434
diff
changeset
|
87 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
|
88 branch = tree.branch |
12063
516b000fbb7e
cleanup: remove unused variables
Brodie Rao <brodie@bitheap.org>
parents:
11134
diff
changeset
|
89 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
|
90 tree = None |
dd24488cba2d
convert/bzr: warn when source is a lightweight checkout (issue1647)
Patrick Mezard <pmezard@gmail.com>
parents:
8434
diff
changeset
|
91 branch = dir.open_branch() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38572
diff
changeset
|
92 if ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38572
diff
changeset
|
93 tree is not None |
47377
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
94 and tree.controldir.root_transport.base |
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
95 != branch.controldir.root_transport.base |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38572
diff
changeset
|
96 ): |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38572
diff
changeset
|
97 self.ui.warn( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38572
diff
changeset
|
98 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
99 b'warning: lightweight checkouts may cause ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
100 b'conversion failures, try with a regular ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
101 b'branch instead.\n' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38572
diff
changeset
|
102 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38572
diff
changeset
|
103 ) |
16689
f366d4c2ff34
cleanup: replace naked excepts with except Exception: ...
Brodie Rao <brodie@sf.io>
parents:
16099
diff
changeset
|
104 except Exception: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
105 self.ui.note(_(b'bzr source type could not be determined\n')) |
8470
dd24488cba2d
convert/bzr: warn when source is a lightweight checkout (issue1647)
Patrick Mezard <pmezard@gmail.com>
parents:
8434
diff
changeset
|
106 |
7053 | 107 def before(self): |
108 """Before the conversion begins, acquire a read lock | |
109 for all the operations that might need it. Fortunately | |
110 read locks don't block other reads or writes to the | |
111 repository, so this shouldn't have any impact on the usage of | |
112 the source repository. | |
113 | |
114 The alternative would be locking on every operation that | |
115 needs locks (there are currently two: getting the file and | |
116 getting the parent map) and releasing immediately after, | |
117 but this approach can take even 40% longer.""" | |
118 self.sourcerepo.lock_read() | |
119 | |
120 def after(self): | |
121 self.sourcerepo.unlock() | |
122 | |
16099
4e4c416a0b1f
convert/bzr: ignore nested repos when listing branches (issue3254)
Patrick Mezard <patrick@mezard.eu>
parents:
16061
diff
changeset
|
123 def _bzrbranches(self): |
4e4c416a0b1f
convert/bzr: ignore nested repos when listing branches (issue3254)
Patrick Mezard <patrick@mezard.eu>
parents:
16061
diff
changeset
|
124 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
|
125 |
7053 | 126 def getheads(self): |
25748
baea47cafe75
convert: add support for specifying multiple revs
Durham Goode <durham@fb.com>
parents:
24395
diff
changeset
|
127 if not self.revs: |
16099
4e4c416a0b1f
convert/bzr: ignore nested repos when listing branches (issue3254)
Patrick Mezard <patrick@mezard.eu>
parents:
16061
diff
changeset
|
128 # 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
|
129 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
|
130 else: |
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
131 revid = None |
16099
4e4c416a0b1f
convert/bzr: ignore nested repos when listing branches (issue3254)
Patrick Mezard <patrick@mezard.eu>
parents:
16061
diff
changeset
|
132 for branch in self._bzrbranches(): |
16060
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
133 try: |
47377
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
134 revspec = self.revs[0].decode() |
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
135 r = revisionspec.RevisionSpec.from_string(revspec) |
16060
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
136 info = r.in_history(branch) |
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
137 except errors.BzrError: |
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
138 pass |
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
139 revid = info.rev_id |
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
140 if revid is None: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38572
diff
changeset
|
141 raise error.Abort( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
142 _(b'%s is not a valid revision') % self.revs[0] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38572
diff
changeset
|
143 ) |
16060
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
144 heads = [revid] |
16061
915e06faa8f3
convert/bzr: handle empty bzr repositories (issue3233)
Patrick Mezard <pmezard@gmail.com>
parents:
16060
diff
changeset
|
145 # Empty repositories return 'null:', which cannot be retrieved |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
146 heads = [h for h in heads if h != b'null:'] |
16060
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
147 return heads |
7053 | 148 |
149 def getfile(self, name, rev): | |
47377
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
150 name = name.decode() |
7053 | 151 revtree = self.sourcerepo.revision_tree(rev) |
47377
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
152 |
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
153 try: |
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
154 kind = revtree.kind(name) |
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
155 except breezy.errors.NoSuchFile: |
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
156 return None, None |
8423
eb7be0e752d9
convert/bzr: fix symlinks target (issue1626/2)
Patrick Mezard <pmezard@gmail.com>
parents:
8165
diff
changeset
|
157 if kind not in supportedkinds: |
7053 | 158 # the file is not available anymore - was deleted |
22296
650b5b6e75ed
convert: use None value for missing files instead of overloading IOError
Mads Kiilerich <madski@unity3d.com>
parents:
17424
diff
changeset
|
159 return None, None |
47377
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
160 mode = self._modecache[(name.encode(), rev)] |
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
161 if kind == 'symlink': |
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
162 target = revtree.get_symlink_target(name) |
8423
eb7be0e752d9
convert/bzr: fix symlinks target (issue1626/2)
Patrick Mezard <pmezard@gmail.com>
parents:
8165
diff
changeset
|
163 if target is None: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38572
diff
changeset
|
164 raise error.Abort( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
165 _(b'%s.%s symlink has no target') % (name, rev) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38572
diff
changeset
|
166 ) |
47377
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
167 return target.encode(), mode |
8423
eb7be0e752d9
convert/bzr: fix symlinks target (issue1626/2)
Patrick Mezard <pmezard@gmail.com>
parents:
8165
diff
changeset
|
168 else: |
47377
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
169 sio = revtree.get_file(name) |
11134
33010ff1fd6f
convert: merge sources getmode() into getfile()
Patrick Mezard <pmezard@gmail.com>
parents:
10939
diff
changeset
|
170 return sio.read(), mode |
7053 | 171 |
22300
35ab037de989
convert: introduce --full for converting all files
Mads Kiilerich <madski@unity3d.com>
parents:
22296
diff
changeset
|
172 def getchanges(self, version, full): |
35ab037de989
convert: introduce --full for converting all files
Mads Kiilerich <madski@unity3d.com>
parents:
22296
diff
changeset
|
173 if full: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
174 raise error.Abort(_(b"convert from cvs does not support --full")) |
7053 | 175 self._modecache = {} |
176 self._revtree = self.sourcerepo.revision_tree(version) | |
177 # get the parentids from the cache | |
178 parentids = self._parentids.pop(version) | |
179 # only diff against first parent id | |
180 prevtree = self.sourcerepo.revision_tree(parentids[0]) | |
24395
216fa1ba9993
convert: optimize convert of files that are unmodified from p2 in merges
Mads Kiilerich <madski@unity3d.com>
parents:
22300
diff
changeset
|
181 files, changes = self._gettreechanges(self._revtree, prevtree) |
216fa1ba9993
convert: optimize convert of files that are unmodified from p2 in merges
Mads Kiilerich <madski@unity3d.com>
parents:
22300
diff
changeset
|
182 return files, changes, set() |
7053 | 183 |
184 def getcommit(self, version): | |
185 rev = self.sourcerepo.get_revision(version) | |
186 # populate parent id cache | |
187 if not rev.parent_ids: | |
188 parents = [] | |
189 self._parentids[version] = (revision.NULL_REVISION,) | |
190 else: | |
191 parents = self._filterghosts(rev.parent_ids) | |
192 self._parentids[version] = parents | |
193 | |
47377
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
194 branch = rev.properties.get('branch-nick', 'default') |
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
195 if branch == 'trunk': |
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
196 branch = 'default' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38572
diff
changeset
|
197 return common.commit( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38572
diff
changeset
|
198 parents=parents, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
199 date=b'%d %d' % (rev.timestamp, -rev.timezone), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38572
diff
changeset
|
200 author=self.recode(rev.committer), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38572
diff
changeset
|
201 desc=self.recode(rev.message), |
47377
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
202 branch=branch.encode('utf8'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38572
diff
changeset
|
203 rev=version, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38572
diff
changeset
|
204 saverev=self._saverev, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38572
diff
changeset
|
205 ) |
7053 | 206 |
207 def gettags(self): | |
208 bytetags = {} | |
16099
4e4c416a0b1f
convert/bzr: ignore nested repos when listing branches (issue3254)
Patrick Mezard <patrick@mezard.eu>
parents:
16061
diff
changeset
|
209 for branch in self._bzrbranches(): |
16060
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
210 if not branch.supports_tags(): |
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
211 return {} |
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
212 tagdict = branch.tags.get_tag_dict() |
43105
649d3ac37a12
py3: define and use pycompat.iteritems() for hgext/
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43077
diff
changeset
|
213 for name, rev in pycompat.iteritems(tagdict): |
16060
f84dda152a55
convert/bzr: convert all branches (issue3229) (BC)
Patrick Mezard <pmezard@gmail.com>
parents:
16059
diff
changeset
|
214 bytetags[self.recode(name)] = rev |
7053 | 215 return bytetags |
216 | |
217 def getchangedfiles(self, rev, i): | |
218 self._modecache = {} | |
219 curtree = self.sourcerepo.revision_tree(rev) | |
220 if i is not None: | |
8165
78658990c725
convert/bzr: make it work with filemaps (issue1631)
Patrick Mezard <pmezard@gmail.com>
parents:
8148
diff
changeset
|
221 parentid = self._parentids[rev][i] |
7053 | 222 else: |
223 # no parent id, get the empty revision | |
224 parentid = revision.NULL_REVISION | |
225 | |
226 prevtree = self.sourcerepo.revision_tree(parentid) | |
227 changes = [e[0] for e in self._gettreechanges(curtree, prevtree)[0]] | |
228 return changes | |
229 | |
230 def _gettreechanges(self, current, origin): | |
10394
4612cded5176
fix coding style (reported by pylint)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
231 revid = current._revision_id |
7053 | 232 changes = [] |
233 renames = {} | |
15461
6ba2fc0a87ab
convert/bzr: correctly handle divergent nested renames (issue3089)
Patrick Mezard <pmezard@gmail.com>
parents:
12063
diff
changeset
|
234 seen = set() |
35198
759234670d19
convert: restore the ability to use bzr < 2.6.0 (issue5733)
Matt Harbison <matt_harbison@yahoo.com>
parents:
34488
diff
changeset
|
235 |
759234670d19
convert: restore the ability to use bzr < 2.6.0 (issue5733)
Matt Harbison <matt_harbison@yahoo.com>
parents:
34488
diff
changeset
|
236 # Fall back to the deprecated attribute for legacy installations. |
759234670d19
convert: restore the ability to use bzr < 2.6.0 (issue5733)
Matt Harbison <matt_harbison@yahoo.com>
parents:
34488
diff
changeset
|
237 try: |
759234670d19
convert: restore the ability to use bzr < 2.6.0 (issue5733)
Matt Harbison <matt_harbison@yahoo.com>
parents:
34488
diff
changeset
|
238 inventory = origin.root_inventory |
759234670d19
convert: restore the ability to use bzr < 2.6.0 (issue5733)
Matt Harbison <matt_harbison@yahoo.com>
parents:
34488
diff
changeset
|
239 except AttributeError: |
759234670d19
convert: restore the ability to use bzr < 2.6.0 (issue5733)
Matt Harbison <matt_harbison@yahoo.com>
parents:
34488
diff
changeset
|
240 inventory = origin.inventory |
759234670d19
convert: restore the ability to use bzr < 2.6.0 (issue5733)
Matt Harbison <matt_harbison@yahoo.com>
parents:
34488
diff
changeset
|
241 |
15461
6ba2fc0a87ab
convert/bzr: correctly handle divergent nested renames (issue3089)
Patrick Mezard <pmezard@gmail.com>
parents:
12063
diff
changeset
|
242 # 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
|
243 # handle nested renames correctly, most specific first. |
47377
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
244 |
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
245 def key(c): |
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
246 return c.path[0] or c.path[1] or "" |
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
247 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38572
diff
changeset
|
248 curchanges = sorted( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38572
diff
changeset
|
249 current.iter_changes(origin), |
47377
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
250 key=key, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38572
diff
changeset
|
251 reverse=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38572
diff
changeset
|
252 ) |
47377
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
253 for change in curchanges: |
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
254 paths = change.path |
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
255 kind = change.kind |
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
256 executable = change.executable |
7053 | 257 if paths[0] == u'' or paths[1] == u'': |
258 # ignore changes to tree root | |
259 continue | |
260 | |
261 # bazaar tracks directories, mercurial does not, so | |
262 # we have to rename the directory contents | |
47377
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
263 if kind[1] == 'directory': |
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
264 if kind[0] not in (None, 'directory'): |
8126
13b36eb14324
convert/bzr: handle files replaced by directories (issue1623)
Patrick Mezard <pmezard@gmail.com>
parents:
8045
diff
changeset
|
265 # 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
|
266 # so it can be removed. |
13b36eb14324
convert/bzr: handle files replaced by directories (issue1623)
Patrick Mezard <pmezard@gmail.com>
parents:
8045
diff
changeset
|
267 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
|
268 |
47377
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
269 if kind[0] == 'directory' and None not in paths: |
15461
6ba2fc0a87ab
convert/bzr: correctly handle divergent nested renames (issue3089)
Patrick Mezard <pmezard@gmail.com>
parents:
12063
diff
changeset
|
270 renaming = paths[0] != paths[1] |
7053 | 271 # neither an add nor an delete - a move |
272 # rename all directory contents manually | |
35198
759234670d19
convert: restore the ability to use bzr < 2.6.0 (issue5733)
Matt Harbison <matt_harbison@yahoo.com>
parents:
34488
diff
changeset
|
273 subdir = inventory.path2id(paths[0]) |
7053 | 274 # get all child-entries of the directory |
35198
759234670d19
convert: restore the ability to use bzr < 2.6.0 (issue5733)
Matt Harbison <matt_harbison@yahoo.com>
parents:
34488
diff
changeset
|
275 for name, entry in inventory.iter_entries(subdir): |
7053 | 276 # hg does not track directory renames |
47377
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
277 if entry.kind == 'directory': |
7053 | 278 continue |
47377
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
279 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
|
280 if frompath in seen: |
6ba2fc0a87ab
convert/bzr: correctly handle divergent nested renames (issue3089)
Patrick Mezard <pmezard@gmail.com>
parents:
12063
diff
changeset
|
281 # 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
|
282 # This is important when you have: |
6ba2fc0a87ab
convert/bzr: correctly handle divergent nested renames (issue3089)
Patrick Mezard <pmezard@gmail.com>
parents:
12063
diff
changeset
|
283 # a => b |
6ba2fc0a87ab
convert/bzr: correctly handle divergent nested renames (issue3089)
Patrick Mezard <pmezard@gmail.com>
parents:
12063
diff
changeset
|
284 # a/c => a/c |
6ba2fc0a87ab
convert/bzr: correctly handle divergent nested renames (issue3089)
Patrick Mezard <pmezard@gmail.com>
parents:
12063
diff
changeset
|
285 # 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
|
286 continue |
6ba2fc0a87ab
convert/bzr: correctly handle divergent nested renames (issue3089)
Patrick Mezard <pmezard@gmail.com>
parents:
12063
diff
changeset
|
287 seen.add(frompath) |
6ba2fc0a87ab
convert/bzr: correctly handle divergent nested renames (issue3089)
Patrick Mezard <pmezard@gmail.com>
parents:
12063
diff
changeset
|
288 if not renaming: |
6ba2fc0a87ab
convert/bzr: correctly handle divergent nested renames (issue3089)
Patrick Mezard <pmezard@gmail.com>
parents:
12063
diff
changeset
|
289 continue |
47377
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
290 topath = self.recode(paths[1] + '/' + name) |
7053 | 291 # register the files as changed |
292 changes.append((frompath, revid)) | |
293 changes.append((topath, revid)) | |
294 # add to mode cache | |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38572
diff
changeset
|
295 mode = ( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
296 (entry.executable and b'x') |
47377
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
297 or (entry.kind == 'symlink' and b's') |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
298 or b'' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38572
diff
changeset
|
299 ) |
7053 | 300 self._modecache[(topath, revid)] = mode |
301 # register the change as move | |
302 renames[topath] = frompath | |
303 | |
17424
e7cfe3587ea4
fix trivial spelling errors
Mads Kiilerich <mads@kiilerich.com>
parents:
16689
diff
changeset
|
304 # no further changes, go to the next change |
7053 | 305 continue |
306 | |
307 # 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
|
308 path, topath = paths |
f5b6046f6ce8
convert/bzr: expect unicode metadata, encode in UTF-8 (issue3232)
Patrick Mezard <pmezard@gmail.com>
parents:
15461
diff
changeset
|
309 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
|
310 path = self.recode(path) |
f5b6046f6ce8
convert/bzr: expect unicode metadata, encode in UTF-8 (issue3232)
Patrick Mezard <pmezard@gmail.com>
parents:
15461
diff
changeset
|
311 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
|
312 topath = self.recode(topath) |
15461
6ba2fc0a87ab
convert/bzr: correctly handle divergent nested renames (issue3089)
Patrick Mezard <pmezard@gmail.com>
parents:
12063
diff
changeset
|
313 seen.add(path or topath) |
7053 | 314 |
315 if topath is None: | |
316 # file deleted | |
317 changes.append((path, revid)) | |
318 continue | |
319 | |
320 # renamed | |
321 if path and path != topath: | |
322 renames[topath] = path | |
8035
cb77c0fbec39
convert: remove renamed source files (issue1505)
Xavier ALT <dex@phoenix-ind.net>
parents:
7060
diff
changeset
|
323 changes.append((path, revid)) |
7053 | 324 |
325 # populate the mode cache | |
326 kind, executable = [e[1] for e in (kind, executable)] | |
47377
26127236b229
convert-bazaar: use breezy package instead of old bzr one
Raphaël Gomès <rgomes@octobus.net>
parents:
45942
diff
changeset
|
327 mode = (executable and b'x') or (kind == 'symlink' and b'l') or b'' |
7053 | 328 self._modecache[(topath, revid)] = mode |
329 changes.append((topath, revid)) | |
330 | |
331 return changes, renames | |
332 | |
333 def _filterghosts(self, ids): | |
334 """Filters out ghost revisions which hg does not support, see | |
335 <http://bazaar-vcs.org/GhostRevision> | |
336 """ | |
337 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
|
338 parents = tuple([parent for parent in ids if parent in parentmap]) |
7053 | 339 return parents |