Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/mercurial/from_disk.py
Show First 20 Lines • Show All 266 Lines • ▼ Show 20 Lines | def _set_recorded_state(self, latest_snapshot: Snapshot) -> None: | ||||
self._saved_tags.update( | self._saved_tags.update( | ||||
HgNodeId(extid.extid) for extid in self._get_extids_for_targets(tags) | HgNodeId(extid.extid) for extid in self._get_extids_for_targets(tags) | ||||
) | ) | ||||
def _get_extids_for_targets(self, targets: List[Sha1Git]) -> List[ExtID]: | def _get_extids_for_targets(self, targets: List[Sha1Git]) -> List[ExtID]: | ||||
"""Get all Mercurial ExtIDs for the targets in the latest snapshot""" | """Get all Mercurial ExtIDs for the targets in the latest snapshot""" | ||||
extids = [] | extids = [] | ||||
for extid in self.storage.extid_get_from_target( | for extid in self.storage.extid_get_from_target( | ||||
identifiers.ObjectType.REVISION, targets | identifiers.ObjectType.REVISION, | ||||
targets, | |||||
extid_type=EXTID_TYPE, | |||||
extid_version=EXTID_VERSION, | |||||
): | ): | ||||
if extid.extid_type != EXTID_TYPE or extid.extid_version != EXTID_VERSION: | |||||
continue | |||||
extids.append(extid) | extids.append(extid) | ||||
self._revision_nodeid_to_sha1git[ | self._revision_nodeid_to_sha1git[ | ||||
HgNodeId(extid.extid) | HgNodeId(extid.extid) | ||||
] = extid.target.object_id | ] = extid.target.object_id | ||||
if extids: | if extids: | ||||
# Filter out dangling extids, we need to load their target again | # Filter out dangling extids, we need to load their target again | ||||
revisions_missing = self.storage.revision_missing( | revisions_missing = self.storage.revision_missing( | ||||
Show All 9 Lines | class HgLoaderFromDisk(BaseLoader): | ||||
def _get_extids_for_hgnodes(self, hgnode_ids: List[HgNodeId]) -> List[ExtID]: | def _get_extids_for_hgnodes(self, hgnode_ids: List[HgNodeId]) -> List[ExtID]: | ||||
"""Get all Mercurial ExtIDs for the mercurial nodes in the list which point to | """Get all Mercurial ExtIDs for the mercurial nodes in the list which point to | ||||
a known revision. | a known revision. | ||||
""" | """ | ||||
extids = [] | extids = [] | ||||
for group_ids in grouper(hgnode_ids, n=1000): | for group_ids in grouper(hgnode_ids, n=1000): | ||||
for extid in self.storage.extid_get_from_extid(EXTID_TYPE, group_ids): | for extid in self.storage.extid_get_from_extid( | ||||
if extid.extid_version != EXTID_VERSION: | EXTID_TYPE, group_ids, version=EXTID_VERSION | ||||
continue | ): | ||||
extids.append(extid) | extids.append(extid) | ||||
self._revision_nodeid_to_sha1git[ | self._revision_nodeid_to_sha1git[ | ||||
HgNodeId(extid.extid) | HgNodeId(extid.extid) | ||||
] = extid.target.object_id | ] = extid.target.object_id | ||||
if extids: | if extids: | ||||
# Filter out dangling extids, we need to load their target again | # Filter out dangling extids, we need to load their target again | ||||
revisions_missing = self.storage.revision_missing( | revisions_missing = self.storage.revision_missing( | ||||
▲ Show 20 Lines • Show All 198 Lines • ▼ Show 20 Lines | def get_revision_id_from_hg_nodeid(self, hg_nodeid: HgNodeId) -> Sha1Git: | ||||
""" | """ | ||||
from_cache = self._revision_nodeid_to_sha1git.get(hg_nodeid) | from_cache = self._revision_nodeid_to_sha1git.get(hg_nodeid) | ||||
if from_cache is not None: | if from_cache is not None: | ||||
return from_cache | return from_cache | ||||
# The parent was not loaded in this run, get it from storage | # The parent was not loaded in this run, get it from storage | ||||
from_storage = [ | from_storage = [ | ||||
extid | extid | ||||
for extid in self.storage.extid_get_from_extid(EXTID_TYPE, ids=[hg_nodeid]) | for extid in self.storage.extid_get_from_extid( | ||||
if extid.extid_version == EXTID_VERSION | EXTID_TYPE, ids=[hg_nodeid], version=EXTID_VERSION | ||||
) | |||||
] | ] | ||||
msg = "Expected 1 match from storage for hg node %r, got %d" | msg = "Expected 1 match from storage for hg node %r, got %d" | ||||
assert len(from_storage) == 1, msg % (hg_nodeid.hex(), len(from_storage)) | assert len(from_storage) == 1, msg % (hg_nodeid.hex(), len(from_storage)) | ||||
return from_storage[0].target.object_id | return from_storage[0].target.object_id | ||||
def get_revision_parents(self, rev_ctx: hgutil.BaseContext) -> Tuple[Sha1Git, ...]: | def get_revision_parents(self, rev_ctx: hgutil.BaseContext) -> Tuple[Sha1Git, ...]: | ||||
"""Return the git sha1 of the parent revisions. | """Return the git sha1 of the parent revisions. | ||||
▲ Show 20 Lines • Show All 283 Lines • Show Last 20 Lines |