~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/versionedfile.py

Merge transaction finalisation and ensure iter_lines_added_or_present in knits does a old-to-new read in the knit.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
from unittest import TestSuite
29
29
 
30
30
 
 
31
import bzrlib.errors as errors
31
32
from bzrlib.inter import InterObject
32
33
from bzrlib.symbol_versioning import *
33
34
from bzrlib.transport.memory import MemoryTransport
49
50
    Texts are identified by a version-id string.
50
51
    """
51
52
 
 
53
    def __init__(self, access_mode):
 
54
        self.finished = False
 
55
        self._access_mode = access_mode
 
56
 
52
57
    def copy_to(self, name, transport):
53
58
        """Copy this versioned file to name on transport."""
54
59
        raise NotImplementedError(self.copy_to)
80
85
        already present in file history.
81
86
 
82
87
        Must raise RevisionNotPresent if any of the given parents are
83
 
        not present in file history."""
 
88
        not present in file history.
 
89
        """
 
90
        self._check_write_ok()
 
91
        return self._add_lines(version_id, parents, lines)
 
92
 
 
93
    def _add_lines(self, version_id, parents, lines):
 
94
        """Helper to do the class specific add_lines."""
84
95
        raise NotImplementedError(self.add_lines)
85
96
 
86
97
    def add_lines_with_ghosts(self, version_id, parents, lines):
87
98
        """Add lines to the versioned file, allowing ghosts to be present."""
 
99
        self._check_write_ok()
 
100
        return self._add_lines_with_ghosts(version_id, parents, lines)
 
101
 
 
102
    def _add_lines_with_ghosts(self, version_id, parents, lines):
 
103
        """Helper to do class specific add_lines_with_ghosts."""
88
104
        raise NotImplementedError(self.add_lines_with_ghosts)
89
105
 
90
106
    def check(self, progress_bar=None):
91
107
        """Check the versioned file for integrity."""
92
108
        raise NotImplementedError(self.check)
93
109
 
 
110
    def _check_write_ok(self):
 
111
        """Is the versioned file marked as 'finished' ? Raise if it is."""
 
112
        if self.finished:
 
113
            raise errors.OutSideTransaction()
 
114
        if self._access_mode != 'w':
 
115
            raise errors.ReadOnlyObjectDirtiedError(self)
 
116
 
94
117
    def clear_cache(self):
95
118
        """Remove any data cached in the versioned file object."""
96
119
 
102
125
 
103
126
        Must raise RevisionAlreadyPresent if the new version is
104
127
        already present in file history."""
 
128
        self._check_write_ok()
 
129
        return self._clone_text(new_version_id, old_version_id, parents)
 
130
 
 
131
    def _clone_text(self, new_version_id, old_version_id, parents):
 
132
        """Helper function to do the _clone_text work."""
105
133
        raise NotImplementedError(self.clone_text)
106
134
 
107
135
    def create_empty(self, name, transport, mode=None):
121
149
        the parents list must be a superset of the current
122
150
        list.
123
151
        """
 
152
        self._check_write_ok()
 
153
        return self._fix_parents(version, new_parents)
 
154
 
 
155
    def _fix_parents(self, version, new_parents):
 
156
        """Helper for fix_parents."""
124
157
        raise NotImplementedError(self.fix_parents)
125
158
 
126
159
    def get_suffixes(self):
234
267
        are not present in the other files history unless ignore_missing
235
268
        is supplied when they are silently skipped.
236
269
        """
 
270
        self._check_write_ok()
237
271
        return InterVersionedFile.get(other, self).join(
238
272
            pb,
239
273
            msg,
254
288
        """
255
289
        raise NotImplementedError(self.iter_lines_added_or_present_in_versions)
256
290
 
 
291
    def transaction_finished(self):
 
292
        """The transaction that this file was opened in has finished.
 
293
 
 
294
        This records self.finished = True and should cause all mutating
 
295
        operations to error.
 
296
        """
 
297
        self.finished = True
 
298
 
257
299
    @deprecated_method(zero_eight)
258
300
    def walk(self, version_ids=None):
259
301
        """Walk the versioned file as a weave-like structure, for