~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/versionedfile.py

  • Committer: Alexander Belchenko
  • Date: 2006-07-30 16:43:12 UTC
  • mto: (1711.2.111 jam-integration)
  • mto: This revision was merged to the branch mainline in revision 1906.
  • Revision ID: bialix@ukr.net-20060730164312-b025fd3ff0cee59e
rename  gpl.txt => COPYING.txt

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 by Canonical Ltd
2
2
#
3
3
# Authors:
4
4
#   Johan Rydberg <jrydberg@gnu.org>
19
19
 
20
20
"""Versioned text file storage api."""
21
21
 
22
 
from bzrlib.lazy_import import lazy_import
23
 
lazy_import(globals(), """
 
22
 
24
23
from copy import deepcopy
25
 
import unittest
26
 
 
27
 
from bzrlib import (
28
 
    errors,
29
 
    osutils,
30
 
    tsort,
31
 
    revision,
32
 
    ui,
33
 
    )
34
 
from bzrlib.transport.memory import MemoryTransport
35
 
""")
36
 
 
 
24
from unittest import TestSuite
 
25
 
 
26
 
 
27
import bzrlib.errors as errors
37
28
from bzrlib.inter import InterObject
38
29
from bzrlib.textmerge import TextMerge
 
30
from bzrlib.transport.memory import MemoryTransport
 
31
from bzrlib.tsort import topo_sort
 
32
from bzrlib import ui
39
33
from bzrlib.symbol_versioning import (deprecated_function,
40
34
        deprecated_method,
41
35
        zero_eight,
60
54
        self.finished = False
61
55
        self._access_mode = access_mode
62
56
 
63
 
    @staticmethod
64
 
    def check_not_reserved_id(version_id):
65
 
        revision.check_not_reserved_id(version_id)
66
 
 
67
57
    def copy_to(self, name, transport):
68
58
        """Copy this versioned file to name on transport."""
69
59
        raise NotImplementedError(self.copy_to)
97
87
        :param sha1: The sha1 of the full text.
98
88
        :param delta: The delta instructions. See get_delta for details.
99
89
        """
100
 
        version_id = osutils.safe_revision_id(version_id)
101
 
        parents = [osutils.safe_revision_id(v) for v in parents]
102
90
        self._check_write_ok()
103
91
        if self.has_version(version_id):
104
92
            raise errors.RevisionAlreadyPresent(version_id, self)
141
129
                 provided back to future add_lines calls in the parent_texts
142
130
                 dictionary.
143
131
        """
144
 
        version_id = osutils.safe_revision_id(version_id)
145
 
        parents = [osutils.safe_revision_id(v) for v in parents]
146
132
        self._check_write_ok()
147
133
        return self._add_lines(version_id, parents, lines, parent_texts)
148
134
 
156
142
        
157
143
        This takes the same parameters as add_lines.
158
144
        """
159
 
        version_id = osutils.safe_revision_id(version_id)
160
 
        parents = [osutils.safe_revision_id(v) for v in parents]
161
145
        self._check_write_ok()
162
146
        return self._add_lines_with_ghosts(version_id, parents, lines,
163
147
                                           parent_texts)
211
195
 
212
196
        Must raise RevisionAlreadyPresent if the new version is
213
197
        already present in file history."""
214
 
        new_version_id = osutils.safe_revision_id(new_version_id)
215
 
        old_version_id = osutils.safe_revision_id(old_version_id)
216
198
        self._check_write_ok()
217
199
        return self._clone_text(new_version_id, old_version_id, parents)
218
200
 
229
211
        """
230
212
        raise NotImplementedError(self.create_empty)
231
213
 
232
 
    def fix_parents(self, version_id, new_parents):
 
214
    def fix_parents(self, version, new_parents):
233
215
        """Fix the parents list for version.
234
216
        
235
217
        This is done by appending a new version to the index
237
219
        the parents list must be a superset of the current
238
220
        list.
239
221
        """
240
 
        version_id = osutils.safe_revision_id(version_id)
241
 
        new_parents = [osutils.safe_revision_id(p) for p in new_parents]
242
222
        self._check_write_ok()
243
 
        return self._fix_parents(version_id, new_parents)
 
223
        return self._fix_parents(version, new_parents)
244
224
 
245
 
    def _fix_parents(self, version_id, new_parents):
 
225
    def _fix_parents(self, version, new_parents):
246
226
        """Helper for fix_parents."""
247
227
        raise NotImplementedError(self.fix_parents)
248
228
 
254
234
        """
255
235
        raise NotImplementedError(self.get_delta)
256
236
 
257
 
    def get_deltas(self, version_ids):
 
237
    def get_deltas(self, versions):
258
238
        """Get multiple deltas at once for constructing versions.
259
239
        
260
240
        :return: dict(version_id:(delta_parent, sha1, noeol, delta))
262
242
        version_id is the version_id created by that delta.
263
243
        """
264
244
        result = {}
265
 
        for version_id in version_ids:
266
 
            result[version_id] = self.get_delta(version_id)
 
245
        for version in versions:
 
246
            result[version] = self.get_delta(version)
267
247
        return result
268
248
 
269
249
    def get_sha1(self, version_id):
336
316
            for version in self.versions():
337
317
                result[version] = self.get_parents(version)
338
318
        else:
339
 
            pending = set(osutils.safe_revision_id(v) for v in version_ids)
 
319
            pending = set(version_ids)
340
320
            while pending:
341
321
                version = pending.pop()
342
322
                if version in result:
423
403
            version_ids,
424
404
            ignore_missing)
