fix(#2854): slice the store-path hash from the front, not the pname suffix from the back
current_flake_rev canonicalizes to /nix/store/<hash>-<pname>; the hash right after /nix/store/ is what varies between builds, the trailing -<pname> is constant. slice(-12) was taking the tail, so two different builds would very likely render the same truncated string. slice the hash prefix out instead, with a plain head-slice fallback for a non-store-path rev (e.g. a bare local dir in dev). damocles caught this in review on PR #2869.
This commit is contained in:
parent
761f4b8351
commit
abffa5234d
1 changed files with 10 additions and 3 deletions
|
|
@ -52,11 +52,18 @@ async function init() {
|
||||||
// Rev line: absent when the flake ref isn't a local path pin (a bare
|
// Rev line: absent when the flake ref isn't a local path pin (a bare
|
||||||
// `github:` url has no on-disk rev to canonicalize) — hidden rather
|
// `github:` url has no on-disk rev to canonicalize) — hidden rather
|
||||||
// than showing a placeholder in that case.
|
// than showing a placeholder in that case.
|
||||||
|
//
|
||||||
|
// `current_flake_rev` canonicalizes to a nix store path
|
||||||
|
// (/nix/store/<hash>-<pname>) — the part that actually varies between
|
||||||
|
// builds is the hash right after `/nix/store/`, not the trailing
|
||||||
|
// `-<pname>` (constant across revs). Slice the hash out of the front
|
||||||
|
// rather than truncating from the tail, so two different builds don't
|
||||||
|
// render as the same string. Falls back to a plain head-slice for a
|
||||||
|
// non-store path (e.g. a bare local dir during dev).
|
||||||
const rev = $('hive-rev');
|
const rev = $('hive-rev');
|
||||||
if (rev && state.hyperhive_rev) {
|
if (rev && state.hyperhive_rev) {
|
||||||
const short = state.hyperhive_rev.length > 16
|
const storeMatch = state.hyperhive_rev.match(/^\/nix\/store\/([^-]+)/);
|
||||||
? `…${state.hyperhive_rev.slice(-12)}`
|
const short = storeMatch ? storeMatch[1].slice(0, 12) : state.hyperhive_rev.slice(0, 12);
|
||||||
: state.hyperhive_rev;
|
|
||||||
rev.textContent = `rev ${short}`;
|
rev.textContent = `rev ${short}`;
|
||||||
rev.title = state.hyperhive_rev;
|
rev.title = state.hyperhive_rev;
|
||||||
rev.hidden = false;
|
rev.hidden = false;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue