diff --git a/swh/loader/mercurial/hgutil.py b/swh/loader/mercurial/hgutil.py --- a/swh/loader/mercurial/hgutil.py +++ b/swh/loader/mercurial/hgutil.py @@ -1,11 +1,16 @@ +# Copyright (C) 2020-2021 The Software Heritage developers +# See the AUTHORS file at the top-level directory of this distribution +# License: GNU General Public License version 3, or any later version +# See top-level LICENSE file for more information + import io -import traceback from multiprocessing import Process, Queue +import traceback from typing import Dict, NewType # The internal Mercurial API is not guaranteed to be stable. +from mercurial import context, hg, util # type: ignore import mercurial.ui # type: ignore -from mercurial import context, hg, util NULLID = mercurial.node.nullid HgNodeId = NewType("HgNodeId", bytes) @@ -46,7 +51,13 @@ errors: message queue to communicate errors """ try: - hg.clone(mercurial.ui.ui.load(), {}, src.encode(), dest.encode()) + hg.clone( + ui=mercurial.ui.ui.load(), + peeropts={}, + source=src.encode(), + dest=dest.encode(), + update=False, + ) except Exception as e: exc_buffer = io.StringIO() traceback.print_exc(file=exc_buffer) diff --git a/swh/loader/mercurial/loader.py b/swh/loader/mercurial/loader.py --- a/swh/loader/mercurial/loader.py +++ b/swh/loader/mercurial/loader.py @@ -195,7 +195,7 @@ def do_clone(queue, origin, destination): try: - result = hglib.clone(source=origin, dest=destination) + result = hglib.clone(source=origin, dest=destination, noupdate=True) except CommandError as e: # the queued object need an empty constructor to be deserialized later queue.put(CommandErrorWrapper(e.err)) diff --git a/swh/loader/mercurial/tests/test_hgutil.py b/swh/loader/mercurial/tests/test_hgutil.py --- a/swh/loader/mercurial/tests/test_hgutil.py +++ b/swh/loader/mercurial/tests/test_hgutil.py @@ -1,4 +1,4 @@ -# Copyright (C) 2020 The Software Heritage developers +# Copyright (C) 2020-2021 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information @@ -6,8 +6,8 @@ import time import traceback -import pytest from mercurial import hg # type: ignore +import pytest from .. import hgutil @@ -17,7 +17,7 @@ dest = "/dev/null" timeout = 1 - def clone(*args): + def clone(*args, **kwargs): time.sleep(5) monkeypatch.setattr(hg, "clone", clone) @@ -32,7 +32,7 @@ dest = "/dev/null" expected_traceback = "Some traceback" - def clone(*args): + def clone(*args, **kwargs): raise ValueError() def print_exc(file): diff --git a/swh/loader/mercurial/tests/test_loader.py b/swh/loader/mercurial/tests/test_loader.py --- a/swh/loader/mercurial/tests/test_loader.py +++ b/swh/loader/mercurial/tests/test_loader.py @@ -57,11 +57,7 @@ ) assert_last_visit_matches( - swh_storage, - repo_url, - status="full", - type="hg", - snapshot=expected_snapshot.id, + swh_storage, repo_url, status="full", type="hg", snapshot=expected_snapshot.id, ) check_snapshot(expected_snapshot, swh_storage) @@ -325,7 +321,7 @@ def test_clone_with_timeout_timeout(caplog, tmp_path, monkeypatch): log = logging.getLogger("test_clone_with_timeout") - def clone_timeout(source, dest): + def clone_timeout(source, dest, *args, **kwargs): time.sleep(60) monkeypatch.setattr(hglib, "clone", clone_timeout) @@ -344,7 +340,7 @@ def test_clone_with_timeout_returns(caplog, tmp_path, monkeypatch): log = logging.getLogger("test_clone_with_timeout") - def clone_return(source, dest): + def clone_return(source, dest, *args, **kwargs): return (source, dest) monkeypatch.setattr(hglib, "clone", clone_return) @@ -357,7 +353,7 @@ def test_clone_with_timeout_exception(caplog, tmp_path, monkeypatch): log = logging.getLogger("test_clone_with_timeout") - def clone_return(source, dest): + def clone_return(source, dest, *args, **kwargs): raise ValueError("Test exception") monkeypatch.setattr(hglib, "clone", clone_return)