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

git: fix caching git commit through multiple refs #5444

Merged
merged 1 commit into from
Oct 28, 2024

Conversation

tonistiigi
Copy link
Member

This fixes a current issue when a Git commit is accessed multiple times through different refs, or a ref is added after the commit has already been pulled once.

When keep-git-dir option is true, then program can try to resolve the current reference via .git directory and because old cache key was only the git commit, previous .git directory can be reused without any refs inside.

There is no change to the behavior if keep-git-dir is false, as then requests through multiple refs yield identical content.

Only the reference in the user-provided identifier is added to the cache key, and that is the only one that can be expected in .git because of the shallow fetches. We do not do extra request to find named refs for a commit SHA if that is provided in the identifier.

This change can break old cache for existing keep-git-dir clones.

@jedevc
Copy link
Member

jedevc commented Oct 23, 2024

I think this goes someway towards fixing #4446 (comment)?

Not fully, since we're still in a detached-head state, but someway, since at least now we've consistently got the right refs in .git.

This fixes current issue when a Git commit is accessed
multiple times through different refs or ref is added
after commit has already been pulled once.

When keep-git-dir option is true, then program can
try to resolve the current reference via .git directory
and because old cache key was only the git commit, previous
.git directory can be reused without any refs inside.

There is no change to the behavior if keep-git-dir is
false as then requests through multiple refs yield to
identical content.

Only the reference in the user provided identifier is added
to the cache key, and that is the only one that can be
expected in .git because of the shallow fetches. We do not
do extra request to find named refs for a commit SHA if that is
provided in the identifier.

Signed-off-by: Tonis Tiigi <[email protected]>
@crazy-max crazy-max added this to the v0.17.0 milestone Oct 25, 2024
@tonistiigi tonistiigi merged commit 94f0ff8 into moby:master Oct 28, 2024
93 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants