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

  • Committer: Martin Pool
  • Date: 2005-09-19 11:50:47 UTC
  • Revision ID: mbp@sourcefrog.net-20050919115047-4f6bc984a56405bb
- split out merge-ancestry stuff where it can be reused

Show diffs side-by-side

added added

removed removed

Lines of Context:
234
234
        This should be the merged ancestry of all parents, plus the
235
235
        new revision id."""
236
236
        w = self.weave_store.get_weave_or_empty(ANCESTRY_FILEID)
237
 
        lines = self._merge_ancestry_lines(w)
 
237
        lines = self._make_ancestry(w)
238
238
        w.add(self.rev_id, self.parents, lines)
239
239
        self.weave_store.put_weave(ANCESTRY_FILEID, w)
240
240
 
241
241
 
242
 
    def _merge_ancestry_lines(self, ancestry_weave):
 
242
    def _make_ancestry(self, ancestry_weave):
243
243
        """Return merged ancestry lines.
244
244
 
245
245
        The lines are revision-ids followed by newlines."""
246
 
        seen = set()
247
 
        ancs = []
248
 
        for parent_id in self.parents:
249
 
            for line in ancestry_weave.get(parent_id):
250
 
                assert line[-1] == '\n'
251
 
                if line not in seen:
252
 
                    ancs.append(line)
253
 
                    seen.add(line)
254
 
        r = self.rev_id + '\n'
255
 
        assert r not in ancs
256
 
        ancs.append(r)
257
 
        mutter('merged ancestry of {%s}:\n%s', self.rev_id, ''.join(ancs))
258
 
        return ancs
 
246
        parent_ancestries = [ancestry_weave.get(p) for p in self.parents]
 
247
        new_lines = merge_ancestry_lines(self.rev_id, parent_ancestries)
 
248
        mutter('merged ancestry of {%s}:\n%s', self.rev_id, ''.join(new_lines))
 
249
        return new_lines
259
250
 
260
251
 
261
252
    def _gather_parents(self):
487
478
 
488
479
 
489
480
    
 
481
def merge_ancestry_lines(rev_id, ancestries):
 
482
    """Return merged ancestry lines.
 
483
 
 
484
    rev_id -- id of the new revision
 
485
    
 
486
    ancestries -- a sequence of ancestries for parent revisions,
 
487
        as newline-terminated line lists.
 
488
    """
 
489
    if len(ancestries) == 0:
 
490
        return [rev_id + '\n']
 
491
    seen = set(ancestries[0])
 
492
    ancs = ancestries[0][:]    
 
493
    for parent_ancestry in ancestries[1:]:
 
494
        for line in parent_ancestry:
 
495
            assert line[-1] == '\n'
 
496
            if line not in seen:
 
497
                ancs.append(line)
 
498
                seen.add(line)
 
499
    r = rev_id + '\n'
 
500
    assert r not in seen
 
501
    ancs.append(r)
 
502
    return ancs
 
503