/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 bzr_commit_handler.py

  • Committer: Ian Clatworthy
  • Date: 2009-02-19 07:13:43 UTC
  • mto: (0.64.125 trunk)
  • mto: This revision was merged to the branch mainline in revision 6631.
  • Revision ID: ian.clatworthy@canonical.com-20090219071343-kno3mkdy2bcmixcb
generalise RevisionLoader to RevisionStore as a repo abstraction

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""CommitHandlers that build and save revisions & their inventories."""
18
18
 
19
19
 
20
 
import os
21
20
from bzrlib import (
22
21
    errors,
23
22
    generate_ids,
31
30
class GenericCommitHandler(processor.CommitHandler):
32
31
    """Base class for Bazaar CommitHandlers."""
33
32
 
34
 
    def __init__(self, command, cache_mgr, repo, loader, verbose=False):
 
33
    def __init__(self, command, cache_mgr, rev_store, verbose=False):
35
34
        super(GenericCommitHandler, self).__init__(command)
36
35
        self.cache_mgr = cache_mgr
37
 
        self.repo = repo
38
 
        self.loader = loader
 
36
        self.rev_store = rev_store
39
37
        self.verbose = verbose
40
38
 
41
39
    def pre_process_files(self):
43
41
        self.revision_id = self.gen_revision_id()
44
42
        # cache of texts for this commit, indexed by file-id
45
43
        self.lines_for_commit = {}
46
 
        if self.loader.expects_rich_root():
 
44
        if self.rev_store.expects_rich_root():
47
45
            self.lines_for_commit[inventory.ROOT_ID] = []
48
46
 
49
47
        # Track the heads and get the real parent list
114
112
        except KeyError:
115
113
            if self.verbose:
116
114
                self.note("get_inventory cache miss for %s", revision_id)
117
 
            # Not cached so reconstruct from repository
118
 
            inv = self.revision_tree(revision_id).inventory
 
115
            # Not cached so reconstruct from the RevisionStore
 
116
            inv = self.rev_store.get_inventory(revision_id)
119
117
            self.cache_mgr.inventories[revision_id] = inv
120
118
        return inv
121
119
 
122
 
    def revision_tree(self, revision_id):
123
 
        return self.repo.revision_tree(revision_id)
124
 
 
125
120
    def _warn_unless_in_merges(self, fileid, path):
126
121
        if len(self.parents) <= 1:
127
122
            return
145
140
            inv = self.get_inventory(self.parents[0])
146
141
            # TODO: Shallow copy - deep inventory copying is expensive
147
142
            self.inventory = inv.copy()
148
 
        if self.loader.expects_rich_root():
 
143
        if self.rev_store.expects_rich_root():
149
144
            self.inventory.revision_id = self.revision_id
150
145
        else:
151
 
            # In this repository, root entries have no knit or weave. When
152
 
            # serializing out to disk and back in, root.revision is always
153
 
            # the new revision_id.
 
146
            # In this revision store, root entries have no knit or weave.
 
147
            # When serializing out to disk and back in, root.revision is
 
148
            # always the new revision_id.
154
149
            self.inventory.root.revision = self.revision_id
155
150
 
156
151
        # directory-path -> inventory-entry for current inventory
159
154
    def gen_initial_inventory(self):
160
155
        """Generate an inventory for a parentless revision."""
161
156
        inv = inventory.Inventory(revision_id=self.revision_id)
162
 
        if self.repo.supports_rich_root():
 
157
        if self.rev_store.expects_rich_root():
163
158
            # The very first root needs to have the right revision
164
159
            inv.root.revision = self.revision_id
165
160
        return inv
168
163
        """Save the revision."""
169
164
        self.cache_mgr.inventories[self.revision_id] = self.inventory
170
165
        rev = self.build_revision()
171
 
        self.loader.load(rev, self.inventory, None,
 
166
        self.rev_store.load(rev, self.inventory, None,
172
167
            lambda file_id: self._get_lines(file_id),
173
168
            lambda revision_ids: self._get_inventories(revision_ids))
174
169
 
185
180
        present = []
186
181
        inventories = []
187
182
        # If an inventory is in the cache, we assume it was
188
 
        # successfully loaded into the repsoitory
 
183
        # successfully loaded into the revision store
189
184
        for revision_id in revision_ids:
190
185
            try:
191
186
                inv = self.cache_mgr.inventories[revision_id]
193
188
            except KeyError:
194
189
                if self.verbose:
195
190
                    self.note("get_inventories cache miss for %s", revision_id)
196
 
                # Not cached so reconstruct from repository
197
 
                if self.repo.has_revision(revision_id):
198
 
                    rev_tree = self.revision_tree(revision_id)
 
191
                # Not cached so reconstruct from the revision store
 
192
                try:
 
193
                    inv = self.get_inventory(revision_id)
199
194
                    present.append(revision_id)
200
 
                else:
201
 
                    rev_tree = self.revision_tree(None)
202
 
                inv = rev_tree.inventory
 
195
                except:
 
196
                    inv = self.gen_initial_inventory()
203
197
                self.cache_mgr.inventories[revision_id] = inv
204
198
            inventories.append(inv)
205
199
        return present, inventories
223
217
        if (fileid in self.inventory and
224
218
            isinstance(self.inventory[fileid], inventory.InventoryDirectory)):
225
219
            for child_path in self.inventory[fileid].children.keys():
226
 
                self._delete_recursive(os.utils.pathjoin(path, child_path))
 
220
                self._delete_recursive(osutils.pathjoin(path, child_path))
227
221
        try:
228
222
            if self.inventory.id2path(fileid) == path:
229
223
                del self.inventory[fileid]
264
258
        ie = self.inventory[file_id]
265
259
        kind = ie.kind
266
260
        if kind == 'file':
267
 
            revtree = self.revision_tree(self.parents[0])
268
 
            content = revtree.get_file_text(file_id)
 
261
            content = self.rev_store.get_file_text(self.parents[0], file_id)
269
262
            self._modify_inventory(dest_path, kind, ie.executable, content)
270
263
        elif kind == 'symlink':
271
264
            self._modify_inventory(dest_path, kind, False, ie.symlink_target)
284
277
        if existing_id is not None:
285
278
            self.inventory.remove_recursive_id(existing_id)
286
279
        ie = self.inventory[file_id]
287
 
        lines = self.loader._get_lines(file_id, ie.revision)
 
280
        lines = self.rev_store._get_lines(file_id, ie.revision)
288
281
        self.lines_for_commit[file_id] = lines
289
282
        self.inventory.rename(file_id, new_parent_id, basename)
290
283
        self.cache_mgr.rename_path(old_path, new_path)