~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/versionedfile.py

Teach versioned files to prevent mutation after finishing.

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):
 
54
        self.finished = False
 
55
 
52
56
    def copy_to(self, name, transport):
53
57
        """Copy this versioned file to name on transport."""
54
58
        raise NotImplementedError(self.copy_to)
80
84
        already present in file history.
81
85
 
82
86
        Must raise RevisionNotPresent if any of the given parents are
83
 
        not present in file history."""
 
87
        not present in file history.
 
88
        """
 
89
        self._check_finished()
 
90
        self._add_lines(version_id, parents, lines)
 
91
 
 
92
    def _add_lines(self, version_id, parents, lines):
 
93
        """Helper to do the class specific add_lines."""
84
94
        raise NotImplementedError(self.add_lines)
85
95
 
86
96
    def add_lines_with_ghosts(self, version_id, parents, lines):
87
97
        """Add lines to the versioned file, allowing ghosts to be present."""
 
98
        self._check_finished()
 
99
        self._add_lines_with_ghosts(version_id, parents, lines)
 
100
 
 
101
    def _add_lines_with_ghosts(self, version_id, parents, lines):
 
102
        """Helper to do class specific add_lines_with_ghosts."""
88
103
        raise NotImplementedError(self.add_lines_with_ghosts)
89
104
 
90
105
    def check(self, progress_bar=None):
91
106
        """Check the versioned file for integrity."""
92
107
        raise NotImplementedError(self.check)
93
108
 
 
109
    def _check_finished(self):
 
110
        """Is the versioned file marked as 'finished' ? Raise if it is."""
 
111
        if self.finished:
 
112
            raise errors.OutSideTransaction()
 
113
 
94
114
    def clear_cache(self):
95
115
        """Remove any data cached in the versioned file object."""
96
116
 
121
141
        the parents list must be a superset of the current
122
142
        list.
123
143
        """
 
144
        self._check_finished()
 
145
        self._fix_parents(version, new_parents)
 
146
 
 
147
    def _fix_parents(self, version, new_parents):
 
148
        """Helper for fix_parents."""
124
149
        raise NotImplementedError(self.fix_parents)
125
150
 
126
151
    def get_suffixes(self):
234
259
        are not present in the other files history unless ignore_missing
235
260
        is supplied when they are silently skipped.
236
261
        """
 
262
        self._check_finished()
237
263
        return InterVersionedFile.get(other, self).join(
238
264
            pb,
239
265
            msg,
254
280
        """
255
281
        raise NotImplementedError(self.iter_lines_added_or_present_in_versions)
256
282
 
 
283
    def transaction_finished(self):
 
284
        """The transaction that this file was opened in has finished.
 
285
 
 
286
        This records self.finished = True and should cause all mutating
 
287
        operations to error.
 
288
        """
 
289
        self.finished = True
 
290
 
257
291
    @deprecated_method(zero_eight)
258
292
    def walk(self, version_ids=None):
259
293
        """Walk the versioned file as a weave-like structure, for