mirror of
https://github.com/wentasah/ros2nix.git
synced 2025-06-09 15:52:23 +03:00
Use URL and prefix (directory) as git cache keys
Using URL instead of git revisions should ensure that the cache doesn't grow indefinitely. With git revisions, the cache would be soon full of mostly old revisions. The advantage using git revision is that, for example, different branches of a repo can be cached simultaneously. I hope, this is not the common usage pattern. And if it is, one can always set XDG_CACHE_HOME variable to use different caches for different branches.
This commit is contained in:
parent
c619c573f2
commit
a6c2ff98fb
1 changed files with 6 additions and 9 deletions
|
@ -444,21 +444,18 @@ def ros2nix(args):
|
||||||
merge_base = merge_base_to_upstream(head)
|
merge_base = merge_base_to_upstream(head)
|
||||||
head = check_output(f"git rev-list {merge_base} -1 -- .".split())
|
head = check_output(f"git rev-list {merge_base} -1 -- .".split())
|
||||||
|
|
||||||
def cache_key(prefix, rev):
|
def cache_key(url, prefix):
|
||||||
if args.use_per_package_src:
|
if args.use_per_package_src:
|
||||||
return f"{prefix}-{rev}"
|
return f"{url}?dir={prefix}"
|
||||||
return rev
|
return url
|
||||||
|
|
||||||
|
|
||||||
# Latest commit present in the upstream repo. If
|
# Latest commit present in the upstream repo. If
|
||||||
# the local repository doesn't have additional
|
# the local repository doesn't have additional
|
||||||
# commits, it is the same as HEAD. Should work
|
# commits, it is the same as HEAD. Should work
|
||||||
# even with detached HEAD.
|
# even with detached HEAD.
|
||||||
upstream_rev = merge_base_to_upstream(head)
|
upstream_rev = merge_base_to_upstream(head)
|
||||||
if cache_key(prefix, upstream_rev) in git_cache:
|
info = git_cache.get(cache_key(url, prefix))
|
||||||
info = git_cache[cache_key(prefix, upstream_rev)]
|
if info is None or info["rev"] != upstream_rev:
|
||||||
upstream_rev = info["rev"]
|
|
||||||
else:
|
|
||||||
info = json.loads(
|
info = json.loads(
|
||||||
subprocess.check_output(
|
subprocess.check_output(
|
||||||
["nix-prefetch-git", "--quiet"]
|
["nix-prefetch-git", "--quiet"]
|
||||||
|
@ -470,7 +467,7 @@ def ros2nix(args):
|
||||||
+ [toplevel, upstream_rev],
|
+ [toplevel, upstream_rev],
|
||||||
).decode()
|
).decode()
|
||||||
)
|
)
|
||||||
git_cache[cache_key(prefix, upstream_rev)] = {k : info[k] for k in ["rev", "sha256"]}
|
git_cache[cache_key(url, prefix)] = {k : info[k] for k in ["rev", "sha256"]}
|
||||||
|
|
||||||
match = re.match("https://github.com/(?P<owner>[^/]*)/(?P<repo>.*?)(.git|/.*)?$", url)
|
match = re.match("https://github.com/(?P<owner>[^/]*)/(?P<repo>.*?)(.git|/.*)?$", url)
|
||||||
sparse_checkout = f"""sparseCheckout = ["{prefix}"];
|
sparse_checkout = f"""sparseCheckout = ["{prefix}"];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue