Skip to content

Commit

Permalink
reckless: prefer to search a local copy of a remote source
Browse files Browse the repository at this point in the history
If it has already been cloned, this is less problematic than
using the github rest API.
  • Loading branch information
endothermicdev committed Feb 19, 2024
1 parent 8b65a90 commit 7149f59
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions tools/reckless
Original file line number Diff line number Diff line change
Expand Up @@ -855,11 +855,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
Expand Down

0 comments on commit 7149f59

Please sign in to comment.