Skip to content
Snippets Groups Projects
Commit 4aefe6e1 authored by Antoine Lambert's avatar Antoine Lambert
Browse files

directory: Ensure to filter out .hg dirs in HgCheckoutLoader

Those are mercurial related and should not end up in the directory
archived by that loader.

Related to swh/infra/sysadm-environment#5256.
parent 47801da0
No related branches found
No related tags found
No related merge requests found
Pipeline #7273 passed
...@@ -6,11 +6,12 @@ ...@@ -6,11 +6,12 @@
from os.path import basename from os.path import basename
from pathlib import Path from pathlib import Path
import tempfile import tempfile
from typing import Iterator from typing import Any, Iterable, Iterator
from swh.loader.core.loader import BaseDirectoryLoader from swh.loader.core.loader import BaseDirectoryLoader
from swh.loader.mercurial.hgutil import clone from swh.loader.mercurial.hgutil import clone
from swh.loader.mercurial.utils import raise_not_found_repository from swh.loader.mercurial.utils import raise_not_found_repository
from swh.model.from_disk import ignore_empty_directories, ignore_named_directories
from swh.model.model import Snapshot, SnapshotBranch, TargetType from swh.model.model import Snapshot, SnapshotBranch, TargetType
...@@ -40,6 +41,13 @@ def clone_repository(repo_url: str, hg_changeset: str, target: Path) -> Path: ...@@ -40,6 +41,13 @@ def clone_repository(repo_url: str, hg_changeset: str, target: Path) -> Path:
return local_clone_dir return local_clone_dir
def list_hg_tree(dirpath: bytes, dirname: bytes, entries: Iterable[Any]) -> bool:
"""List a mercurial tree. This ignores any repo_path/.hg/* and empty folders."""
return ignore_named_directories([b".hg"])(
dirpath, dirname, entries
) and ignore_empty_directories(dirpath, dirname, entries)
class HgCheckoutLoader(BaseDirectoryLoader): class HgCheckoutLoader(BaseDirectoryLoader):
"""Hg directory loader in charge of ingesting a mercurial tree at a specific """Hg directory loader in charge of ingesting a mercurial tree at a specific
changeset, tag or branch into the swh archive. changeset, tag or branch into the swh archive.
...@@ -63,7 +71,7 @@ class HgCheckoutLoader(BaseDirectoryLoader): ...@@ -63,7 +71,7 @@ class HgCheckoutLoader(BaseDirectoryLoader):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self.hg_changeset = kwargs.pop("ref") self.hg_changeset = kwargs.pop("ref")
super().__init__(*args, **kwargs) super().__init__(*args, dir_filter=list_hg_tree, **kwargs)
def fetch_artifact(self) -> Iterator[Path]: def fetch_artifact(self) -> Iterator[Path]:
with tempfile.TemporaryDirectory() as tmpdir: with tempfile.TemporaryDirectory() as tmpdir:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment