Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/mercurial/from_disk.py
Show First 20 Lines • Show All 315 Lines • ▼ Show 20 Lines | def fetch_data(self) -> bool: | ||||
self._repo = hgutil.repository(self._repo_directory) | self._repo = hgutil.repository(self._repo_directory) | ||||
return False | return False | ||||
def get_hg_revs_to_load(self) -> Union[HgFilteredSet, HgSpanSet]: | def get_hg_revs_to_load(self) -> Union[HgFilteredSet, HgSpanSet]: | ||||
"""Return the hg revision numbers to load.""" | """Return the hg revision numbers to load.""" | ||||
assert self._repo is not None | assert self._repo is not None | ||||
repo: hgutil.Repository = self._repo | repo: hgutil.Repository = self._repo | ||||
if self._latest_heads: | |||||
existing_heads = [] # heads that still exist in the repository | existing_heads = [] # heads that still exist in the repository | ||||
for hg_nodeid in self._latest_heads: | revs = self._latest_heads if self._latest_heads else repo.revs("all()") | ||||
for hg_nodeid in revs: | |||||
try: | try: | ||||
rev = repo[hg_nodeid].rev() | rev = repo[hg_nodeid].rev() | ||||
existing_heads.append(rev) | existing_heads.append(rev) | ||||
except KeyError: # the node does not exist anymore | except KeyError: # the node does not exist anymore | ||||
pass | pass | ||||
# select revisions that are not ancestors of heads | # select revisions that are not ancestors of heads | ||||
# and not the heads themselves | # and not the heads themselves | ||||
new_revs = repo.revs("not ::(%ld)", existing_heads) | new_revs = repo.revs("not ::(%ld)", existing_heads) | ||||
if new_revs: | if new_revs: | ||||
self.log.info("New revisions found: %d", len(new_revs)) | self.log.info("New revisions found: %d", len(new_revs)) | ||||
return new_revs | return new_revs | ||||
else: | |||||
return repo.revs("all()") | |||||
def store_data(self): | def store_data(self): | ||||
"""Store fetched data in the database.""" | """Store fetched data in the database.""" | ||||
revs = self.get_hg_revs_to_load() | revs = self.get_hg_revs_to_load() | ||||
if not revs: | if not revs: | ||||
self._load_status = "uneventful" | self._load_status = "uneventful" | ||||
return | return | ||||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | def store_data(self): | ||||
default_branch_alias = branching_info.default_branch_alias | default_branch_alias = branching_info.default_branch_alias | ||||
if default_branch_alias is not None: | if default_branch_alias is not None: | ||||
snapshot_branches[b"HEAD"] = SnapshotBranch( | snapshot_branches[b"HEAD"] = SnapshotBranch( | ||||
target=default_branch_alias, target_type=TargetType.ALIAS, | target=default_branch_alias, target_type=TargetType.ALIAS, | ||||
) | ) | ||||
snapshot = Snapshot(branches=snapshot_branches) | snapshot = Snapshot(branches=snapshot_branches) | ||||
self.storage.snapshot_add([snapshot]) | self.storage.snapshot_add([snapshot]) | ||||
self.flush() | |||||
self.loaded_snapshot_id = snapshot.id | self.loaded_snapshot_id = snapshot.id | ||||
def load_status(self) -> Dict[str, str]: | def load_status(self) -> Dict[str, str]: | ||||
"""Detailed loading status. | """Detailed loading status. | ||||
Defaults to logging an eventful load. | Defaults to logging an eventful load. | ||||
Returns: a dictionary that is eventually passed back as the task's | Returns: a dictionary that is eventually passed back as the task's | ||||
▲ Show 20 Lines • Show All 322 Lines • Show Last 20 Lines |