Skip to content

git source: add AttrGitChecksum #5975

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

Merged
merged 4 commits into from
May 19, 2025
Merged

Conversation

AkihiroSuda
Copy link
Member

@AkihiroSuda AkihiroSuda commented May 15, 2025

refCommitFullHash = gs.src.Ref
}
if refCommitFullHash != "" {
cacheKey := gs.shaToCacheKey(refCommitFullHash, "")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the checksum is set together with the ref then the ref should be passed here as well to shaToCacheKey. If checking out different branches with the same checksum they can be different after checkout with keep-git-dir.

There is still bit of a difference between the cache key generated with checksum compared to the one generated without it because in here we only have access to ref passed by user while in other code-path we use usedRef (if we have full ref like refs/heads, refs/tags then they should be the same though). Iiuc we could use the keep-git-dir option.

If keep-git and text ref then resolve text ref as done without the checksum. If checksums don't match can error right away. Cache key would be gs.shaToCacheKey(sha, usedRef).

If no keep-git-dir then we could just use the sha(either from ref or from checksum) as a cache key without remote resolve. shaToCacheKey already ignores ref if no keep-git-dir.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shaToCacheKey

done

usedRef

This might be beyond the scope of this PR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be beyond the scope of this PR?

Changing it later would break cache though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added testcase for this 427305b

Atm cache keys would be different with 2799cae6ffb0390691ecf8f6ca9c6371c4a6dfe3.git#refs/tags/v0.0.2 for first build and 2799cae6ffb0390691ecf8f6ca9c6371c4a6dfe3.git#v0.0.2?checksum=2799cae6ffb0390691ecf8f6ca9c6371c4a6dfe3 for the second one.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, cherry-picked your commit

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropped ?checksum=... from shaToCacheKey, as originally suggested in #5903 (comment)

The test should pass now.

@AkihiroSuda AkihiroSuda marked this pull request as draft May 16, 2025 06:37
@AkihiroSuda AkihiroSuda marked this pull request as ready for review May 16, 2025 14:56
@AkihiroSuda AkihiroSuda marked this pull request as draft May 17, 2025 09:53
AkihiroSuda and others added 4 commits May 18, 2025 21:38
@AkihiroSuda AkihiroSuda marked this pull request as ready for review May 18, 2025 12:44
}

var refCommitFullHash, ref2 string
if gitutil.IsCommitSHA(gs.src.Checksum) && !gs.src.KeepGitDir {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be follow-up: I think if gs.src.Ref is a full ref like refs/tags/..., refs/heads/... pull/NR/head etc. then we can do early return in here even if gs.src.KeepGitDir is true.

@crazy-max crazy-max merged commit bc508e4 into moby:master May 19, 2025
112 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