~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repofmt/pack_repo.py

Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
        pack,
27
27
        ui,
28
28
        )
 
29
from bzrlib.graph import Graph
29
30
from bzrlib.index import (
30
31
    GraphIndex,
31
32
    GraphIndexBuilder,
73
74
    added text, reducing memory and object pressure.
74
75
    """
75
76
 
 
77
    def __init__(self, repository, parents, config, timestamp=None,
 
78
                 timezone=None, committer=None, revprops=None,
 
79
                 revision_id=None):
 
80
        CommitBuilder.__init__(self, repository, parents, config,
 
81
            timestamp=timestamp, timezone=timezone, committer=committer,
 
82
            revprops=revprops, revision_id=revision_id)
 
83
        self._file_graph = Graph(
 
84
            repository._pack_collection.text_index.combined_index)
 
85
 
76
86
    def _add_text_to_weave(self, file_id, new_lines, parents, nostore_sha):
77
87
        return self.repository._pack_collection._add_text_to_weave(file_id,
78
88
            self._new_revision_id, new_lines, parents, nostore_sha,
79
89
            self.random_revid)
80
90
 
 
91
    def _heads(self, file_id, revision_ids):
 
92
        keys = [(file_id, revision_id) for revision_id in revision_ids]
 
93
        return set([key[1] for key in self._file_graph.heads(keys)])
 
94
 
81
95
 
82
96
class PackRootCommitBuilder(RootCommitBuilder):
83
97
    """A subclass of RootCommitBuilder to add texts with pack semantics.
86
100
    added text, reducing memory and object pressure.
87
101
    """
88
102
 
 
103
    def __init__(self, repository, parents, config, timestamp=None,
 
104
                 timezone=None, committer=None, revprops=None,
 
105
                 revision_id=None):
 
106
        CommitBuilder.__init__(self, repository, parents, config,
 
107
            timestamp=timestamp, timezone=timezone, committer=committer,
 
108
            revprops=revprops, revision_id=revision_id)
 
109
        self._file_graph = Graph(
 
110
            repository._pack_collection.text_index.combined_index)
 
111
 
89
112
    def _add_text_to_weave(self, file_id, new_lines, parents, nostore_sha):
90
113
        return self.repository._pack_collection._add_text_to_weave(file_id,
91
114
            self._new_revision_id, new_lines, parents, nostore_sha,
92
115
            self.random_revid)
93
116
 
 
117
    def _heads(self, file_id, revision_ids):
 
118
        keys = [(file_id, revision_id) for revision_id in revision_ids]
 
119
        return set([key[1] for key in self._file_graph.heads(keys)])
 
120
 
94
121
 
95
122
class Pack(object):
96
123
    """An in memory proxy for a pack and its indices.
718
745
        """
719
746
        pb = ui.ui_factory.nested_progress_bar()
720
747
        try:
721
 
            return self._do_copy_nodes_graph(nodes, index_map, writer,
722
 
                write_index, output_lines, pb)
723
 
        finally:
 
748
            for result in self._do_copy_nodes_graph(nodes, index_map, writer,
 
749
                write_index, output_lines, pb):
 
750
                yield result
 
751
        except Exception:
 
752
            # Python 2.4 does not permit try:finally: in a generator.
 
753
            pb.finished()
 
754
            raise
 
755
        else:
724
756
            pb.finished()
725
757
 
726
758
    def _do_copy_nodes_graph(self, nodes, index_map, writer, write_index,