Skip to content

Commit

Permalink
run-task: update our copy of robustcheckout hg extension
Browse files Browse the repository at this point in the history
  • Loading branch information
jcristau committed Dec 24, 2024
1 parent 5a03d0f commit b037849
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions src/taskgraph/run-task/robustcheckout.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import ssl
import time

from mercurial.i18n import _ # type: ignore
from mercurial.node import hex, nullid # type: ignore
from mercurial import ( # type: ignore
from mercurial.i18n import _
from mercurial.node import hex, nullid
from mercurial import (
commands,
configitems,
error,
Expand Down Expand Up @@ -57,7 +57,7 @@


def getsparse():
from mercurial import sparse # type: ignore
from mercurial import sparse

return sparse

Expand All @@ -79,7 +79,7 @@ def peerlookup(remote, v):
b"",
b"networkattempts",
3,
b"Maximum number of attempts for network " b"operations",
b"Maximum number of attempts for network operations",
),
(b"", b"sparseprofile", b"", b"Sparse checkout profile to use (path in repo)"),
(
Expand Down Expand Up @@ -150,7 +150,7 @@ def robustcheckout(
or not re.match(b"^[a-f0-9]+$", revision)
):
raise error.Abort(
b"--revision must be a SHA-1 fragment 12-40 " b"characters long"
b"--revision must be a SHA-1 fragment 12-40 characters long"
)

sharebase = sharebase or ui.config(b"share", b"pool")
Expand All @@ -171,7 +171,7 @@ def robustcheckout(
extensions.find(b"sparse")
except KeyError:
raise error.Abort(
b"sparse extension must be enabled to use " b"--sparseprofile"
b"sparse extension must be enabled to use --sparseprofile"
)

ui.warn(b"(using Mercurial %s)\n" % util.version())
Expand Down Expand Up @@ -337,7 +337,6 @@ def callself():
@contextlib.contextmanager
def timeit(op, behavior):
behaviors.add(behavior)
start = 0
errored = False
try:
start = time.time()
Expand Down Expand Up @@ -381,14 +380,14 @@ def deletesharedstore(path=None):
# enabled sparse, we would lock them out.
if destvfs.exists() and sparse_profile and not destvfs.exists(b".hg/sparse"):
raise error.Abort(
b"cannot enable sparse profile on existing " b"non-sparse checkout",
b"cannot enable sparse profile on existing non-sparse checkout",
hint=b"use a separate working directory to use sparse",
)

# And the other direction for symmetry.
if not sparse_profile and destvfs.exists(b".hg/sparse"):
raise error.Abort(
b"cannot use non-sparse checkout on existing sparse " b"checkout",
b"cannot use non-sparse checkout on existing sparse checkout",
hint=b"use a separate working directory to use sparse",
)

Expand All @@ -408,7 +407,7 @@ def deletesharedstore(path=None):
ui.warn(b"(shared store does not exist; deleting destination)\n")
with timeit("removed_missing_shared_store", "remove-wdir"):
destvfs.rmtree(forcibly=True)
elif not re.search(rb"[a-f0-9]{40}/\.hg$", storepath.replace(b"\\", b"/")):
elif not re.search(b"[a-f0-9]{40}/\\.hg$", storepath.replace(b"\\", b"/")):
ui.warn(
b"(shared store does not belong to pooled storage; "
b"deleting destination to improve efficiency)\n"
Expand All @@ -430,7 +429,7 @@ def handlerepoerror(e):
ui.warn(b"(abandoned transaction found; trying to recover)\n")
repo = hg.repository(ui, dest)
if not repo.recover():
ui.warn(b"(could not recover repo state; " b"deleting shared store)\n")
ui.warn(b"(could not recover repo state; deleting shared store)\n")
with timeit("remove_unrecovered_shared_store", "remove-store"):
deletesharedstore()

Expand All @@ -445,7 +444,7 @@ def handlerepoerror(e):
def handlenetworkfailure():
if networkattempts[0] >= networkattemptlimit:
raise error.Abort(
b"reached maximum number of network attempts; " b"giving up\n"
b"reached maximum number of network attempts; giving up\n"
)

ui.warn(
Expand Down Expand Up @@ -539,7 +538,7 @@ def handlepullerror(e):
clonepeer = hg.peer(ui, {}, cloneurl)
rootnode = peerlookup(clonepeer, b"0")
except error.RepoLookupError:
raise error.Abort(b"unable to resolve root revision from clone " b"source")
raise error.Abort(b"unable to resolve root revision from clone source")
except (
error.Abort,
ssl.SSLError,
Expand Down Expand Up @@ -673,7 +672,6 @@ def handlepullerror(e):
# We only pull if we are using symbolic names or the requested revision
# doesn't exist.
havewantedrev = False
checkoutrevision = None

if revision:
try:
Expand All @@ -685,7 +683,7 @@ def handlepullerror(e):
if not ctx.hex().startswith(revision):
raise error.Abort(
b"--revision argument is ambiguous",
hint=b"must be the first 12+ characters of a " b"SHA-1 fragment",
hint=b"must be the first 12+ characters of a SHA-1 fragment",
)

checkoutrevision = ctx.hex()
Expand Down Expand Up @@ -750,7 +748,6 @@ def handlepullerror(e):
# Mercurial 4.3 doesn't purge files outside the sparse checkout.
# See https://bz.mercurial-scm.org/show_bug.cgi?id=5626. Force
# purging by monkeypatching the sparse matcher.
old_sparse_fn = None
try:
old_sparse_fn = getattr(repo.dirstate, "_sparsematchfn", None)
if old_sparse_fn is not None:
Expand All @@ -764,7 +761,7 @@ def handlepullerror(e):
abort_on_err=True,
# The function expects all arguments to be
# defined.
**{"print": None, "print0": None, "dirs": None, "files": None},
**{"print": None, "print0": None, "dirs": None, "files": None}
):
raise error.Abort(b"error purging")
finally:
Expand Down

0 comments on commit b037849

Please sign in to comment.