bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
2052.3.2
by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical |
1 |
# Copyright (C) 2005, 2006 Canonical Ltd
|
|
1563.2.1
by Robert Collins
Merge in a variation of the versionedfile api from versioned-file. |
2 |
#
|
3 |
# Authors:
|
|
4 |
# Johan Rydberg <jrydberg@gnu.org>
|
|
5 |
#
|
|
6 |
# This program is free software; you can redistribute it and/or modify
|
|
7 |
# it under the terms of the GNU General Public License as published by
|
|
8 |
# the Free Software Foundation; either version 2 of the License, or
|
|
9 |
# (at your option) any later version.
|
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
10 |
#
|
|
1563.2.1
by Robert Collins
Merge in a variation of the versionedfile api from versioned-file. |
11 |
# This program is distributed in the hope that it will be useful,
|
12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 |
# GNU General Public License for more details.
|
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
15 |
#
|
|
1563.2.1
by Robert Collins
Merge in a variation of the versionedfile api from versioned-file. |
16 |
# You should have received a copy of the GNU General Public License
|
17 |
# along with this program; if not, write to the Free Software
|
|
18 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
19 |
||
20 |
"""Versioned text file storage api."""
|
|
21 |
||
|
1996.3.7
by John Arbash Meinel
lazy import versionedfile, late-load bzrlib.merge |
22 |
from bzrlib.lazy_import import lazy_import |
23 |
lazy_import(globals(), """ |
|
24 |
||
25 |
from bzrlib import (
|
|
26 |
errors,
|
|
|
2249.5.12
by John Arbash Meinel
Change the APIs for VersionedFile, Store, and some of Repository into utf-8 |
27 |
osutils,
|
|
2520.4.3
by Aaron Bentley
Implement plain strategy for extracting and installing multiparent diffs |
28 |
multiparent,
|
|
1996.3.7
by John Arbash Meinel
lazy import versionedfile, late-load bzrlib.merge |
29 |
tsort,
|
|
2229.2.1
by Aaron Bentley
Reject reserved ids in versiondfile, tree, branch and repository |
30 |
revision,
|
|
1996.3.7
by John Arbash Meinel
lazy import versionedfile, late-load bzrlib.merge |
31 |
ui,
|
32 |
)
|
|
|
3287.6.1
by Robert Collins
* ``VersionedFile.get_graph`` is deprecated, with no replacement method. |
33 |
from bzrlib.graph import Graph
|
|
1996.3.7
by John Arbash Meinel
lazy import versionedfile, late-load bzrlib.merge |
34 |
from bzrlib.transport.memory import MemoryTransport
|
35 |
""") |
|
36 |
||
|
2520.4.90
by Aaron Bentley
Handle \r terminated lines in Weaves properly |
37 |
from cStringIO import StringIO |
38 |
||
|
1563.2.12
by Robert Collins
Checkpointing: created InterObject to factor out common inter object worker code, added InterVersionedFile and tests to allow making join work between any versionedfile. |
39 |
from bzrlib.inter import InterObject |
|
3350.3.7
by Robert Collins
Create a registry of versioned file record adapters. |
40 |
from bzrlib.registry import Registry |
|
3287.5.2
by Robert Collins
Deprecate VersionedFile.get_parents, breaking pulling from a ghost containing knit or pack repository to weaves, which improves correctness and allows simplification of core code. |
41 |
from bzrlib.symbol_versioning import * |
|
1551.6.7
by Aaron Bentley
Implemented two-way merge, refactored weave merge |
42 |
from bzrlib.textmerge import TextMerge |
|
1563.2.11
by Robert Collins
Consolidate reweave and join as we have no separate usage, make reweave tests apply to all versionedfile implementations and deprecate the old reweave apis. |
43 |
|
44 |
||
|
3350.3.7
by Robert Collins
Create a registry of versioned file record adapters. |
45 |
adapter_registry = Registry() |
46 |
adapter_registry.register_lazy(('knit-delta-gz', 'fulltext'), 'bzrlib.knit', |
|
47 |
'DeltaPlainToFullText') |
|
48 |
adapter_registry.register_lazy(('knit-ft-gz', 'fulltext'), 'bzrlib.knit', |
|
49 |
'FTPlainToFullText') |
|
50 |
adapter_registry.register_lazy(('knit-annotated-delta-gz', 'knit-delta-gz'), |
|
51 |
'bzrlib.knit', 'DeltaAnnotatedToUnannotated') |
|
52 |
adapter_registry.register_lazy(('knit-annotated-delta-gz', 'fulltext'), |
|
53 |
'bzrlib.knit', 'DeltaAnnotatedToFullText') |
|
54 |
adapter_registry.register_lazy(('knit-annotated-ft-gz', 'knit-ft-gz'), |
|
55 |
'bzrlib.knit', 'FTAnnotatedToUnannotated') |
|
56 |
adapter_registry.register_lazy(('knit-annotated-ft-gz', 'fulltext'), |
|
57 |
'bzrlib.knit', 'FTAnnotatedToFullText') |
|
58 |
||
59 |
||
|
3350.3.3
by Robert Collins
Functional get_record_stream interface tests covering full interface. |
60 |
class ContentFactory(object): |
61 |
"""Abstract interface for insertion and retrieval from a VersionedFile. |
|
62 |
|
|
63 |
:ivar sha1: None, or the sha1 of the content fulltext.
|
|
64 |
:ivar storage_kind: The native storage kind of this factory. One of
|
|
65 |
'mpdiff', 'knit-annotated-ft', 'knit-annotated-delta', 'knit-ft',
|
|
66 |
'knit-delta', 'fulltext', 'knit-annotated-ft-gz',
|
|
67 |
'knit-annotated-delta-gz', 'knit-ft-gz', 'knit-delta-gz'.
|
|
68 |
:ivar key: The key of this content. Each key is a tuple with a single
|
|
69 |
string in it.
|
|
70 |
:ivar parents: A tuple of parent keys for self.key. If the object has
|
|
71 |
no parent information, None (as opposed to () for an empty list of
|
|
72 |
parents).
|
|
73 |
"""
|
|
74 |
||
75 |
def __init__(self): |
|
76 |
"""Create a ContentFactory.""" |
|
77 |
self.sha1 = None |
|
78 |
self.storage_kind = None |
|
79 |
self.key = None |
|
80 |
self.parents = None |
|
81 |
||
82 |
||
|
3350.3.12
by Robert Collins
Generate streams with absent records. |
83 |
class AbsentContentFactory(object): |
84 |
"""A placeholder content factory for unavailable texts. |
|
85 |
|
|
86 |
:ivar sha1: None.
|
|
87 |
:ivar storage_kind: 'absent'.
|
|
88 |
:ivar key: The key of this content. Each key is a tuple with a single
|
|
89 |
string in it.
|
|
90 |
:ivar parents: None.
|
|
91 |
"""
|
|
92 |
||
93 |
def __init__(self, key): |
|
94 |
"""Create a ContentFactory.""" |
|
95 |
self.sha1 = None |
|
96 |
self.storage_kind = 'absent' |
|
97 |
self.key = key |
|
98 |
self.parents = None |
|
99 |
||
100 |
||
|
3350.3.14
by Robert Collins
Deprecate VersionedFile.join. |
101 |
def filter_absent(record_stream): |
102 |
"""Adapt a record stream to remove absent records.""" |
|
103 |
for record in record_stream: |
|
104 |
if record.storage_kind != 'absent': |
|
105 |
yield record |
|
106 |
||
107 |
||
|
1563.2.1
by Robert Collins
Merge in a variation of the versionedfile api from versioned-file. |
108 |
class VersionedFile(object): |
109 |
"""Versioned text file storage. |
|
110 |
|
|
111 |
A versioned file manages versions of line-based text files,
|
|
112 |
keeping track of the originating version for each line.
|
|
113 |
||
114 |
To clients the "lines" of the file are represented as a list of
|
|
115 |
strings. These strings will typically have terminal newline
|
|
116 |
characters, but this is not required. In particular files commonly
|
|
117 |
do not have a newline at the end of the file.
|
|
118 |
||
119 |
Texts are identified by a version-id string.
|
|
120 |
"""
|
|
121 |
||
|
2229.2.1
by Aaron Bentley
Reject reserved ids in versiondfile, tree, branch and repository |
122 |
@staticmethod
|
|
2229.2.3
by Aaron Bentley
change reserved_id to is_reserved_id, add check_not_reserved for DRY |
123 |
def check_not_reserved_id(version_id): |
124 |
revision.check_not_reserved_id(version_id) |
|
|
2229.2.1
by Aaron Bentley
Reject reserved ids in versiondfile, tree, branch and repository |
125 |
|
|
1563.2.15
by Robert Collins
remove the weavestore assumptions about the number and nature of files it manages. |
126 |
def copy_to(self, name, transport): |
127 |
"""Copy this versioned file to name on transport.""" |
|
128 |
raise NotImplementedError(self.copy_to) |
|
|
1863.1.1
by John Arbash Meinel
Allow Versioned files to do caching if explicitly asked, and implement for Knit |
129 |
|
|
3350.3.3
by Robert Collins
Functional get_record_stream interface tests covering full interface. |
130 |
def get_record_stream(self, versions, ordering, include_delta_closure): |
131 |
"""Get a stream of records for versions. |
|
132 |
||
133 |
:param versions: The versions to include. Each version is a tuple
|
|
134 |
(version,).
|
|
135 |
:param ordering: Either 'unordered' or 'topological'. A topologically
|
|
136 |
sorted stream has compression parents strictly before their
|
|
137 |
children.
|
|
138 |
:param include_delta_closure: If True then the closure across any
|
|
|
3350.3.22
by Robert Collins
Review feedback. |
139 |
compression parents will be included (in the data content of the
|
140 |
stream, not in the emitted records). This guarantees that
|
|
141 |
'fulltext' can be used successfully on every record.
|
|
|
3350.3.3
by Robert Collins
Functional get_record_stream interface tests covering full interface. |
142 |
:return: An iterator of ContentFactory objects, each of which is only
|
143 |
valid until the iterator is advanced.
|
|
144 |
"""
|
|
145 |
raise NotImplementedError(self.get_record_stream) |
|
|
1563.2.1
by Robert Collins
Merge in a variation of the versionedfile api from versioned-file. |
146 |
|
147 |
def has_version(self, version_id): |
|
148 |
"""Returns whether version is present.""" |
|
149 |
raise NotImplementedError(self.has_version) |
|
150 |
||
|
3350.3.8
by Robert Collins
Basic stream insertion, no fast path yet for knit to knit. |
151 |
def insert_record_stream(self, stream): |
152 |
"""Insert a record stream into this versioned file. |
|
153 |
||
154 |
:param stream: A stream of records to insert.
|
|
155 |
:return: None
|
|
156 |
:seealso VersionedFile.get_record_stream:
|
|
157 |
"""
|
|
158 |
raise NotImplementedError |
|
159 |
||
|
2520.4.140
by Aaron Bentley
Use matching blocks from mpdiff for knit delta creation |
160 |
def add_lines(self, version_id, parents, lines, parent_texts=None, |
|
2805.6.7
by Robert Collins
Review feedback. |
161 |
left_matching_blocks=None, nostore_sha=None, random_id=False, |
162 |
check_content=True): |
|
|
1563.2.1
by Robert Collins
Merge in a variation of the versionedfile api from versioned-file. |
163 |
"""Add a single text on top of the versioned file. |
164 |
||
165 |
Must raise RevisionAlreadyPresent if the new version is
|
|
166 |
already present in file history.
|
|
167 |
||
168 |
Must raise RevisionNotPresent if any of the given parents are
|
|
|
1594.2.21
by Robert Collins
Teach versioned files to prevent mutation after finishing. |
169 |
not present in file history.
|
|
2805.6.3
by Robert Collins
* The ``VersionedFile`` interface no longer protects against misuse when |
170 |
|
171 |
:param lines: A list of lines. Each line must be a bytestring. And all
|
|
172 |
of them except the last must be terminated with \n and contain no
|
|
173 |
other \n's. The last line may either contain no \n's or a single
|
|
174 |
terminated \n. If the lines list does meet this constraint the add
|
|
175 |
routine may error or may succeed - but you will be unable to read
|
|
176 |
the data back accurately. (Checking the lines have been split
|
|
|
2805.6.7
by Robert Collins
Review feedback. |
177 |
correctly is expensive and extremely unlikely to catch bugs so it
|
178 |
is not done at runtime unless check_content is True.)
|
|
|
1596.2.32
by Robert Collins
Reduce re-extraction of texts during weave to knit joins by providing a memoisation facility. |
179 |
:param parent_texts: An optional dictionary containing the opaque
|
|
2805.6.3
by Robert Collins
* The ``VersionedFile`` interface no longer protects against misuse when |
180 |
representations of some or all of the parents of version_id to
|
181 |
allow delta optimisations. VERY IMPORTANT: the texts must be those
|
|
182 |
returned by add_lines or data corruption can be caused.
|
|
|
2520.4.148
by Aaron Bentley
Updates from review |
183 |
:param left_matching_blocks: a hint about which areas are common
|
184 |
between the text and its left-hand-parent. The format is
|
|
185 |
the SequenceMatcher.get_matching_blocks format.
|
|
|
2794.1.1
by Robert Collins
Allow knits to be instructed not to add a text based on a sha, for commit. |
186 |
:param nostore_sha: Raise ExistingContent and do not add the lines to
|
187 |
the versioned file if the digest of the lines matches this.
|
|
|
2805.6.4
by Robert Collins
Don't check for existing versions when adding texts with random revision ids. |
188 |
:param random_id: If True a random id has been selected rather than
|
189 |
an id determined by some deterministic process such as a converter
|
|
190 |
from a foreign VCS. When True the backend may choose not to check
|
|
191 |
for uniqueness of the resulting key within the versioned file, so
|
|
192 |
this should only be done when the result is expected to be unique
|
|
193 |
anyway.
|
|
|
2805.6.7
by Robert Collins
Review feedback. |
194 |
:param check_content: If True, the lines supplied are verified to be
|
195 |
bytestrings that are correctly formed lines.
|
|
|
2776.1.1
by Robert Collins
* The ``add_lines`` methods on ``VersionedFile`` implementations has changed |
196 |
:return: The text sha1, the number of bytes in the text, and an opaque
|
197 |
representation of the inserted version which can be provided
|
|
198 |
back to future add_lines calls in the parent_texts dictionary.
|
|
|
1594.2.21
by Robert Collins
Teach versioned files to prevent mutation after finishing. |
199 |
"""
|
|
1594.2.23
by Robert Collins
Test versioned file storage handling of clean/dirty status for accessed versioned files. |
200 |
self._check_write_ok() |
|
2520.4.140
by Aaron Bentley
Use matching blocks from mpdiff for knit delta creation |
201 |
return self._add_lines(version_id, parents, lines, parent_texts, |
|
2805.6.7
by Robert Collins
Review feedback. |
202 |
left_matching_blocks, nostore_sha, random_id, check_content) |
|
1594.2.21
by Robert Collins
Teach versioned files to prevent mutation after finishing. |
203 |
|
|
2520.4.140
by Aaron Bentley
Use matching blocks from mpdiff for knit delta creation |
204 |
def _add_lines(self, version_id, parents, lines, parent_texts, |
|
2805.6.7
by Robert Collins
Review feedback. |
205 |
left_matching_blocks, nostore_sha, random_id, check_content): |
|
1594.2.21
by Robert Collins
Teach versioned files to prevent mutation after finishing. |
206 |
"""Helper to do the class specific add_lines.""" |
|
1563.2.4
by Robert Collins
First cut at including the knit implementation of versioned_file. |
207 |
raise NotImplementedError(self.add_lines) |
|
1563.2.1
by Robert Collins
Merge in a variation of the versionedfile api from versioned-file. |
208 |
|
|
1596.2.32
by Robert Collins
Reduce re-extraction of texts during weave to knit joins by providing a memoisation facility. |
209 |
def add_lines_with_ghosts(self, version_id, parents, lines, |
|
2805.6.7
by Robert Collins
Review feedback. |
210 |
parent_texts=None, nostore_sha=None, random_id=False, |
|
3287.5.2
by Robert Collins
Deprecate VersionedFile.get_parents, breaking pulling from a ghost containing knit or pack repository to weaves, which improves correctness and allows simplification of core code. |
211 |
check_content=True, left_matching_blocks=None): |
|
1596.2.32
by Robert Collins
Reduce re-extraction of texts during weave to knit joins by providing a memoisation facility. |
212 |
"""Add lines to the versioned file, allowing ghosts to be present. |
213 |
|
|
|
2794.1.1
by Robert Collins
Allow knits to be instructed not to add a text based on a sha, for commit. |
214 |
This takes the same parameters as add_lines and returns the same.
|
|
1596.2.32
by Robert Collins
Reduce re-extraction of texts during weave to knit joins by providing a memoisation facility. |
215 |
"""
|
|
1594.2.23
by Robert Collins
Test versioned file storage handling of clean/dirty status for accessed versioned files. |
216 |
self._check_write_ok() |
|
1596.2.32
by Robert Collins
Reduce re-extraction of texts during weave to knit joins by providing a memoisation facility. |
217 |
return self._add_lines_with_ghosts(version_id, parents, lines, |
|
3287.5.2
by Robert Collins
Deprecate VersionedFile.get_parents, breaking pulling from a ghost containing knit or pack repository to weaves, which improves correctness and allows simplification of core code. |
218 |
parent_texts, nostore_sha, random_id, check_content, left_matching_blocks) |
|
1594.2.21
by Robert Collins
Teach versioned files to prevent mutation after finishing. |
219 |
|
|
2794.1.1
by Robert Collins
Allow knits to be instructed not to add a text based on a sha, for commit. |
220 |
def _add_lines_with_ghosts(self, version_id, parents, lines, parent_texts, |
|
3287.5.2
by Robert Collins
Deprecate VersionedFile.get_parents, breaking pulling from a ghost containing knit or pack repository to weaves, which improves correctness and allows simplification of core code. |
221 |
nostore_sha, random_id, check_content, left_matching_blocks): |
|
1594.2.21
by Robert Collins
Teach versioned files to prevent mutation after finishing. |
222 |
"""Helper to do class specific add_lines_with_ghosts.""" |
|
1594.2.8
by Robert Collins
add ghost aware apis to knits. |
223 |
raise NotImplementedError(self.add_lines_with_ghosts) |
224 |
||
|
1563.2.19
by Robert Collins
stub out a check for knits. |
225 |
def check(self, progress_bar=None): |
226 |
"""Check the versioned file for integrity.""" |
|
227 |
raise NotImplementedError(self.check) |
|
228 |
||
|
1666.1.6
by Robert Collins
Make knit the default format. |
229 |
def _check_lines_not_unicode(self, lines): |
230 |
"""Check that lines being added to a versioned file are not unicode.""" |
|
231 |
for line in lines: |
|
232 |
if line.__class__ is not str: |
|
233 |
raise errors.BzrBadParameterUnicode("lines") |
|
234 |
||
235 |
def _check_lines_are_lines(self, lines): |
|
236 |
"""Check that the lines really are full lines without inline EOL.""" |
|
237 |
for line in lines: |
|
238 |
if '\n' in line[:-1]: |
|
239 |
raise errors.BzrBadParameterContainsNewline("lines") |
|
240 |
||
|
2535.3.1
by Andrew Bennetts
Add get_format_signature to VersionedFile |
241 |
def get_format_signature(self): |
242 |
"""Get a text description of the data encoding in this file. |
|
243 |
|
|
|
2831.7.1
by Ian Clatworthy
versionedfile.py code cleanups |
244 |
:since: 0.90
|
|
2535.3.1
by Andrew Bennetts
Add get_format_signature to VersionedFile |
245 |
"""
|
246 |
raise NotImplementedError(self.get_format_signature) |
|
247 |
||
|
2520.4.41
by Aaron Bentley
Accelerate mpdiff generation |
248 |
def make_mpdiffs(self, version_ids): |
|
2831.7.1
by Ian Clatworthy
versionedfile.py code cleanups |
249 |
"""Create multiparent diffs for specified versions.""" |
|
2520.4.41
by Aaron Bentley
Accelerate mpdiff generation |
250 |
knit_versions = set() |
|
3287.5.2
by Robert Collins
Deprecate VersionedFile.get_parents, breaking pulling from a ghost containing knit or pack repository to weaves, which improves correctness and allows simplification of core code. |
251 |
knit_versions.update(version_ids) |
252 |
parent_map = self.get_parent_map(version_ids) |
|
|
2520.4.41
by Aaron Bentley
Accelerate mpdiff generation |
253 |
for version_id in version_ids: |
|
3287.5.2
by Robert Collins
Deprecate VersionedFile.get_parents, breaking pulling from a ghost containing knit or pack repository to weaves, which improves correctness and allows simplification of core code. |
254 |
try: |
255 |
knit_versions.update(parent_map[version_id]) |
|
256 |
except KeyError: |
|
257 |
raise RevisionNotPresent(version_id, self) |
|
258 |
# We need to filter out ghosts, because we can't diff against them.
|
|
259 |
knit_versions = set(self.get_parent_map(knit_versions).keys()) |
|
|
2520.4.90
by Aaron Bentley
Handle \r terminated lines in Weaves properly |
260 |
lines = dict(zip(knit_versions, |
261 |
self._get_lf_split_line_list(knit_versions))) |
|
|
2520.4.41
by Aaron Bentley
Accelerate mpdiff generation |
262 |
diffs = [] |
263 |
for version_id in version_ids: |
|
264 |
target = lines[version_id] |
|
|
3287.5.2
by Robert Collins
Deprecate VersionedFile.get_parents, breaking pulling from a ghost containing knit or pack repository to weaves, which improves correctness and allows simplification of core code. |
265 |
try: |
266 |
parents = [lines[p] for p in parent_map[version_id] if p in |
|
267 |
knit_versions] |
|
268 |
except KeyError: |
|
269 |
raise RevisionNotPresent(version_id, self) |
|
|
2520.4.48
by Aaron Bentley
Support getting blocks from knit deltas with no final EOL |
270 |
if len(parents) > 0: |
271 |
left_parent_blocks = self._extract_blocks(version_id, |
|
272 |
parents[0], target) |
|
273 |
else: |
|
274 |
left_parent_blocks = None |
|
|
2520.4.41
by Aaron Bentley
Accelerate mpdiff generation |
275 |
diffs.append(multiparent.MultiParent.from_lines(target, parents, |
276 |
left_parent_blocks)) |
|
277 |
return diffs |
|
278 |
||
|
2520.4.48
by Aaron Bentley
Support getting blocks from knit deltas with no final EOL |
279 |
def _extract_blocks(self, version_id, source, target): |
|
2520.4.41
by Aaron Bentley
Accelerate mpdiff generation |
280 |
return None |
|
2520.4.3
by Aaron Bentley
Implement plain strategy for extracting and installing multiparent diffs |
281 |
|
|
2520.4.61
by Aaron Bentley
Do bulk insertion of records |
282 |
def add_mpdiffs(self, records): |
|
2831.7.1
by Ian Clatworthy
versionedfile.py code cleanups |
283 |
"""Add mpdiffs to this VersionedFile. |
|
2520.4.126
by Aaron Bentley
Add more docs |
284 |
|
285 |
Records should be iterables of version, parents, expected_sha1,
|
|
|
2831.7.1
by Ian Clatworthy
versionedfile.py code cleanups |
286 |
mpdiff. mpdiff should be a MultiParent instance.
|
|
2520.4.126
by Aaron Bentley
Add more docs |
287 |
"""
|
|
2831.7.1
by Ian Clatworthy
versionedfile.py code cleanups |
288 |
# Does this need to call self._check_write_ok()? (IanC 20070919)
|
|
2520.4.61
by Aaron Bentley
Do bulk insertion of records |
289 |
vf_parents = {} |
|
2520.4.141
by Aaron Bentley
More batch operations adding mpdiffs |
290 |
mpvf = multiparent.MultiMemoryVersionedFile() |
291 |
versions = [] |
|
292 |
for version, parent_ids, expected_sha1, mpdiff in records: |
|
293 |
versions.append(version) |
|
294 |
mpvf.add_diff(mpdiff, version, parent_ids) |
|
295 |
needed_parents = set() |
|
|
2520.4.142
by Aaron Bentley
Clean up installation of inventory records |
296 |
for version, parent_ids, expected_sha1, mpdiff in records: |
|
2520.4.141
by Aaron Bentley
More batch operations adding mpdiffs |
297 |
needed_parents.update(p for p in parent_ids |
298 |
if not mpvf.has_version(p)) |
|
|
3287.5.2
by Robert Collins
Deprecate VersionedFile.get_parents, breaking pulling from a ghost containing knit or pack repository to weaves, which improves correctness and allows simplification of core code. |
299 |
present_parents = set(self.get_parent_map(needed_parents).keys()) |
300 |
for parent_id, lines in zip(present_parents, |
|
301 |
self._get_lf_split_line_list(present_parents)): |
|
|
2520.4.141
by Aaron Bentley
More batch operations adding mpdiffs |
302 |
mpvf.add_version(lines, parent_id, []) |
303 |
for (version, parent_ids, expected_sha1, mpdiff), lines in\ |
|
304 |
zip(records, mpvf.get_line_list(versions)): |
|
305 |
if len(parent_ids) == 1: |
|
|
2520.4.140
by Aaron Bentley
Use matching blocks from mpdiff for knit delta creation |
306 |
left_matching_blocks = list(mpdiff.get_matching_blocks(0, |
|
2520.4.141
by Aaron Bentley
More batch operations adding mpdiffs |
307 |
mpvf.get_diff(parent_ids[0]).num_lines())) |
|
2520.4.140
by Aaron Bentley
Use matching blocks from mpdiff for knit delta creation |
308 |
else: |
309 |
left_matching_blocks = None |
|
|
3287.5.2
by Robert Collins
Deprecate VersionedFile.get_parents, breaking pulling from a ghost containing knit or pack repository to weaves, which improves correctness and allows simplification of core code. |
310 |
try: |
311 |
_, _, version_text = self.add_lines_with_ghosts(version, |
|
312 |
parent_ids, lines, vf_parents, |
|
313 |
left_matching_blocks=left_matching_blocks) |
|
314 |
except NotImplementedError: |
|
315 |
# The vf can't handle ghosts, so add lines normally, which will
|
|
316 |
# (reasonably) fail if there are ghosts in the data.
|
|
317 |
_, _, version_text = self.add_lines(version, |
|
318 |
parent_ids, lines, vf_parents, |
|
319 |
left_matching_blocks=left_matching_blocks) |
|
|
2520.4.61
by Aaron Bentley
Do bulk insertion of records |
320 |
vf_parents[version] = version_text |
|
2520.4.142
by Aaron Bentley
Clean up installation of inventory records |
321 |
for (version, parent_ids, expected_sha1, mpdiff), sha1 in\ |
322 |
zip(records, self.get_sha1s(versions)): |
|
323 |
if expected_sha1 != sha1: |
|
|
2520.4.71
by Aaron Bentley
Update test to accept VersionedFileInvalidChecksum instead of TestamentMismatch |
324 |
raise errors.VersionedFileInvalidChecksum(version) |
|
2520.4.3
by Aaron Bentley
Implement plain strategy for extracting and installing multiparent diffs |
325 |
|
|
2520.4.89
by Aaron Bentley
Add get_sha1s to weaves |
326 |
def get_sha1s(self, version_ids): |
327 |
"""Get the stored sha1 sums for the given revisions. |
|
328 |
||
329 |
:param version_ids: The names of the versions to lookup
|
|
330 |
:return: a list of sha1s in order according to the version_ids
|
|
331 |
"""
|
|
|
2831.7.1
by Ian Clatworthy
versionedfile.py code cleanups |
332 |
raise NotImplementedError(self.get_sha1s) |
|
2520.4.89
by Aaron Bentley
Add get_sha1s to weaves |
333 |
|
|
1563.2.1
by Robert Collins
Merge in a variation of the versionedfile api from versioned-file. |
334 |
def get_text(self, version_id): |
335 |
"""Return version contents as a text string. |
|
336 |
||
337 |
Raises RevisionNotPresent if version is not present in
|
|
338 |
file history.
|
|
339 |
"""
|
|
340 |
return ''.join(self.get_lines(version_id)) |
|
341 |
get_string = get_text |
|
342 |
||
|
1756.2.1
by Aaron Bentley
Implement get_texts |
343 |
def get_texts(self, version_ids): |
344 |
"""Return the texts of listed versions as a list of strings. |
|
345 |
||
346 |
Raises RevisionNotPresent if version is not present in
|
|
347 |
file history.
|
|
348 |
"""
|
|
349 |
return [''.join(self.get_lines(v)) for v in version_ids] |
|
350 |
||
|
1563.2.1
by Robert Collins
Merge in a variation of the versionedfile api from versioned-file. |
351 |
def get_lines(self, version_id): |
352 |
"""Return version contents as a sequence of lines. |
|
353 |
||
354 |
Raises RevisionNotPresent if version is not present in
|
|
355 |
file history.
|
|
356 |
"""
|
|
357 |
raise NotImplementedError(self.get_lines) |
|
358 |
||
|
2520.4.90
by Aaron Bentley
Handle \r terminated lines in Weaves properly |
359 |
def _get_lf_split_line_list(self, version_ids): |
360 |
return [StringIO(t).readlines() for t in self.get_texts(version_ids)] |
|
|
2520.4.3
by Aaron Bentley
Implement plain strategy for extracting and installing multiparent diffs |
361 |
|
|
2530.1.1
by Aaron Bentley
Make topological sorting optional for get_ancestry |
362 |
def get_ancestry(self, version_ids, topo_sorted=True): |
|
1563.2.1
by Robert Collins
Merge in a variation of the versionedfile api from versioned-file. |
363 |
"""Return a list of all ancestors of given version(s). This |
364 |
will not include the null revision.
|
|
365 |
||
|
2490.2.32
by Aaron Bentley
Merge of not-sorting-ancestry branch |
366 |
This list will not be topologically sorted if topo_sorted=False is
|
367 |
passed.
|
|
|
2530.1.1
by Aaron Bentley
Make topological sorting optional for get_ancestry |
368 |
|
|
1563.2.1
by Robert Collins
Merge in a variation of the versionedfile api from versioned-file. |
369 |
Must raise RevisionNotPresent if any of the given versions are
|
370 |
not present in file history."""
|
|
371 |
if isinstance(version_ids, basestring): |
|
372 |
version_ids = [version_ids] |
|
373 |
raise NotImplementedError(self.get_ancestry) |
|
374 |
||
|
1594.2.8
by Robert Collins
add ghost aware apis to knits. |
375 |
def get_ancestry_with_ghosts(self, version_ids): |
376 |
"""Return a list of all ancestors of given version(s). This |
|
377 |
will not include the null revision.
|
|
378 |
||
379 |
Must raise RevisionNotPresent if any of the given versions are
|
|
380 |
not present in file history.
|
|
381 |
|
|
382 |
Ghosts that are known about will be included in ancestry list,
|
|
383 |
but are not explicitly marked.
|
|
384 |
"""
|
|
385 |
raise NotImplementedError(self.get_ancestry_with_ghosts) |
|
|
3316.2.7
by Robert Collins
Actually deprecated VersionedFile.get_graph. |
386 |
|
|
3287.5.1
by Robert Collins
Add VersionedFile.get_parent_map. |
387 |
def get_parent_map(self, version_ids): |
388 |
"""Get a map of the parents of version_ids. |
|
389 |
||
390 |
:param version_ids: The version ids to look up parents for.
|
|
391 |
:return: A mapping from version id to parents.
|
|
392 |
"""
|
|
393 |
raise NotImplementedError(self.get_parent_map) |
|
394 |
||
|
1594.2.8
by Robert Collins
add ghost aware apis to knits. |
395 |
def get_parents_with_ghosts(self, version_id): |
396 |
"""Return version names for parents of version_id. |
|
397 |
||
398 |
Will raise RevisionNotPresent if version_id is not present
|
|
399 |
in the history.
|
|
400 |
||
401 |
Ghosts that are known about will be included in the parent list,
|
|
402 |
but are not explicitly marked.
|
|
403 |
"""
|
|
|
3287.5.1
by Robert Collins
Add VersionedFile.get_parent_map. |
404 |
try: |
405 |
return list(self.get_parent_map([version_id])[version_id]) |
|
406 |
except KeyError: |
|
407 |
raise errors.RevisionNotPresent(version_id, self) |
|
|
1594.2.8
by Robert Collins
add ghost aware apis to knits. |
408 |
|
|
1563.2.1
by Robert Collins
Merge in a variation of the versionedfile api from versioned-file. |
409 |
def annotate(self, version_id): |
|
3316.2.13
by Robert Collins
* ``VersionedFile.annotate_iter`` is deprecated. While in principal this |
410 |
"""Return a list of (version-id, line) tuples for version_id. |
411 |
||
412 |
:raise RevisionNotPresent: If the given version is
|
|
413 |
not present in file history.
|
|
414 |
"""
|
|
415 |
raise NotImplementedError(self.annotate) |
|
|
1563.2.1
by Robert Collins
Merge in a variation of the versionedfile api from versioned-file. |
416 |
|
|
3350.3.14
by Robert Collins
Deprecate VersionedFile.join. |
417 |
@deprecated_method(one_five) |
|
1563.2.31
by Robert Collins
Convert Knit repositories to use knits. |
418 |
def join(self, other, pb=None, msg=None, version_ids=None, |
419 |
ignore_missing=False): |
|
|
1563.2.1
by Robert Collins
Merge in a variation of the versionedfile api from versioned-file. |
420 |
"""Integrate versions from other into this versioned file. |
421 |
||
422 |
If version_ids is None all versions from other should be
|
|
423 |
incorporated into this versioned file.
|
|
424 |
||
425 |
Must raise RevisionNotPresent if any of the specified versions
|
|
|
2831.7.1
by Ian Clatworthy
versionedfile.py code cleanups |
426 |
are not present in the other file's history unless ignore_missing
|
427 |
is supplied in which case they are silently skipped.
|
|
|
1563.2.31
by Robert Collins
Convert Knit repositories to use knits. |
428 |
"""
|
|
1594.2.23
by Robert Collins
Test versioned file storage handling of clean/dirty status for accessed versioned files. |
429 |
self._check_write_ok() |
|
1563.2.31
by Robert Collins
Convert Knit repositories to use knits. |
430 |
return InterVersionedFile.get(other, self).join( |
431 |
pb, |
|
432 |
msg, |
|
433 |
version_ids, |
|
434 |
ignore_missing) |
|
|
1563.2.1
by Robert Collins
Merge in a variation of the versionedfile api from versioned-file. |
435 |
|
|
2975.3.2
by Robert Collins
Review feedback - document the API change and improve readability in pack's _do_copy_nodes. |
436 |
def iter_lines_added_or_present_in_versions(self, version_ids=None, |
|
2039.1.1
by Aaron Bentley
Clean up progress properly when interrupted during fetch (#54000) |
437 |
pb=None): |
|
1594.2.6
by Robert Collins
Introduce a api specifically for looking at lines in some versions of the inventory, for fileid_involved. |
438 |
"""Iterate over the lines in the versioned file from version_ids. |
439 |
||
|
2975.3.2
by Robert Collins
Review feedback - document the API change and improve readability in pack's _do_copy_nodes. |
440 |
This may return lines from other versions. Each item the returned
|
441 |
iterator yields is a tuple of a line and a text version that that line
|
|
442 |
is present in (not introduced in).
|
|
443 |
||
444 |
Ordering of results is in whatever order is most suitable for the
|
|
445 |
underlying storage format.
|
|
|
1594.2.6
by Robert Collins
Introduce a api specifically for looking at lines in some versions of the inventory, for fileid_involved. |
446 |
|
|
2039.1.1
by Aaron Bentley
Clean up progress properly when interrupted during fetch (#54000) |
447 |
If a progress bar is supplied, it may be used to indicate progress.
|
448 |
The caller is responsible for cleaning up progress bars (because this
|
|
449 |
is an iterator).
|
|
450 |
||
|
1594.2.6
by Robert Collins
Introduce a api specifically for looking at lines in some versions of the inventory, for fileid_involved. |
451 |
NOTES: Lines are normalised: they will all have \n terminators.
|
452 |
Lines are returned in arbitrary order.
|
|
|
2975.3.2
by Robert Collins
Review feedback - document the API change and improve readability in pack's _do_copy_nodes. |
453 |
|
454 |
:return: An iterator over (line, version_id).
|
|
|
1594.2.6
by Robert Collins
Introduce a api specifically for looking at lines in some versions of the inventory, for fileid_involved. |
455 |
"""
|
456 |
raise NotImplementedError(self.iter_lines_added_or_present_in_versions) |
|
457 |
||
|
1551.6.15
by Aaron Bentley
Moved plan_merge into Weave |
458 |
def plan_merge(self, ver_a, ver_b): |
|
1563.2.1
by Robert Collins
Merge in a variation of the versionedfile api from versioned-file. |
459 |
"""Return pseudo-annotation indicating how the two versions merge. |
460 |
||
461 |
This is computed between versions a and b and their common
|
|
462 |
base.
|
|
463 |
||
464 |
Weave lines present in none of them are skipped entirely.
|
|
|
1664.2.2
by Aaron Bentley
Added legend for plan-merge output |
465 |
|
466 |
Legend:
|
|
467 |
killed-base Dead in base revision
|
|
468 |
killed-both Killed in each revision
|
|
469 |
killed-a Killed in a
|
|
470 |
killed-b Killed in b
|
|
471 |
unchanged Alive in both a and b (possibly created in both)
|
|
472 |
new-a Created in a
|
|
473 |
new-b Created in b
|
|
|
1664.2.5
by Aaron Bentley
Update plan-merge legend |
474 |
ghost-a Killed in a, unborn in b
|
475 |
ghost-b Killed in b, unborn in a
|
|
|
1664.2.2
by Aaron Bentley
Added legend for plan-merge output |
476 |
irrelevant Not in either revision
|
|
1563.2.1
by Robert Collins
Merge in a variation of the versionedfile api from versioned-file. |
477 |
"""
|
|
1551.6.15
by Aaron Bentley
Moved plan_merge into Weave |
478 |
raise NotImplementedError(VersionedFile.plan_merge) |
479 |
||
|
1996.3.7
by John Arbash Meinel
lazy import versionedfile, late-load bzrlib.merge |
480 |
def weave_merge(self, plan, a_marker=TextMerge.A_MARKER, |
|
1551.6.14
by Aaron Bentley
Tweaks from merge review |
481 |
b_marker=TextMerge.B_MARKER): |
|
1551.6.12
by Aaron Bentley
Indicate conflicts from merge_lines, insead of guessing |
482 |
return PlanWeaveMerge(plan, a_marker, b_marker).merge_lines()[0] |
|
1551.6.10
by Aaron Bentley
Renamed WeaveMerge to PlanMerge, added plan method, created planless WeaveMerge |
483 |
|
|
1664.2.7
by Aaron Bentley
Merge bzr.dev |
484 |
|
|
3350.3.4
by Robert Collins
Finish adapters for annotated knits to unannotated knits and full texts. |
485 |
class RecordingVersionedFileDecorator(object): |
486 |
"""A minimal versioned file that records calls made on it. |
|
487 |
|
|
488 |
Only enough methods have been added to support tests using it to date.
|
|
489 |
||
490 |
:ivar calls: A list of the calls made; can be reset at any time by
|
|
491 |
assigning [] to it.
|
|
492 |
"""
|
|
493 |
||
494 |
def __init__(self, backing_vf): |
|
495 |
"""Create a RecordingVersionedFileDecorator decorating backing_vf. |
|
496 |
|
|
497 |
:param backing_vf: The versioned file to answer all methods.
|
|
498 |
"""
|
|
499 |
self._backing_vf = backing_vf |
|
500 |
self.calls = [] |
|
501 |
||
502 |
def get_lines(self, version_ids): |
|
503 |
self.calls.append(("get_lines", version_ids)) |
|
504 |
return self._backing_vf.get_lines(version_ids) |
|
505 |
||
506 |
||
|
3062.1.9
by Aaron Bentley
Move PlanMerge into merge and _PlanMergeVersionedFile into versionedfile |
507 |
class _PlanMergeVersionedFile(object): |
508 |
"""A VersionedFile for uncommitted and committed texts. |
|
509 |
||
510 |
It is intended to allow merges to be planned with working tree texts.
|
|
511 |
It implements only the small part of the VersionedFile interface used by
|
|
512 |
PlanMerge. It falls back to multiple versionedfiles for data not stored in
|
|
513 |
_PlanMergeVersionedFile itself.
|
|
514 |
"""
|
|
515 |
||
516 |
def __init__(self, file_id, fallback_versionedfiles=None): |
|
517 |
"""Constuctor |
|
518 |
||
519 |
:param file_id: Used when raising exceptions.
|
|
520 |
:param fallback_versionedfiles: If supplied, the set of fallbacks to
|
|
521 |
use. Otherwise, _PlanMergeVersionedFile.fallback_versionedfiles
|
|
522 |
can be appended to later.
|
|
523 |
"""
|
|
524 |
self._file_id = file_id |
|
525 |
if fallback_versionedfiles is None: |
|
526 |
self.fallback_versionedfiles = [] |
|
527 |
else: |
|
528 |
self.fallback_versionedfiles = fallback_versionedfiles |
|
529 |
self._parents = {} |
|
530 |
self._lines = {} |
|
531 |
||
|
3062.2.3
by Aaron Bentley
Sync up with bzr.dev API changes |
532 |
def plan_merge(self, ver_a, ver_b, base=None): |
|
3062.1.13
by Aaron Bentley
Make _PlanMerge an implementation detail of _PlanMergeVersionedFile |
533 |
"""See VersionedFile.plan_merge""" |
|
3144.3.7
by Aaron Bentley
Update from review |
534 |
from bzrlib.merge import _PlanMerge |
|
3062.2.3
by Aaron Bentley
Sync up with bzr.dev API changes |
535 |
if base is None: |
536 |
return _PlanMerge(ver_a, ver_b, self).plan_merge() |
|
537 |
old_plan = list(_PlanMerge(ver_a, base, self).plan_merge()) |
|
538 |
new_plan = list(_PlanMerge(ver_a, ver_b, self).plan_merge()) |
|
539 |
return _PlanMerge._subtract_plans(old_plan, new_plan) |
|
540 |
||
|
3144.3.1
by Aaron Bentley
Implement LCA merge, with problematic conflict markers |
541 |
def plan_lca_merge(self, ver_a, ver_b, base=None): |
|
3144.3.7
by Aaron Bentley
Update from review |
542 |
from bzrlib.merge import _PlanLCAMerge |
|
3144.3.1
by Aaron Bentley
Implement LCA merge, with problematic conflict markers |
543 |
graph = self._get_graph() |
544 |
new_plan = _PlanLCAMerge(ver_a, ver_b, self, graph).plan_merge() |
|
545 |
if base is None: |
|
546 |
return new_plan |
|
547 |
old_plan = _PlanLCAMerge(ver_a, base, self, graph).plan_merge() |
|
548 |
return _PlanLCAMerge._subtract_plans(list(old_plan), list(new_plan)) |
|
|
3062.1.13
by Aaron Bentley
Make _PlanMerge an implementation detail of _PlanMergeVersionedFile |
549 |
|
|
3062.1.9
by Aaron Bentley
Move PlanMerge into merge and _PlanMergeVersionedFile into versionedfile |
550 |
def add_lines(self, version_id, parents, lines): |
551 |
"""See VersionedFile.add_lines |
|
552 |
||
553 |
Lines are added locally, not fallback versionedfiles. Also, ghosts are
|
|
554 |
permitted. Only reserved ids are permitted.
|
|
555 |
"""
|
|
556 |
if not revision.is_reserved_id(version_id): |
|
557 |
raise ValueError('Only reserved ids may be used') |
|
558 |
if parents is None: |
|
559 |
raise ValueError('Parents may not be None') |
|
560 |
if lines is None: |
|
561 |
raise ValueError('Lines may not be None') |
|
|
3287.5.2
by Robert Collins
Deprecate VersionedFile.get_parents, breaking pulling from a ghost containing knit or pack repository to weaves, which improves correctness and allows simplification of core code. |
562 |
self._parents[version_id] = tuple(parents) |
|
3062.1.9
by Aaron Bentley
Move PlanMerge into merge and _PlanMergeVersionedFile into versionedfile |
563 |
self._lines[version_id] = lines |
564 |
||
565 |
def get_lines(self, version_id): |
|
566 |
"""See VersionedFile.get_ancestry""" |
|
567 |
lines = self._lines.get(version_id) |
|
568 |
if lines is not None: |
|
569 |
return lines |
|
570 |
for versionedfile in self.fallback_versionedfiles: |
|
571 |
try: |
|
572 |
return versionedfile.get_lines(version_id) |
|
573 |
except errors.RevisionNotPresent: |
|
574 |
continue
|
|
575 |
else: |
|
576 |
raise errors.RevisionNotPresent(version_id, self._file_id) |
|
577 |
||
|
3062.1.14
by Aaron Bentley
Use topo_sorted=False with get_ancestry |
578 |
def get_ancestry(self, version_id, topo_sorted=False): |
|
3062.1.9
by Aaron Bentley
Move PlanMerge into merge and _PlanMergeVersionedFile into versionedfile |
579 |
"""See VersionedFile.get_ancestry. |
580 |
||
581 |
Note that this implementation assumes that if a VersionedFile can
|
|
582 |
answer get_ancestry at all, it can give an authoritative answer. In
|
|
583 |
fact, ghosts can invalidate this assumption. But it's good enough
|
|
584 |
99% of the time, and far cheaper/simpler.
|
|
585 |
||
586 |
Also note that the results of this version are never topologically
|
|
587 |
sorted, and are a set.
|
|
588 |
"""
|
|
|
3062.1.14
by Aaron Bentley
Use topo_sorted=False with get_ancestry |
589 |
if topo_sorted: |
590 |
raise ValueError('This implementation does not provide sorting') |
|
|
3062.1.9
by Aaron Bentley
Move PlanMerge into merge and _PlanMergeVersionedFile into versionedfile |
591 |
parents = self._parents.get(version_id) |
592 |
if parents is None: |
|
593 |
for vf in self.fallback_versionedfiles: |
|
594 |
try: |
|
|
3062.1.14
by Aaron Bentley
Use topo_sorted=False with get_ancestry |
595 |
return vf.get_ancestry(version_id, topo_sorted=False) |
|
3062.1.9
by Aaron Bentley
Move PlanMerge into merge and _PlanMergeVersionedFile into versionedfile |
596 |
except errors.RevisionNotPresent: |
597 |
continue
|
|
598 |
else: |
|
599 |
raise errors.RevisionNotPresent(version_id, self._file_id) |
|
600 |
ancestry = set([version_id]) |
|
601 |
for parent in parents: |
|
|
3062.1.14
by Aaron Bentley
Use topo_sorted=False with get_ancestry |
602 |
ancestry.update(self.get_ancestry(parent, topo_sorted=False)) |
|
3062.1.9
by Aaron Bentley
Move PlanMerge into merge and _PlanMergeVersionedFile into versionedfile |
603 |
return ancestry |
604 |
||
|
3287.5.2
by Robert Collins
Deprecate VersionedFile.get_parents, breaking pulling from a ghost containing knit or pack repository to weaves, which improves correctness and allows simplification of core code. |
605 |
def get_parent_map(self, version_ids): |
606 |
"""See VersionedFile.get_parent_map""" |
|
607 |
result = {} |
|
608 |
pending = set(version_ids) |
|
609 |
for key in version_ids: |
|
610 |
try: |
|
611 |
result[key] = self._parents[key] |
|
612 |
except KeyError: |
|
613 |
pass
|
|
614 |
pending = pending - set(result.keys()) |
|
|
3062.1.9
by Aaron Bentley
Move PlanMerge into merge and _PlanMergeVersionedFile into versionedfile |
615 |
for versionedfile in self.fallback_versionedfiles: |
|
3287.5.2
by Robert Collins
Deprecate VersionedFile.get_parents, breaking pulling from a ghost containing knit or pack repository to weaves, which improves correctness and allows simplification of core code. |
616 |
parents = versionedfile.get_parent_map(pending) |
617 |
result.update(parents) |
|
618 |
pending = pending - set(parents.keys()) |
|
619 |
if not pending: |
|
620 |
return result |
|
621 |
return result |
|
|
3062.1.9
by Aaron Bentley
Move PlanMerge into merge and _PlanMergeVersionedFile into versionedfile |
622 |
|
|
3144.3.1
by Aaron Bentley
Implement LCA merge, with problematic conflict markers |
623 |
def _get_graph(self): |
|
3144.3.7
by Aaron Bentley
Update from review |
624 |
from bzrlib.graph import ( |
625 |
DictParentsProvider, |
|
626 |
Graph, |
|
627 |
_StackedParentsProvider, |
|
628 |
)
|
|
629 |
from bzrlib.repofmt.knitrepo import _KnitParentsProvider |
|
|
3144.3.1
by Aaron Bentley
Implement LCA merge, with problematic conflict markers |
630 |
parent_providers = [DictParentsProvider(self._parents)] |
631 |
for vf in self.fallback_versionedfiles: |
|
632 |
parent_providers.append(_KnitParentsProvider(vf)) |
|
633 |
return Graph(_StackedParentsProvider(parent_providers)) |
|
634 |
||
|
3062.1.9
by Aaron Bentley
Move PlanMerge into merge and _PlanMergeVersionedFile into versionedfile |
635 |
|
|
1551.6.10
by Aaron Bentley
Renamed WeaveMerge to PlanMerge, added plan method, created planless WeaveMerge |
636 |
class PlanWeaveMerge(TextMerge): |
|
1551.6.13
by Aaron Bentley
Cleanup |
637 |
"""Weave merge that takes a plan as its input. |
638 |
|
|
|
1551.6.14
by Aaron Bentley
Tweaks from merge review |
639 |
This exists so that VersionedFile.plan_merge is implementable.
|
640 |
Most callers will want to use WeaveMerge instead.
|
|
|
1551.6.13
by Aaron Bentley
Cleanup |
641 |
"""
|
642 |
||
|
1551.6.14
by Aaron Bentley
Tweaks from merge review |
643 |
def __init__(self, plan, a_marker=TextMerge.A_MARKER, |
644 |
b_marker=TextMerge.B_MARKER): |
|
|
1551.6.10
by Aaron Bentley
Renamed WeaveMerge to PlanMerge, added plan method, created planless WeaveMerge |
645 |
TextMerge.__init__(self, a_marker, b_marker) |
646 |
self.plan = plan |
|
647 |
||
|
1551.6.7
by Aaron Bentley
Implemented two-way merge, refactored weave merge |
648 |
def _merge_struct(self): |
|
1563.2.1
by Robert Collins
Merge in a variation of the versionedfile api from versioned-file. |
649 |
lines_a = [] |
650 |
lines_b = [] |
|
651 |
ch_a = ch_b = False |
|
|
1664.2.8
by Aaron Bentley
Fix WeaveMerge when plan doesn't end with unchanged lines |
652 |
|
653 |
def outstanding_struct(): |
|
654 |
if not lines_a and not lines_b: |
|
655 |
return
|
|
656 |
elif ch_a and not ch_b: |
|
657 |
# one-sided change:
|
|
658 |
yield(lines_a,) |
|
659 |
elif ch_b and not ch_a: |
|
660 |
yield (lines_b,) |
|
661 |
elif lines_a == lines_b: |
|
662 |
yield(lines_a,) |
|
663 |
else: |
|
664 |
yield (lines_a, lines_b) |
|
|
1551.6.13
by Aaron Bentley
Cleanup |
665 |
|
|
1616.1.18
by Martin Pool
(weave-merge) don't treat killed-both lines as points of agreement; |
666 |
# We previously considered either 'unchanged' or 'killed-both' lines
|
667 |
# to be possible places to resynchronize. However, assuming agreement
|
|
|
1759.2.1
by Jelmer Vernooij
Fix some types (found using aspell). |
668 |
# on killed-both lines may be too aggressive. -- mbp 20060324
|
|
1551.6.7
by Aaron Bentley
Implemented two-way merge, refactored weave merge |
669 |
for state, line in self.plan: |
|
1616.1.18
by Martin Pool
(weave-merge) don't treat killed-both lines as points of agreement; |
670 |
if state == 'unchanged': |
|
1563.2.1
by Robert Collins
Merge in a variation of the versionedfile api from versioned-file. |
671 |
# resync and flush queued conflicts changes if any
|
|
1664.2.8
by Aaron Bentley
Fix WeaveMerge when plan doesn't end with unchanged lines |
672 |
for struct in outstanding_struct(): |
673 |
yield struct |
|
|
1551.6.11
by Aaron Bentley
Switched TextMerge_lines to work on a list |
674 |
lines_a = [] |
675 |
lines_b = [] |
|
|
1563.2.1
by Robert Collins
Merge in a variation of the versionedfile api from versioned-file. |
676 |
ch_a = ch_b = False |
677 |
||
678 |
if state == 'unchanged': |
|
679 |
if line: |
|
|
1551.6.5
by Aaron Bentley
Got weave merge producing structural output |
680 |
yield ([line],) |
|
1563.2.1
by Robert Collins
Merge in a variation of the versionedfile api from versioned-file. |
681 |
elif state == 'killed-a': |
682 |
ch_a = True |
|
683 |
lines_b.append(line) |
|
684 |
elif state == 'killed-b': |
|
685 |
ch_b = True |
|
686 |
lines_a.append(line) |
|
687 |
elif state == 'new-a': |
|
688 |
ch_a = True |
|
689 |
lines_a.append(line) |
|
690 |
elif state == 'new-b': |
|
691 |
ch_b = True |
|
692 |
lines_b.append(line) |
|
|
3144.3.2
by Aaron Bentley
Get conflict handling working |
693 |
elif state == 'conflicted-a': |
694 |
ch_b = ch_a = True |
|
695 |
lines_a.append(line) |
|
696 |
elif state == 'conflicted-b': |
|
697 |
ch_b = ch_a = True |
|
698 |
lines_b.append(line) |
|
|
1563.2.1
by Robert Collins
Merge in a variation of the versionedfile api from versioned-file. |
699 |
else: |
|
3376.2.4
by Martin Pool
Remove every assert statement from bzrlib! |
700 |
if state not in ('irrelevant', 'ghost-a', 'ghost-b', |
701 |
'killed-base', 'killed-both'): |
|
702 |
raise AssertionError(state) |
|
|
1664.2.8
by Aaron Bentley
Fix WeaveMerge when plan doesn't end with unchanged lines |
703 |
for struct in outstanding_struct(): |
704 |
yield struct |
|
|
1563.2.12
by Robert Collins
Checkpointing: created InterObject to factor out common inter object worker code, added InterVersionedFile and tests to allow making join work between any versionedfile. |
705 |
|
|
1664.2.14
by Aaron Bentley
spacing fix |
706 |
|
|
1551.6.10
by Aaron Bentley
Renamed WeaveMerge to PlanMerge, added plan method, created planless WeaveMerge |
707 |
class WeaveMerge(PlanWeaveMerge): |
|
2831.7.1
by Ian Clatworthy
versionedfile.py code cleanups |
708 |
"""Weave merge that takes a VersionedFile and two versions as its input.""" |
|
1551.6.13
by Aaron Bentley
Cleanup |
709 |
|
|
1551.6.10
by Aaron Bentley
Renamed WeaveMerge to PlanMerge, added plan method, created planless WeaveMerge |
710 |
def __init__(self, versionedfile, ver_a, ver_b, |
|
1551.6.14
by Aaron Bentley
Tweaks from merge review |
711 |
a_marker=PlanWeaveMerge.A_MARKER, b_marker=PlanWeaveMerge.B_MARKER): |
|
1551.6.15
by Aaron Bentley
Moved plan_merge into Weave |
712 |
plan = versionedfile.plan_merge(ver_a, ver_b) |
|
1551.6.10
by Aaron Bentley
Renamed WeaveMerge to PlanMerge, added plan method, created planless WeaveMerge |
713 |
PlanWeaveMerge.__init__(self, plan, a_marker, b_marker) |
714 |
||
715 |
||
|
1563.2.12
by Robert Collins
Checkpointing: created InterObject to factor out common inter object worker code, added InterVersionedFile and tests to allow making join work between any versionedfile. |
716 |
class InterVersionedFile(InterObject): |
|
2831.7.1
by Ian Clatworthy
versionedfile.py code cleanups |
717 |
"""This class represents operations taking place between two VersionedFiles. |
|
1563.2.12
by Robert Collins
Checkpointing: created InterObject to factor out common inter object worker code, added InterVersionedFile and tests to allow making join work between any versionedfile. |
718 |
|
719 |
Its instances have methods like join, and contain
|
|
720 |
references to the source and target versionedfiles these operations can be
|
|
721 |
carried out on.
|
|
722 |
||
723 |
Often we will provide convenience methods on 'versionedfile' which carry out
|
|
724 |
operations with another versionedfile - they will always forward to
|
|
725 |
InterVersionedFile.get(other).method_name(parameters).
|
|
726 |
"""
|
|
727 |
||
|
1910.2.15
by Aaron Bentley
Back out inter.get changes, make optimizers an ordered list |
728 |
_optimisers = [] |
|
1563.2.12
by Robert Collins
Checkpointing: created InterObject to factor out common inter object worker code, added InterVersionedFile and tests to allow making join work between any versionedfile. |
729 |
"""The available optimised InterVersionedFile types.""" |
730 |
||
|
1563.2.31
by Robert Collins
Convert Knit repositories to use knits. |
731 |
def join(self, pb=None, msg=None, version_ids=None, ignore_missing=False): |
|
1563.2.13
by Robert Collins
InterVersionedFile implemented. |
732 |
"""Integrate versions from self.source into self.target. |
733 |
||
734 |
If version_ids is None all versions from source should be
|
|
735 |
incorporated into this versioned file.
|
|
736 |
||
737 |
Must raise RevisionNotPresent if any of the specified versions
|
|
|
2831.7.1
by Ian Clatworthy
versionedfile.py code cleanups |
738 |
are not present in the other file's history unless ignore_missing is
|
739 |
supplied in which case they are silently skipped.
|
|
|
1563.2.13
by Robert Collins
InterVersionedFile implemented. |
740 |
"""
|
|
3316.2.1
by Robert Collins
* ``VersionedFile.create_empty`` is removed. This method presupposed a |
741 |
target = self.target |
|
1684.3.2
by Robert Collins
Factor out version_ids-to-join selection in InterVersionedfile. |
742 |
version_ids = self._get_source_version_ids(version_ids, ignore_missing) |
|
3287.6.1
by Robert Collins
* ``VersionedFile.get_graph`` is deprecated, with no replacement method. |
743 |
graph = Graph(self.source) |
744 |
search = graph._make_breadth_first_searcher(version_ids) |
|
745 |
transitive_ids = set() |
|
746 |
map(transitive_ids.update, list(search)) |
|
747 |
parent_map = self.source.get_parent_map(transitive_ids) |
|
748 |
order = tsort.topo_sort(parent_map.items()) |
|
|
1563.2.37
by Robert Collins
Merge in nested progress bars |
749 |
pb = ui.ui_factory.nested_progress_bar() |
|
1596.2.38
by Robert Collins
rollback from using deltas to using fulltexts - deltas need more work to be ready. |
750 |
parent_texts = {} |
|
1563.2.37
by Robert Collins
Merge in nested progress bars |
751 |
try: |
|
1596.2.28
by Robert Collins
more knit profile based tuning. |
752 |
# TODO for incremental cross-format work:
|
|
1596.2.27
by Robert Collins
Note potential improvements in knit adds. |
753 |
# make a versioned file with the following content:
|
754 |
# all revisions we have been asked to join
|
|
755 |
# all their ancestors that are *not* in target already.
|
|
756 |
# the immediate parents of the above two sets, with
|
|
757 |
# empty parent lists - these versions are in target already
|
|
758 |
# and the incorrect version data will be ignored.
|
|
759 |
# TODO: for all ancestors that are present in target already,
|
|
760 |
# check them for consistent data, this requires moving sha1 from
|
|
|
1596.2.38
by Robert Collins
rollback from using deltas to using fulltexts - deltas need more work to be ready. |
761 |
#
|
762 |
# TODO: remove parent texts when they are not relevant any more for
|
|
763 |
# memory pressure reduction. RBC 20060313
|
|
764 |
# pb.update('Converting versioned data', 0, len(order))
|
|
|
2851.4.3
by Ian Clatworthy
fix up plain-to-annotated knit conversion |
765 |
total = len(order) |
|
1563.2.37
by Robert Collins
Merge in nested progress bars |
766 |
for index, version in enumerate(order): |
|
2851.4.3
by Ian Clatworthy
fix up plain-to-annotated knit conversion |
767 |
pb.update('Converting versioned data', index, total) |
|
3316.2.1
by Robert Collins
* ``VersionedFile.create_empty`` is removed. This method presupposed a |
768 |
if version in target: |
769 |
continue
|
|
|
2776.1.3
by Robert Collins
Missed bundles in the return value conversion of vf.add_lines. |
770 |
_, _, parent_text = target.add_lines(version, |
|
3287.5.2
by Robert Collins
Deprecate VersionedFile.get_parents, breaking pulling from a ghost containing knit or pack repository to weaves, which improves correctness and allows simplification of core code. |
771 |
parent_map[version], |
|
1596.2.38
by Robert Collins
rollback from using deltas to using fulltexts - deltas need more work to be ready. |
772 |
self.source.get_lines(version), |
773 |
parent_texts=parent_texts) |
|
774 |
parent_texts[version] = parent_text |
|
|
3316.2.1
by Robert Collins
* ``VersionedFile.create_empty`` is removed. This method presupposed a |
775 |
return total |
|
1563.2.37
by Robert Collins
Merge in nested progress bars |
776 |
finally: |
777 |
pb.finished() |
|
|
1563.2.13
by Robert Collins
InterVersionedFile implemented. |
778 |
|
|
1684.3.2
by Robert Collins
Factor out version_ids-to-join selection in InterVersionedfile. |
779 |
def _get_source_version_ids(self, version_ids, ignore_missing): |
780 |
"""Determine the version ids to be used from self.source. |
|
781 |
||
782 |
:param version_ids: The caller-supplied version ids to check. (None
|
|
|
1684.3.3
by Robert Collins
Add a special cased weaves to knit converter. |
783 |
for all). If None is in version_ids, it is stripped.
|
|
1684.3.2
by Robert Collins
Factor out version_ids-to-join selection in InterVersionedfile. |
784 |
:param ignore_missing: if True, remove missing ids from the version
|
785 |
list. If False, raise RevisionNotPresent on
|
|
786 |
a missing version id.
|
|
787 |
:return: A set of version ids.
|
|
788 |
"""
|
|
789 |
if version_ids is None: |
|
|
1684.3.3
by Robert Collins
Add a special cased weaves to knit converter. |
790 |
# None cannot be in source.versions
|
|
1684.3.2
by Robert Collins
Factor out version_ids-to-join selection in InterVersionedfile. |
791 |
return set(self.source.versions()) |
792 |
else: |
|
793 |
if ignore_missing: |
|
794 |
return set(self.source.versions()).intersection(set(version_ids)) |
|
795 |
else: |
|
796 |
new_version_ids = set() |
|
797 |
for version in version_ids: |
|
|
1684.3.3
by Robert Collins
Add a special cased weaves to knit converter. |
798 |
if version is None: |
799 |
continue
|
|
|
1684.3.2
by Robert Collins
Factor out version_ids-to-join selection in InterVersionedfile. |
800 |
if not self.source.has_version(version): |
801 |
raise errors.RevisionNotPresent(version, str(self.source)) |
|
802 |
else: |
|
803 |
new_version_ids.add(version) |
|
804 |
return new_version_ids |