Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a gate to cache LFS fetch operations #209

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
33 changes: 23 additions & 10 deletions project_utils/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ def _add_and_fetch_remote(self, repo, url, remote_name, verbose=False):
if verbose:
print(CACHE_FETCH_REMOTE.format(remote_name, url))
repo.remotes[remote_name].fetch(progress=GitProgressHandler())
repo.git.execute(['git', 'lfs', 'fetch', '--all'])
if self._lfs_enabled(repo):
repo.git.execute(['git', 'lfs', 'fetch', '--all'])

def open(self, verbose=False):
"""
Expand Down Expand Up @@ -232,17 +233,19 @@ def update_cache(self, url_or_name=None, sha_or_branch=None, verbose=False):
if sha_or_branch is not None and ((remote.name == dir_name) or (remote.url == url_or_name)):
print('Fetching ref {}'.format(sha_or_branch))
remote.fetch(refspec=sha_or_branch, progress=GitProgressHandler())
try:
repo.git.execute(['git', 'lfs', 'fetch', '{}'.format(remote.name), '{}'.format(sha_or_branch), '--recent'])
except GitCommandError:
print('No recent LFS object found in {}:{}'.format(remote.name, sha_or_branch))
pass
if self._lfs_enabled(repo):
try:
repo.git.execute(['git', 'lfs', 'fetch', '{}'.format(remote.name), '{}'.format(sha_or_branch), '--recent'])
except GitCommandError:
print('No recent LFS object found in {}:{}'.format(remote.name, sha_or_branch))
pass
else:
remote.fetch(progress=GitProgressHandler())
try:
repo.git.execute(['git', 'lfs', 'fetch', '--recent'])
except GitCommandError:
print('No recent LFS object found in {}'.format(remote.name))
if self._lfs_enabled(repo):
try:
repo.git.execute(['git', 'lfs', 'fetch', '--recent'])
except GitCommandError:
print('No recent LFS object found in {}'.format(remote.name))

def is_sha_cached(self, url_or_name, sha, verbose=False):
repo = self._get_repo(self._create_name(url_or_name))
Expand All @@ -257,3 +260,13 @@ def is_sha_cached(self, url_or_name, sha, verbose=False):

def clean_cache(self, verbose=False):
raise NotImplementedError

def _lfs_enabled(self, repo):
try:
lfs_out = repo.git.execute(['git', 'lfs', 'ls-files', '-n'])
if lfs_out:
return True
else:
return False
except GitCommandError as e:
raise EdkrepoGitException(e)