Skip to content

Commit

Permalink
chore(launch): improved git fetch time by specifying a refspec and …
Browse files Browse the repository at this point in the history
…`depth=1` (#4459)
  • Loading branch information
gtarpenning committed Nov 8, 2022
1 parent 63941ea commit eddc2ac
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion wandb/sdk/launch/utils.py
Expand Up @@ -414,6 +414,20 @@ def apply_patch(patch_string: str, dst_dir: str) -> None:
raise wandb.Error("Failed to apply diff.patch associated with run.")


def _make_refspec_from_version(version: Optional[str]) -> List[str]:
"""
Helper to create a refspec that checks for the existence of origin/main
and the version, if provided.
"""
if version:
return [f"+{version}"]

return [
"+refs/heads/main*:refs/remotes/origin/main*",
"+refs/heads/master*:refs/remotes/origin/master*",
]


def _fetch_git_repo(dst_dir: str, uri: str, version: Optional[str]) -> str:
"""Clones the git repo at ``uri`` into ``dst_dir``.
Expand All @@ -428,7 +442,8 @@ def _fetch_git_repo(dst_dir: str, uri: str, version: Optional[str]) -> str:
_logger.info("Fetching git repo")
repo = git.Repo.init(dst_dir)
origin = repo.create_remote("origin", uri)
origin.fetch()
refspec = _make_refspec_from_version(version)
origin.fetch(refspec=refspec, depth=1)

if version is not None:
try:
Expand Down

0 comments on commit eddc2ac

Please sign in to comment.