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