~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to multiparent/__init__.py

  • Committer: Aaron Bentley
  • Date: 2007-04-11 06:39:09 UTC
  • mto: (2520.4.1 bzr.mpbundle)
  • mto: This revision was merged to the branch mainline in revision 2631.
  • Revision ID: aaron.bentley@utoronto.ca-20070411063909-t630ktlwrss64yyk
Make benchmarks for mp

Show diffs side-by-side

added added

removed removed

Lines of Context:
161
161
class MultiVersionedFile(object):
162
162
    """VersionedFile skeleton for MultiParent"""
163
163
 
164
 
    def __init__(self):
 
164
    def __init__(self, snapshot_interval=25):
165
165
        self._diffs = {}
166
166
        self._lines = {}
167
167
        self._parents = {}
 
168
        self._snapshots = {}
 
169
        self.snapshot_interval = snapshot_interval
 
170
 
 
171
    def do_snapshot(self, version_id, parent_ids):
 
172
        if len(parent_ids) == 0:
 
173
            return False
 
174
        counter = 0
 
175
        while counter < self.snapshot_interval:
 
176
            if len(parent_ids) == 0:
 
177
                return False
 
178
            version_id = parent_ids[0]
 
179
            if self._snapshots[version_id]:
 
180
                return False
 
181
            counter += 1
 
182
            parent_ids = self._parents[version_id]
 
183
        return True
168
184
 
169
185
    def add_version(self, lines, version_id, parent_ids):
170
 
        parent_lines = [self._lines[p] for p in parent_ids]
171
 
        diff = MultiParent.from_lines(lines, parent_lines)
 
186
        if self.do_snapshot(version_id, parent_ids):
 
187
            self._snapshots[version_id] = True
 
188
            diff = MultiParent([NewText(lines)])
 
189
        else:
 
190
            self._snapshots[version_id] = False
 
191
            parent_lines = [self._lines[p] for p in parent_ids]
 
192
            diff = MultiParent.from_lines(lines, parent_lines)
172
193
        self.add_diff(diff, version_id, parent_ids)
173
194
        self._lines[version_id] = lines
174
195