Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 19 additions & 27 deletions bugbug/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import lmdb
import requests
import rs_parsepatch
import tenacity
from tqdm import tqdm

from bugbug import db, rust_code_analysis_server, utils
Expand Down Expand Up @@ -1520,36 +1519,29 @@ def clone(

def pull(repo_dir: str, branch: str, revision: str) -> None:
"""Pull a revision from a branch of a remote repository into a local repository."""

@tenacity.retry(
stop=tenacity.stop_after_attempt(2),
reraise=True,
after=tenacity.after_log(logger, logging.DEBUG),
retry=tenacity.retry_if_exception_type(subprocess.TimeoutExpired),
cmd = _build_hg_cmd(
"robustcheckout",
f"https://hg.mozilla.org/{branch}/".encode("ascii"),
repo_dir,
purge=False,
sharebase=f"{repo_dir}-shared",
revision=revision.encode("ascii"),
noupdate=True,
)
def trigger_pull() -> None:
cmd = _build_hg_cmd(
"pull",
f"https://hg.mozilla.org/{branch}/".encode("ascii"),
r=revision.encode("ascii"),
debug=True,
)

p = subprocess.Popen(cmd, cwd=repo_dir)

try:
p.wait(timeout=180)
except subprocess.TimeoutExpired:
p.terminate()
p.wait()
raise
p = subprocess.Popen(cmd, cwd=repo_dir)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this is a good time to switch to subprocess.run(cmd, cwd=repo_dir, timeout=180...?


if p.returncode != 0:
raise RuntimeError(
f"Error {p.returncode} when pulling {revision} from {branch}"
)
try:
p.wait(timeout=180)
except subprocess.TimeoutExpired:
p.terminate()
p.wait()
raise

trigger_pull()
if p.returncode != 0:
raise RuntimeError(
f"Error {p.returncode} when pulling {revision} from {branch}"
)


if __name__ == "__main__":
Expand Down
3 changes: 2 additions & 1 deletion http_service/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ def mock_repo(
orig_hgutil_cmdbuilder = hglib.util.cmdbuilder

def hglib_cmdbuilder(name, *args, **kwargs):
if name == "pull":
if name == "robustcheckout":
name = "pull"
args = list(args)
args[0] = str(remote_dir).encode("ascii")

Expand Down