7
7
# it under the terms of the GNU General Public License as published by
8
8
# the Free Software Foundation; either version 2 of the License, or
9
9
# (at your option) any later version.
11
11
# This program is distributed in the hope that it will be useful,
12
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
14
# GNU General Public License for more details.
16
16
# You should have received a copy of the GNU General Public License
17
17
# along with this program; if not, write to the Free Software
18
18
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
20
"""Versioned text file storage api."""
22
from bzrlib.lazy_import import lazy_import
23
lazy_import(globals(), """
24
23
from copy import deepcopy
32
from bzrlib.transport.memory import MemoryTransport
24
from unittest import TestSuite
27
import bzrlib.errors as errors
35
28
from bzrlib.inter import InterObject
29
from bzrlib.symbol_versioning import *
36
30
from bzrlib.textmerge import TextMerge
37
from bzrlib.symbol_versioning import (deprecated_function,
31
from bzrlib.transport.memory import MemoryTransport
32
from bzrlib.tsort import topo_sort
43
36
class VersionedFile(object):
61
54
def copy_to(self, name, transport):
62
55
"""Copy this versioned file to name on transport."""
63
56
raise NotImplementedError(self.copy_to)
65
58
@deprecated_method(zero_eight)
67
60
"""Return a list of all the versions in this versioned file.
177
170
if self._access_mode != 'w':
178
171
raise errors.ReadOnlyObjectDirtiedError(self)
180
def enable_cache(self):
181
"""Tell this versioned file that it should cache any data it reads.
183
This is advisory, implementations do not have to support caching.
187
173
def clear_cache(self):
188
"""Remove any data cached in the versioned file object.
190
This only needs to be supported if caches are supported
174
"""Remove any data cached in the versioned file object."""
194
176
def clone_text(self, new_version_id, old_version_id, parents):
195
177
"""Add an identical text to old_version_id as new_version_id.
270
252
return ''.join(self.get_lines(version_id))
271
253
get_string = get_text
273
def get_texts(self, version_ids):
274
"""Return the texts of listed versions as a list of strings.
276
Raises RevisionNotPresent if version is not present in
279
return [''.join(self.get_lines(v)) for v in version_ids]
281
255
def get_lines(self, version_id):
282
256
"""Return version contents as a sequence of lines.
410
def iter_lines_added_or_present_in_versions(self, version_ids=None,
384
def iter_lines_added_or_present_in_versions(self, version_ids=None):
412
385
"""Iterate over the lines in the versioned file from version_ids.
414
387
This may return lines from other versions, and does not return the
415
388
specific version marker at this point. The api may be changed
416
389
during development to include the version that the versioned file
417
390
thinks is relevant, but given that such hints are just guesses,
418
its better not to have it if we don't need it.
420
If a progress bar is supplied, it may be used to indicate progress.
421
The caller is responsible for cleaning up progress bars (because this
391
its better not to have it if we dont need it.
424
393
NOTES: Lines are normalised: they will all have \n terminators.
425
394
Lines are returned in arbitrary order.
478
447
raise NotImplementedError(VersionedFile.plan_merge)
480
def weave_merge(self, plan, a_marker=TextMerge.A_MARKER,
449
def weave_merge(self, plan, a_marker=TextMerge.A_MARKER,
481
450
b_marker=TextMerge.B_MARKER):
482
451
return PlanWeaveMerge(plan, a_marker, b_marker).merge_lines()[0]
515
484
# We previously considered either 'unchanged' or 'killed-both' lines
516
485
# to be possible places to resynchronize. However, assuming agreement
517
# on killed-both lines may be too aggressive. -- mbp 20060324
486
# on killed-both lines may be too agressive. -- mbp 20060324
518
487
for state, line in self.plan:
519
488
if state == 'unchanged':
520
489
# resync and flush queued conflicts changes if any
567
536
InterVersionedFile.get(other).method_name(parameters).
571
540
"""The available optimised InterVersionedFile types."""
573
542
def join(self, pb=None, msg=None, version_ids=None, ignore_missing=False):
594
563
target = temp_source
595
564
version_ids = self._get_source_version_ids(version_ids, ignore_missing)
596
565
graph = self.source.get_graph(version_ids)
597
order = tsort.topo_sort(graph.items())
566
order = topo_sort(graph.items())
598
567
pb = ui.ui_factory.nested_progress_bar()
599
568
parent_texts = {}
669
638
class InterVersionedFileTestProviderAdapter(object):
670
639
"""A tool to generate a suite testing multiple inter versioned-file classes.
672
This is done by copying the test once for each InterVersionedFile provider
641
This is done by copying the test once for each interversionedfile provider
673
642
and injecting the transport_server, transport_readonly_server,
674
643
versionedfile_factory and versionedfile_factory_to classes into each copy.
675
644
Each copy is also given a new id() to make it easy to identify.