Skip to content
Snippets Groups Projects
Commit e2f0d22c authored by Filippo Cremonese's avatar Filippo Cremonese
Browse files

Cache git ls-remote output

parent d0ff9ce0
No related branches found
No related tags found
No related merge requests found
import json
import os.path
import re
from functools import lru_cache
......@@ -53,9 +54,30 @@ class CloneAction(Action):
@lru_cache()
def _ls_remote(self, remote):
return run_script(
cache_filepath = os.path.join(self.config.orchestra_dotdir, "remote_refs_cache.json")
if os.path.exists(cache_filepath):
with open(cache_filepath, "rb") as f:
cached_data = json.loads(f.read())
if self.build.qualified_name in cached_data:
return cached_data[self.build.qualified_name]
data = run_script(
f'git ls-remote -h --refs "{remote}"',
quiet=True,
environment=self.environment,
check_returncode=False
).stdout.decode("utf-8")
if os.path.exists(cache_filepath):
with open(cache_filepath, "rb") as f:
cached_data = json.loads(f.read())
else:
cached_data = {}
cached_data[self.build.qualified_name] = data
# TODO: prevent race condition, if two clone actions run at the same time
with open(cache_filepath, "w") as f:
json.dump(cached_data, f)
return data
......@@ -21,6 +21,11 @@ def handle_update(args, config: Configuration):
else:
clone_binary_archive(name, url, config)
logger.info("Resetting ls-remote cached info")
ls_remote_cache = os.path.join(config.orchestra_dotdir, "remote_refs_cache.json")
if os.path.exists(ls_remote_cache):
os.remove(ls_remote_cache)
logger.info("Updating repositories")
for git_repo in glob(os.path.join(config.sources_dir, "**/.git"), recursive=True):
git_repo = os.path.dirname(git_repo)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment