mirror of
https://code.forgejo.org/actions/checkout.git
synced 2026-03-11 15:13:17 +00:00
feat: override fetch-depth to 0 when reference-cache is active
When reference-cache is enabled, shallow fetches (fetch-depth > 0) are counterproductive because objects are served from the local cache. Shallow negotiation only adds network latency without saving bandwidth. If fetch-depth was not explicitly set by the user, it is automatically overridden to 0. If explicitly set, a warning is emitted explaining the performance impact. Signed-off-by: Michael Wyraz <mw@brick4u.de>
This commit is contained in:
parent
9ddd3f4b35
commit
ed69f3bbdd
6 changed files with 153 additions and 2 deletions
|
|
@ -335,6 +335,10 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
|
|||
await git.lfsInstall()
|
||||
}
|
||||
|
||||
// When using reference cache, fetch-depth > 0 is counterproductive:
|
||||
// objects are served from the local cache, so shallow negotiation only adds latency.
|
||||
adjustFetchDepthForCache(settings)
|
||||
|
||||
// Fetch
|
||||
core.startGroup('Fetching the repository')
|
||||
const fetchOptions: {
|
||||
|
|
@ -568,3 +572,30 @@ async function getGitCommandManager(
|
|||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjusts fetchDepth when reference-cache is active.
|
||||
* Shallow fetches are counterproductive with a local cache because
|
||||
* objects are served from disk, making shallow negotiation pure overhead.
|
||||
*/
|
||||
export function adjustFetchDepthForCache(
|
||||
settings: Pick<
|
||||
IGitSourceSettings,
|
||||
'referenceCache' | 'fetchDepth' | 'fetchDepthExplicit'
|
||||
>
|
||||
): void {
|
||||
if (settings.referenceCache && settings.fetchDepth > 0) {
|
||||
if (settings.fetchDepthExplicit) {
|
||||
core.warning(
|
||||
`'fetch-depth: ${settings.fetchDepth}' is set with reference-cache enabled. ` +
|
||||
`This may slow down checkout because shallow negotiation bypasses the local cache. ` +
|
||||
`Consider using 'fetch-depth: 0' for best performance with reference-cache.`
|
||||
)
|
||||
} else {
|
||||
core.info(
|
||||
`Overriding fetch-depth from ${settings.fetchDepth} to 0 because reference-cache is enabled`
|
||||
)
|
||||
settings.fetchDepth = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue