/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/versionedfile.py

Merge from bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
    revision,
31
31
    ui,
32
32
    )
 
33
from bzrlib.graph import Graph
33
34
from bzrlib.transport.memory import MemoryTransport
34
35
""")
35
36
 
54
55
    Texts are identified by a version-id string.
55
56
    """
56
57
 
57
 
    def __init__(self, access_mode):
58
 
        self.finished = False
59
 
        self._access_mode = access_mode
60
 
 
61
58
    @staticmethod
62
59
    def check_not_reserved_id(version_id):
63
60
        revision.check_not_reserved_id(version_id)
70
67
        """Return a unsorted list of versions."""
71
68
        raise NotImplementedError(self.versions)
72
69
 
 
70
    @deprecated_method(one_four)
73
71
    def has_ghost(self, version_id):
74
72
        """Returns whether version is present as a ghost."""
75
73
        raise NotImplementedError(self.has_ghost)
159
157
            if '\n' in line[:-1]:
160
158
                raise errors.BzrBadParameterContainsNewline("lines")
161
159
 
162
 
    def _check_write_ok(self):
163
 
        """Is the versioned file marked as 'finished' ? Raise if it is."""
164
 
        if self.finished:
165
 
            raise errors.OutSideTransaction()
166
 
        if self._access_mode != 'w':
167
 
            raise errors.ReadOnlyObjectDirtiedError(self)
168
 
 
 
160
    @deprecated_method(one_four)
169
161
    def enable_cache(self):
170
162
        """Tell this versioned file that it should cache any data it reads.
171
163
        
173
165
        """
174
166
        pass
175
167
    
 
168
    @deprecated_method(one_four)
176
169
    def clear_cache(self):
177
170
        """Remove any data cached in the versioned file object.
178
171
 
180
173
        """
181
174
        pass
182
175
 
 
176
    @deprecated_method(one_four)
183
177
    def clone_text(self, new_version_id, old_version_id, parents):
184
178
        """Add an identical text to old_version_id as new_version_id.
185
179
 
189
183
        Must raise RevisionAlreadyPresent if the new version is
190
184
        already present in file history."""
191
185
        self._check_write_ok()
192
 
        return self._clone_text(new_version_id, old_version_id, parents)
193
 
 
194
 
    def _clone_text(self, new_version_id, old_version_id, parents):
195
 
        """Helper function to do the _clone_text work."""
196
 
        raise NotImplementedError(self.clone_text)
197
 
 
198
 
    def create_empty(self, name, transport, mode=None):
199
 
        """Create a new versioned file of this exact type.
200
 
 
201
 
        :param name: the file name
202
 
        :param transport: the transport
203
 
        :param mode: optional file mode.
204
 
        """
205
 
        raise NotImplementedError(self.create_empty)
 
186
        return self.add_lines(new_version_id, parents,
 
187
            self.get_lines(old_version_id))
206
188
 
207
189
    def get_format_signature(self):
208
190
        """Get a text description of the data encoding in this file.
289
271
            if expected_sha1 != sha1:
290
272
                raise errors.VersionedFileInvalidChecksum(version)
291
273
 
 
274
    @deprecated_method(one_four)
292
275
    def get_sha1(self, version_id):
293
276
        """Get the stored sha1 sum for the given revision.
294
277
        
295
278
        :param version_id: The name of the version to lookup
296
279
        """
297
 
        raise NotImplementedError(self.get_sha1)
 
280
        return self.get_sha1s([version_id])[0]
298
281
 
299
282
    def get_sha1s(self, version_ids):
300
283
        """Get the stored sha1 sums for the given revisions.
304
287
        """
305
288
        raise NotImplementedError(self.get_sha1s)
306
289
 
307
 
    def get_suffixes(self):
308
 
        """Return the file suffixes associated with this versioned file."""
309
 
        raise NotImplementedError(self.get_suffixes)
310
 
    
311
290
    def get_text(self, version_id):
312
291
        """Return version contents as a text string.
313
292
 
360
339
        but are not explicitly marked.
361
340
        """
362
341
        raise NotImplementedError(self.get_ancestry_with_ghosts)
363
 
        
 
342
    
 
343
    @deprecated_method(one_four)
364
344
    def get_graph(self, version_ids=None):
365
345
        """Return a graph from the versioned file. 
366
346
        
369
349
                            None means retrieve all versions.
