Changeset View
Changeset View
Standalone View
Standalone View
swh/vault/cookers/git_bare.py
Show First 20 Lines • Show All 297 Lines • ▼ Show 20 Lines | def push_revision_subgraph(self, obj_id: Sha1Git) -> None: | ||||
# revisions | # revisions | ||||
self._walker_state = walker.export_state() | self._walker_state = walker.export_state() | ||||
def push_snapshot_subgraph(self, obj_id: Sha1Git) -> None: | def push_snapshot_subgraph(self, obj_id: Sha1Git) -> None: | ||||
"""Fetches a snapshot and all its children, and writes them to disk""" | """Fetches a snapshot and all its children, and writes them to disk""" | ||||
loaded_from_graph = False | loaded_from_graph = False | ||||
if self.graph: | if self.graph: | ||||
pass # TODO | revision_ids = [] | ||||
release_ids = [] | |||||
from swh.graph.client import GraphArgumentException | |||||
# First, try to cook using swh-graph, as it is more efficient than | |||||
# swh-storage for querying the history | |||||
obj_swhid = identifiers.CoreSWHID( | |||||
object_type=identifiers.ObjectType.SNAPSHOT, object_id=obj_id, | |||||
) | |||||
try: | |||||
swhids = map( | |||||
identifiers.CoreSWHID.from_string, | |||||
self.graph.visit_nodes(str(obj_swhid), edges="snp:*,rel:*,rev:rev"), | |||||
) | |||||
for swhid in swhids: | |||||
if swhid.object_type == identifiers.ObjectType.REVISION: | |||||
revision_ids.append(swhid.object_id) | |||||
elif swhid.object_type == identifiers.ObjectType.RELEASE: | |||||
release_ids.append(swhid.object_id) | |||||
elif swhid.object_type == identifiers.ObjectType.SNAPSHOT: | |||||
douardda: do we really want "just" an assert here (which means, for me, "do not check this in… | |||||
Done Inline ActionsIf we want to use -O, then there are many more asserts to replace all over the codebase. vlorentz: If we want to use `-O`, then there are many more `asserts` to replace all over the codebase. | |||||
assert ( | |||||
swhid.object_id == obj_id | |||||
), f"Snapshot {obj_id.hex()} references a different snapshot" | |||||
else: | |||||
Not Done Inline Actionswhy a NotImplementedError here? is there a possibility that this will make sense and be implemented some day? douardda: why a NotImplementedError here? is there a possibility that this will make sense and be… | |||||
Done Inline ActionsBoth Git's and SWH's data models allow it, so we have to do something about it. raising NotImplementedError just defers the decision because it's really an edge case and I don't want to think about it for now. (It would also probably require changing the test framework, because the Git CLI probably does not allow it) vlorentz: Both Git's and SWH's data models allow it, so we have to do something about it. raising… | |||||
raise NotImplementedError( | |||||
f"{swhid.object_type} objects in snapshot subgraphs." | |||||
) | |||||
except GraphArgumentException: | |||||
# Revision not found in the graph | |||||
pass | |||||
else: | |||||
self._push(self._rev_stack, revision_ids) | |||||
self._push(self._rel_stack, release_ids) | |||||
loaded_from_graph = True | |||||
# TODO: when self.graph is available and supports edge labels, use it | # TODO: when self.graph is available and supports edge labels, use it | ||||
# directly to get branch names. | # directly to get branch names. | ||||
snapshot = snapshot_get_all_branches(self.storage, obj_id) | snapshot = snapshot_get_all_branches(self.storage, obj_id) | ||||
assert snapshot, "Unknown snapshot" # should have been caught by check_exists() | assert snapshot, "Unknown snapshot" # should have been caught by check_exists() | ||||
for branch in snapshot.branches.values(): | for branch in snapshot.branches.values(): | ||||
if not loaded_from_graph: | if not loaded_from_graph: | ||||
if branch.target_type == TargetType.REVISION: | if branch.target_type == TargetType.REVISION: | ||||
▲ Show 20 Lines • Show All 120 Lines • Show Last 20 Lines |
do we really want "just" an assert here (which means, for me, "do not check this in production" since prod should/may run with -O)