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

More work on roundtrip push support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
    Commit,
22
22
    Tree,
23
23
    sha_to_hex,
24
 
    ZERO_SHA,
25
24
    )
26
25
from dulwich.object_store import (
27
26
    BaseObjectStore,
109
108
        self._cache.add(tree.get_revision_id(), tree)
110
109
 
111
110
 
112
 
def _find_missing_bzr_revids(graph, want, have):
 
111
def _find_missing_bzr_revids(get_parent_map, want, have):
113
112
    """Find the revisions that have to be pushed.
114
113
 
115
114
    :param get_parent_map: Function that returns the parents for a sequence
118
117
    :param have: Revisions the target already has
119
118
    :return: Set of revisions to fetch
120
119
    """
 
120
    pending = want - have
 
121
    processed = set()
121
122
    todo = set()
122
 
    for rev in want:
123
 
        todo.update(graph.find_unique_ancestors(rev, have))
 
123
    while pending:
 
124
        processed.update(pending)
 
125
        next_map = get_parent_map(pending)
 
126
        next_pending = set()
 
127
        for item in next_map.iteritems():
 
128
            if item[0] in have:
 
129
                continue
 
130
            todo.add(item[0])
 
131
            next_pending.update(p for p in item[1] if p not in processed)
 
132
        pending = next_pending
124
133
    if NULL_REVISION in todo:
125
134
        todo.remove(NULL_REVISION)
126
135
    return todo
494
503
 
495
504
    def _lookup_revision_sha1(self, revid):
496
505
        """Return the SHA1 matching a Bazaar revision."""
 
506
        from dulwich.protocol import ZERO_SHA
497
507
        if revid == NULL_REVISION:
498
508
            return ZERO_SHA
499
509
        try:
533
543
            return False
534
544
 
535
545
    def lookup_git_shas(self, shas, update_map=True):
 
546
        from dulwich.protocol import ZERO_SHA
536
547
        ret = {}
537
548
        for sha in shas:
538
549
            if sha == ZERO_SHA:
611
622
        ret = self.lookup_git_shas(have + want)
612
623
        for commit_sha in have:
613
624
            try:
614
 
                (type, (revid, tree_sha, verifiers)) = ret[commit_sha]
 
625
                (type, (revid, tree_sha)) = ret[commit_sha]
615
626
            except KeyError:
616
627
                pass
617
628
            else:
622
633
            if commit_sha in have:
623
634
                continue
624
635
            try:
625
 
                (type, (revid, tree_sha, verifiers)) = ret[commit_sha]
 
636
                (type, (revid, tree_sha)) = ret[commit_sha]
626
637
            except KeyError:
627
638
                pass
628
639
            else:
629
640
                assert type == "commit"
630
641
                pending.add(revid)
631
642
 
632
 
        graph = self.repository.get_graph()
633
 
        todo = _find_missing_bzr_revids(graph, pending, processed)
 
643
        todo = _find_missing_bzr_revids(self.repository.get_parent_map, 
 
644
                                        pending, processed)
634
645
        trace.mutter('sending revisions %r', todo)
635
646
        ret = []
636
647
        pb = ui.ui_factory.nested_progress_bar()
637
648
        try:
638
649
            for i, revid in enumerate(todo):
639
650
                pb.update("generating git objects", i, len(todo))
640
 
                try:
641
 
                    rev = self.repository.get_revision(revid)
642
 
                except errors.NoSuchRevision:
643
 
                    continue
 
651
                rev = self.repository.get_revision(revid)
644
652
                tree = self.tree_cache.revision_tree(revid)
645
653
                for path, obj, ie in self._revision_to_objects(rev, tree,
646
654
                    roundtrip=not lossy):