370
350
        """
371
351
        if version_ids is None:
372
 
            return dict(self.iter_parents(self.versions()))
373
 
        result = {}
374
 
        pending = set(version_ids)
375
 
        while pending:
376
 
            this_iteration = pending
377
 
            pending = set()
378
 
            for version, parents in self.iter_parents(this_iteration):
379
 
                result[version] = parents
380
 
                for parent in parents:
381
 
                    if parent in result:
382
 
                        continue
383
 
                    pending.add(parent)
 
352
            result = self.get_parent_map(self.versions())
 
353
        else:
 
354
            result = {}
 
355
            pending = set(version_ids)
 
356
            while pending:
 
357
                this_iteration = pending
 
358
                pending = set()
 
359
                parents = self.get_parent_map(this_iteration)
 
360
                for version, parents in parents.iteritems():
 
361
                    result[version] = parents
 
362
                    for parent in parents:
 
363
                        if parent in result:
 
364
                            continue
 
365
                        pending.add(parent)
 
366
        references = set()
 
367
        for parents in result.itervalues():
 
368
            references.update(parents)
 
369
        existing_parents = self.get_parent_map(references)
 
370
        for key, parents in result.iteritems():
 
371
            present_parents = [parent for parent in parents if parent in
 
372
                existing_parents]
 
373
            result[key] = tuple(present_parents)
384
374
        return result
385
375
 
 
376
    @deprecated_method(one_four)
386
377
    def get_graph_with_ghosts(self):
387
378
        """Return a graph for the entire versioned file.
388
379
        
431
422
        except KeyError:
432
423
            raise errors.RevisionNotPresent(version_id, self)
433
424
 
 
425
    @deprecated_method(one_four)
434
426
    def annotate_iter(self, version_id):
435
427
        """Yield list of (version-id, line) pairs for the specified
436
428
        version.
438
430
        Must raise RevisionNotPresent if the given version is
439
431
        not present in file history.
440
432
        """
441
 
        raise NotImplementedError(self.annotate_iter)
 
433
        return iter(self.annotate(version_id))
442
434
 
443
435
    def annotate(self, version_id):
444
 
        return list(self.annotate_iter(version_id))
 
436
        """Return a list of (version-id, line) tuples for version_id.
 
437
 
 
438
        :raise RevisionNotPresent: If the given version is
 
439
        not present in file history.
 
440
        """
 
441
        raise NotImplementedError(self.annotate)
445
442
 
446
443
    def join(self, other, pb=None, msg=None, version_ids=None,
447
444
             ignore_missing=False):
483
480
        """
484
481
        raise NotImplementedError(self.iter_lines_added_or_present_in_versions)
485
482
 
 
483
    @deprecated_method(one_four)
486
484
    def iter_parents(self, version_ids):
487
485
        """Iterate through the parents for many version ids.
488
486
 
494
492
        """
495
493
        return self.get_parent_map(version_ids).iteritems()
496
494
 
497
 
    def transaction_finished(self):
498
 
        """The transaction that this file was opened in has finished.
499
 
 
500
 
        This records self.finished = True and should cause all mutating
501
 
        operations to error.
502
 
        """
503
 
        self.finished = True
504
 
 
505
495
    def plan_merge(self, ver_a, ver_b):
506
496
        """Return pseudo-annotation indicating how the two versions merge.
507
497
 
762
752
        are not present in the other file's history unless ignore_missing is 
763
753
        supplied in which case they are silently skipped.
764
754
        """
765
 
        # the default join: 
766
 
        # - if the target is empty, just add all the versions from 
767
 
        #   source to target, otherwise:
768
 
        # - make a temporary versioned file of type target
769
 
        # - insert the source content into it one at a time
770
 
        # - join them
771
 
        if not self.target.versions():
772
 
            target = self.target
773
 
        else:
774
 
            # Make a new target-format versioned file. 
775
 
            temp_source = self.target.create_empty("temp", MemoryTransport())
776
 
            target = temp_source
 
755
        target = self.target
777
756
        version_ids = self._get_source_version_ids(version_ids, ignore_missing)
778
 
        graph = self.source.get_graph(version_ids)
779
 
        order = tsort.topo_sort(graph.items())
 
757
        graph = Graph(self.source)
 
758
        search = graph._make_breadth_first_searcher(version_ids)
 
759
        transitive_ids = set()
 
760
        map(transitive_ids.update, list(search))
 
761
        parent_map = self.source.get_parent_map(transitive_ids)
 
762
        order = tsort.topo_sort(parent_map.items())
780
763
        pb = ui.ui_factory.nested_progress_bar()
781
764
        parent_texts = {}
782
765
        try:
794
777
            # memory pressure reduction. RBC 20060313
795
778
            # pb.update('Converting versioned data', 0, len(order))
796
779
            total = len(order)
797
 
            parent_map = self.source.get_parent_map(order)
798
780
            for index, version in enumerate(order):
799
781
                pb.update('Converting versioned data', index, total)
 
782
                if version in target:
 
783
                    continue
800
784
                _, _, parent_text = target.add_lines(version,
801
785
                                               parent_map[version],
802
786
                                               self.source.get_lines(version),
803
787
                                               parent_texts=parent_texts)
804
788
                parent_texts[version] = parent_text
805
 
            
806
 
            # this should hit the native code path for target
807
 
            if target is not self.target:
808
 
                return self.target.join(temp_source,
809
 
                                        pb,
810
 
                                        msg,
811
 
                                        version_ids,
812
 
                                        ignore_missing)
813
 
            else:
814
 
                return total
 
789
            return total
815
790
        finally:
816
791
            pb.finished()
817
792