From 538b4c850e915519143f388e833ac8faf4c9932b Mon Sep 17 00:00:00 2001 From: Alex Myers Date: Mon, 19 Feb 2024 10:23:46 -0600 Subject: [PATCH] reckless: prefer to search a local copy of a remote source If it has already been cloned, this is less problematic than using the github rest API. --- tools/reckless | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/tools/reckless b/tools/reckless index 8f404575b..885cc947c 100755 --- a/tools/reckless +++ b/tools/reckless @@ -850,11 +850,28 @@ def help_alias(targets: list): sys.exit(1) -def _source_search(name: str, source: str) -> Union[InstInfo, None]: +def _source_search(name: str, src: str) -> Union[InstInfo, None]: """Identify source type, retrieve contents, and populate InstInfo if the relevant contents are found.""" - root_dir = SourceDir(source) + root_dir = SourceDir(src) source = InstInfo(name, root_dir.location, None) + + # If a local clone of a github source already exists, prefer searching + # that instead of accessing the github API. + if source.srctype == Source.GITHUB_REPO: + # Do we have a local copy already? Use that. + user, repo = Source.get_github_user_repo(src) + assert user + assert repo + local_clone_location = RECKLESS_DIR / '.remote_sources' / user / repo + if local_clone_location.exists(): + # Make sure it's the correct remote source and fetch any updates. + if _git_update(source, local_clone_location): + logging.debug(f"Using local clone of {src}: " + f"{local_clone_location}") + source.source_loc = local_clone_location + source.srctype = Source.GIT_LOCAL_CLONE + if source.get_inst_details(): return source return None