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

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2020-06-12 01:45:56 UTC
  • mfrom: (7513.1.2 pypy3)
  • Revision ID: breezy.the.bot@gmail.com-20200612014556-tsc8assk3d0luziu
Avoid deprecated behaviour in ElementTree.

Merged from https://code.launchpad.net/~jelmer/brz/pypy3/+merge/385611

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
"""Map from Git sha's to Bazaar objects."""
19
19
 
20
 
from __future__ import absolute_import
21
 
 
22
20
from dulwich.objects import (
23
21
    Blob,
24
22
    Commit,
46
44
from ..revision import (
47
45
    NULL_REVISION,
48
46
    )
49
 
from ..sixish import viewitems
50
47
from ..tree import InterTree
51
48
from ..bzr.testament import (
52
49
    StrictTestament3,
135
132
        self._cache[tree.get_revision_id()] = tree
136
133
 
137
134
 
138
 
def _find_missing_bzr_revids(graph, want, have):
 
135
def _find_missing_bzr_revids(graph, want, have, shallow=None):
139
136
    """Find the revisions that have to be pushed.
140
137
 
141
138
    :param get_parent_map: Function that returns the parents for a sequence
145
142
    :return: Set of revisions to fetch
146
143
    """
147
144
    handled = set(have)
 
145
    if shallow:
 
146
        # Shallows themselves still need to be fetched, but let's exclude their
 
147
        # parents.
 
148
        for ps in graph.get_parent_map(shallow).values():
 
149
            handled.update(ps)
 
150
    handled.add(NULL_REVISION)
148
151
    todo = set()
149
152
    for rev in want:
150
153
        extra_todo = graph.find_unique_ancestors(rev, handled)
151
154
        todo.update(extra_todo)
152
155
        handled.update(extra_todo)
153
 
    if NULL_REVISION in todo:
154
 
        todo.remove(NULL_REVISION)
155
156
    return todo
156
157
 
157
158
 
307
308
    for (path, file_id), chunks in tree.iter_files_bytes(
308
309
            [(path, (path, file_id)) for (path, file_id) in new_blobs]):
309
310
        obj = Blob()
310
 
        obj.chunked = chunks
 
311
        obj.chunked = list(chunks)
311
312
        if add_cache_entry is not None:
312
313
            add_cache_entry(obj, (file_id, tree.get_file_revision(path)), path)
313
314
        yield path, obj, (file_id, tree.get_file_revision(path))
400
401
 
401
402
    def __iter__(self):
402
403
        return ((self.store[object_id], path) for (object_id, path) in
403
 
                viewitems(self.objects))
 
404
                self.objects.items())
404
405
 
405
406
 
406
407
class BazaarObjectStore(BaseObjectStore):
568
569
            ((key[0], key[1], key) for key in keys))
569
570
        for (file_id, revision, expected_sha), chunks in stream:
570
571
            blob = Blob()
571
 
            blob.chunked = chunks
 
572
            blob.chunked = list(chunks)
572
573
            if blob.id != expected_sha and blob.data == b"":
573
574
                # Perhaps it's a symlink ?
574
575
                tree = self.tree_cache.revision_tree(revision)
758
759
        else:
759
760
            raise KeyError(sha)
760
761
 
761
 
    def generate_lossy_pack_data(self, have, want, progress=None,
 
762
    def generate_lossy_pack_data(self, have, want, shallow=None,
 
763
                                 progress=None,
762
764
                                 get_tagged=None, ofs_delta=False):
763
765
        return pack_objects_to_data(
764
 
            self.generate_pack_contents(have, want, progress, get_tagged,
 
766
            self.generate_pack_contents(have, want, progress=progress,
 
767
                                        shallow=shallow, get_tagged=get_tagged,
765
768
                                        lossy=True))
766
769
 
767
 
    def generate_pack_contents(self, have, want, progress=None,
 
770
    def generate_pack_contents(self, have, want, shallow=None, progress=None,
768
771
                               ofs_delta=False, get_tagged=None, lossy=False):
769
772
        """Iterate over the contents of a pack file.
770
773
 
793
796
                    pending.add(type_data[0])
794
797
            except KeyError:
795
798
                pass
 
799
        shallows = set()
 
800
        for commit_sha in shallow or set():
 
801
            try:
 
802
                for (type, type_data) in ret[commit_sha]:
 
803
                    if type != "commit":
 
804
                        raise AssertionError("Type was %s, not commit" % type)
 
805
                    shallows.add(type_data[0])
 
806
            except KeyError:
 
807
                pass
796
808
 
797
809
        graph = self.repository.get_graph()
798
 
        todo = _find_missing_bzr_revids(graph, pending, processed)
 
810
        todo = _find_missing_bzr_revids(graph, pending, processed, shallow)
799
811
        ret = PackTupleIterable(self)
800
812
        with ui.ui_factory.nested_progress_bar() as pb:
801
813
            for i, revid in enumerate(graph.iter_topo_order(todo)):