mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-28 11:32:22 +00:00
checkUpdates() ran `git rev-list HEAD..origin/<branch> --count` unconditionally in the parallel probe batch, even on the shallow + no-merge-base path where resolveBehindCount() ignores the result and falls back to a SHA compare. In the #51922 failure mode that count walks the entire remote ancestry (thousands of commits), so the work was pure latency on every update check for the exact case the fix targets. Split the probes into two phases: resolve --is-shallow-repository and merge-base first, then run rev-list --count only when shouldCountCommits says the number is meaningful (full clone, or shallow-with-merge-base). The shallow/no-merge-base SHA fallback is preserved unchanged.
28 lines
1.4 KiB
JavaScript
28 lines
1.4 KiB
JavaScript
'use strict'
|
|
|
|
// Whether `git rev-list HEAD..origin/<branch> --count` produces a meaningful
|
|
// number worth computing. On a SHALLOW checkout (installer clones with
|
|
// --depth 1) the local history often shares no merge-base with the freshly
|
|
// fetched origin tip, so the count enumerates the entire remote ancestry and
|
|
// returns a bogus huge number (e.g. 12104) — see #51922. resolveBehindCount
|
|
// discards that bogus count in favour of a SHA compare, so the caller should
|
|
// SKIP the expensive rev-list entirely in that case rather than run it and
|
|
// throw the result away.
|
|
function shouldCountCommits({ isShallow, hasMergeBase }) {
|
|
return !(isShallow && !hasMergeBase)
|
|
}
|
|
|
|
// Resolve how many commits the local checkout is behind origin for the desktop
|
|
// update indicator. When the count isn't meaningful (shallow + no merge-base)
|
|
// fall back to a binary up-to-date check by SHA, exactly like the official-SSH
|
|
// path in checkUpdates() and the CLI guard in hermes_cli/banner.py. Full clones
|
|
// (developers / Docker dev images) keep the exact count path unchanged.
|
|
function resolveBehindCount({ countStr, currentSha, targetSha, isShallow, hasMergeBase }) {
|
|
if (!shouldCountCommits({ isShallow, hasMergeBase })) {
|
|
if (currentSha && targetSha && currentSha === targetSha) return 0
|
|
return 1 // behind by an unknown amount — show a generic "update available"
|
|
}
|
|
return Number.parseInt(countStr, 10) || 0
|
|
}
|
|
|
|
module.exports = { resolveBehindCount, shouldCountCommits }
|