425
405
 
426
 
    def iter_lines_added_or_present_in_versions(self, version_ids=None, 
427
 
                                                pb=None):
 
406
    def iter_lines_added_or_present_in_versions(self, version_ids=None):
428
407
        """Iterate over the lines in the versioned file from version_ids.
429
408
 
430
409
        This may return lines from other versions, and does not return the
433
412
        thinks is relevant, but given that such hints are just guesses,
434
413
        its better not to have it if we don't need it.
435
414
 
436
 
        If a progress bar is supplied, it may be used to indicate progress.
437
 
        The caller is responsible for cleaning up progress bars (because this
438
 
        is an iterator).
439
 
 
440
415
        NOTES: Lines are normalised: they will all have \n terminators.
441
416
               Lines are returned in arbitrary order.
442
417
        """
493
468
        """
494
469
        raise NotImplementedError(VersionedFile.plan_merge)
495
470
        
496
 
    def weave_merge(self, plan, a_marker=TextMerge.A_MARKER,
 
471
    def weave_merge(self, plan, a_marker=TextMerge.A_MARKER, 
497
472
                    b_marker=TextMerge.B_MARKER):
498
473
        return PlanWeaveMerge(plan, a_marker, b_marker).merge_lines()[0]
499
474
 
583
558
    InterVersionedFile.get(other).method_name(parameters).
584
559
    """
585
560
 
586
 
    _optimisers = []
 
561
    _optimisers = set()
587
562
    """The available optimised InterVersionedFile types."""
588
563
 
589
564
    def join(self, pb=None, msg=None, version_ids=None, ignore_missing=False):
610
585
            target = temp_source
611
586
        version_ids = self._get_source_version_ids(version_ids, ignore_missing)
612
587
        graph = self.source.get_graph(version_ids)
613
 
        order = tsort.topo_sort(graph.items())
 
588
        order = topo_sort(graph.items())
614
589
        pb = ui.ui_factory.nested_progress_bar()
615
590
        parent_texts = {}
616
591
        try:
668
643
            # None cannot be in source.versions
669
644
            return set(self.source.versions())
670
645
        else:
671
 
            version_ids = [osutils.safe_revision_id(v) for v in version_ids]
672
646
            if ignore_missing:
673
647
                return set(self.source.versions()).intersection(set(version_ids))
674
648
            else:
698
672
        self._formats = formats
699
673
    
700
674
    def adapt(self, test):
701
 
        result = unittest.TestSuite()
 
675
        result = TestSuite()
702
676
        for (interversionedfile_class,
703
677
             versionedfile_factory,
704
678
             versionedfile_factory_to) in self._formats: