/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 processors/generic_processor.py

start of multiple commit handling

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
 
62
62
    def pre_process(self):
63
63
        self.cache_mgr = GenericCacheManager()
64
 
        self.last_reversion_id = None
 
64
        self.active_branch = self.branch
65
65
        self.init_stats()
66
66
 
67
67
    def post_process(self):
68
68
        self.dump_stats()
69
 
        # Update the branch, assuming the last revision is the head
 
69
        # Update the branches, assuming the last revision is the head
70
70
        note("Updating branch information ...")
71
 
        last_rev_id = self.last_revision_id
 
71
        # TODO - loop over the branches created/modified
 
72
        last_rev_id = self.cache_mgr.last_revision_ids[self.branch]
72
73
        revno = len(list(self.repo.iter_reverse_revision_history(last_rev_id)))
73
74
        self.branch.set_last_revision_info(revno, last_rev_id)
74
75
        # Update the working tree, if any
103
104
 
104
105
    def commit_handler(self, cmd):
105
106
        """Process a CommitCommand."""
106
 
        handler = GenericCommitHandler(cmd, self.repo, self.cache_mgr)
 
107
        handler = GenericCommitHandler(cmd, self.repo, self.cache_mgr,
 
108
            self.active_branch)
107
109
        # For now, put a write group around every commit. In the future,
108
110
        # we might only start/commit one every N to sppeed things up
109
111
        self.repo.start_write_group()
110
112
        try:
111
113
            handler.process()
112
 
            self.last_revision_id = handler.revision_id
 
114
            self.cache_mgr.last_revision_ids[self.active_branch] = \
 
115
                handler.revision_id
113
116
            self._revision_count += 1
114
117
        except:
115
118
            self.repo.abort_write_group()
159
162
        # we need to keep all of these but they are small
160
163
        self.revision_ids = {}
161
164
 
 
165
        # branch -> last revision-id lookup table
 
166
        self.last_revision_ids = {}
 
167
 
162
168
 
163
169
class GenericCommitHandler(processor.CommitHandler):
164
170
 
165
 
    def __init__(self, command, repo, cache_mgr):
 
171
    def __init__(self, command, repo, cache_mgr, active_branch):
166
172
        processor.CommitHandler.__init__(self, command)
167
173
        self.repo = repo
168
174
        self.cache_mgr = cache_mgr
 
175
        self.active_branch = active_branch
169
176
        # smart loader that uses these caches
170
177
        self.loader = revisionloader.RevisionLoader(repo,
171
178
            lambda revision_ids: self._get_inventories(revision_ids))
179
186
 
180
187
    def post_process_files(self):
181
188
        """Save the revision."""
 
189
        if self.command.parents:
 
190
            parents = [self.cache_mgr.revision_ids[ref]
 
191
                for ref in self.command.parents]
 
192
        else:
 
193
            # if no parents are given, the last revision on
 
194
            # the current branch is assumed according to the spec
 
195
            last_rev = self.cache_mgr.last_revision_ids.get(
 
196
                    self.active_branch)
 
197
            if last_rev:
 
198
                parents = [last_rev]
 
199
            else:
 
200
                parents = []
 
201
 
182
202
        # Derive the inventory from the previous one
183
 
        parents = [self.cache_mgr.revision_ids[ref]
184
 
            for ref in self.command.parents]
185
203
        if len(parents) == 0:
186
204
            new_inventory = self.gen_initial_inventory()
187
205
        else:
268
286
        timestamp = committer[2]
269
287
        return generate_ids.gen_revision_id(who, timestamp)
270
288
 
 
289
    def get_inventory(self, revision_id):
 
290
        """Get the inventory for a revision id."""
 
291
        try:
 
292
            inv = self.cache_mgr.inventories[revision_id]
 
293
        except KeyError:
 
294
            # TODO: count misses and/or inform the user about the miss?
 
295
            # Not cached so reconstruct from repository
 
296
            inv = self.repo.revision_tree(revision_id).inventory
 
297
            self.cache_mgr.inventories[revision_id] = inv
 
298
        return inv
 
299
 
271
300
    def _get_inventories(self, revision_ids):
272
301
        """Get the inventories for revision-ids.
273
302