From 7a2ed3a02393dfc3942cde192f1703c0d200cc43 Mon Sep 17 00:00:00 2001 From: darshanime Date: Mon, 13 Jul 2026 14:09:25 +0530 Subject: [PATCH] dont push empty bundles --- dist/index.js | 83 +++++++++++++++++++++----------- src/warpbuild/mirror-cache.ts | 91 +++++++++++++++++++++++------------ 2 files changed, 116 insertions(+), 58 deletions(-) diff --git a/dist/index.js b/dist/index.js index 9d945ed..04eb13a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -41983,42 +41983,69 @@ async function uploadBranchDelta(settings) { } const repoPath = settings.repositoryPath; const sha = settings.commit; - const grant = await requestBranchUpload(plan.repoKey, plan.refKey, sha); - if (grant.kind !== 'grant') { - info(`Branch delta upload skipped (${grant.kind})`); - return; - } - if (!(await hasBaseRefs(repoPath))) { - info('No base refs to diff against; branch delta skipped'); - return; - } - const tmp = tempBundlePath('branch'); + await exec_exec('git', ['-C', repoPath, 'update-ref', UPLOAD_TIP_REF, sha]); try { - await exec_exec('git', ['-C', repoPath, 'update-ref', UPLOAD_TIP_REF, sha]); - // Exclude the base with a single --glob, not one `^ref` arg per ref: a large repo - // has hundreds of base refs, and that many args overflows the Windows command-line - // limit (ENAMETOOLONG). The glob matches the multi-level seeded refs and yields the - // same base-relative (order-free) delta. - await exec_exec('git', [ - '-C', - repoPath, - 'bundle', - 'create', - tmp, - UPLOAD_TIP_REF, - '--not', - `--glob=${BASE_REFNS}/*` - ]); - await httpPut(grant.url, tmp); - info(`Uploaded branch delta for '${plan.refKey}'`); + if (!(await hasBaseRefs(repoPath))) { + info('No base refs to diff against; branch delta skipped'); + return; + } + // If the tip is already in the base there is no delta to roll, and `git bundle + // create` errors on an empty range ("Refusing to create empty bundle"). Detect it + // first — and before taking the server lock, so an empty delta never blocks the + // other jobs racing the same branch. + if (await branchDeltaIsEmpty(repoPath)) { + info('Tip already contained in the base; no branch delta to upload'); + return; + } + const grant = await requestBranchUpload(plan.repoKey, plan.refKey, sha); + if (grant.kind !== 'grant') { + info(`Branch delta upload skipped (${grant.kind})`); + return; + } + const tmp = tempBundlePath('branch'); + try { + // Exclude the base with a single --glob, not one `^ref` arg per ref: a large repo + // has hundreds of base refs, and that many args overflows the Windows command-line + // limit (ENAMETOOLONG). The glob matches the multi-level seeded refs and yields the + // same base-relative (order-free) delta. + await exec_exec('git', [ + '-C', + repoPath, + 'bundle', + 'create', + tmp, + UPLOAD_TIP_REF, + '--not', + `--glob=${BASE_REFNS}/*` + ]); + await httpPut(grant.url, tmp); + info(`Uploaded branch delta for '${plan.refKey}'`); + } + finally { + await external_fs_namespaceObject.promises.rm(tmp, { force: true }); + } } finally { - await external_fs_namespaceObject.promises.rm(tmp, { force: true }); await exec_exec('git', ['-C', repoPath, 'update-ref', '-d', UPLOAD_TIP_REF], { ignoreReturnCode: true }); } } +// The tip's delta against the base is empty when the tip is already reachable from the +// base — nothing new to bundle. +async function branchDeltaIsEmpty(repoPath) { + let out = ''; + await exec_exec('git', [ + '-C', + repoPath, + 'rev-list', + '--count', + UPLOAD_TIP_REF, + '--not', + `--glob=${BASE_REFNS}/*` + ], { silent: true, listeners: { stdout: (d) => (out += d.toString()) } }); + return out.trim() === '0'; +} // Whether any base ref was seeded — the guard that keeps the delta base-relative. The // base is excluded by glob (see uploadBranchDelta), so we only need existence here. async function hasBaseRefs(repoPath) { diff --git a/src/warpbuild/mirror-cache.ts b/src/warpbuild/mirror-cache.ts index 35b3938..42d85c0 100644 --- a/src/warpbuild/mirror-cache.ts +++ b/src/warpbuild/mirror-cache.ts @@ -248,38 +248,49 @@ async function uploadBranchDelta(settings: IGitSourceSettings): Promise { const repoPath = settings.repositoryPath const sha = settings.commit - const grant = await api.requestBranchUpload(plan.repoKey, plan.refKey, sha) - if (grant.kind !== 'grant') { - core.info(`Branch delta upload skipped (${grant.kind})`) - return - } - - if (!(await hasBaseRefs(repoPath))) { - core.info('No base refs to diff against; branch delta skipped') - return - } - - const tmp = tempBundlePath('branch') + await exec.exec('git', ['-C', repoPath, 'update-ref', UPLOAD_TIP_REF, sha]) try { - await exec.exec('git', ['-C', repoPath, 'update-ref', UPLOAD_TIP_REF, sha]) - // Exclude the base with a single --glob, not one `^ref` arg per ref: a large repo - // has hundreds of base refs, and that many args overflows the Windows command-line - // limit (ENAMETOOLONG). The glob matches the multi-level seeded refs and yields the - // same base-relative (order-free) delta. - await exec.exec('git', [ - '-C', - repoPath, - 'bundle', - 'create', - tmp, - UPLOAD_TIP_REF, - '--not', - `--glob=${BASE_REFNS}/*` - ]) - await httpPut(grant.url, tmp) - core.info(`Uploaded branch delta for '${plan.refKey}'`) + if (!(await hasBaseRefs(repoPath))) { + core.info('No base refs to diff against; branch delta skipped') + return + } + // If the tip is already in the base there is no delta to roll, and `git bundle + // create` errors on an empty range ("Refusing to create empty bundle"). Detect it + // first — and before taking the server lock, so an empty delta never blocks the + // other jobs racing the same branch. + if (await branchDeltaIsEmpty(repoPath)) { + core.info('Tip already contained in the base; no branch delta to upload') + return + } + + const grant = await api.requestBranchUpload(plan.repoKey, plan.refKey, sha) + if (grant.kind !== 'grant') { + core.info(`Branch delta upload skipped (${grant.kind})`) + return + } + + const tmp = tempBundlePath('branch') + try { + // Exclude the base with a single --glob, not one `^ref` arg per ref: a large repo + // has hundreds of base refs, and that many args overflows the Windows command-line + // limit (ENAMETOOLONG). The glob matches the multi-level seeded refs and yields the + // same base-relative (order-free) delta. + await exec.exec('git', [ + '-C', + repoPath, + 'bundle', + 'create', + tmp, + UPLOAD_TIP_REF, + '--not', + `--glob=${BASE_REFNS}/*` + ]) + await httpPut(grant.url, tmp) + core.info(`Uploaded branch delta for '${plan.refKey}'`) + } finally { + await fs.promises.rm(tmp, {force: true}) + } } finally { - await fs.promises.rm(tmp, {force: true}) await exec.exec( 'git', ['-C', repoPath, 'update-ref', '-d', UPLOAD_TIP_REF], @@ -290,6 +301,26 @@ async function uploadBranchDelta(settings: IGitSourceSettings): Promise { } } +// The tip's delta against the base is empty when the tip is already reachable from the +// base — nothing new to bundle. +async function branchDeltaIsEmpty(repoPath: string): Promise { + let out = '' + await exec.exec( + 'git', + [ + '-C', + repoPath, + 'rev-list', + '--count', + UPLOAD_TIP_REF, + '--not', + `--glob=${BASE_REFNS}/*` + ], + {silent: true, listeners: {stdout: (d: Buffer) => (out += d.toString())}} + ) + return out.trim() === '0' +} + // Whether any base ref was seeded — the guard that keeps the delta base-relative. The // base is excluded by glob (see uploadBranchDelta), so we only need existence here. async function hasBaseRefs(repoPath: string): Promise {