Repository navigation
feat(list): abbreviate the table's SHA with git, not a fixed slice - #3676
Merged
Merged
Conversation
The Commit cell sliced `&head[..8]` while `--format=json`'s `short_sha` carried `%h`, so one commit read `1b9f1d96` in the table and `1b9f1d9` in JSON, and `core.abbrev` reached only the JSON. #3675 gave a detached row's Branch cell the same slice, so the disagreement now showed up twice on one row. `ListItem::short_sha` becomes the only abbreviation of `head`: the Commit cell, a detached row's Branch cell, the statusline, and JSON all render it. `abbreviated_head` is gone. Both columns size to the measured widths rather than a hardcoded 8, so `core.abbrev = 12` no longer truncates mid-hash and the default 7 stops reserving a column nothing fills — the character it frees goes to Message. `collect()` folds `%h` onto the rows before layout instead of after the skeleton. It costs no fork: the batch carrying it already gates the skeleton for `%ct` sort order. Both cells are identity columns with no placeholder, so they paint in the first frame exactly as before. Where the batch fails, the Commit cell is now empty rather than a slice of a SHA git refused — the same way Age and Message already report that failure, under the same warning. `render_text_cell` stops styling empty text, so the blank cell no longer emits an escape pair around nothing.
worktrunk-bot
approved these changes
Jul 31, 2026
max-sixty
added a commit
that referenced
this pull request
Aug 1, 2026
Follow-up to #3676, which made `wt list`'s table render git's `%h` instead of `&head[..8]`. The `--prs` `log` tab was the last user-visible fixed-8 abbreviation. ## The defect `wt switch --prs` renders a row's `log` tab from the local `git log` when the PR head is in the object store, and from `gh pr view <n> --json commits` / `glab api …/commits` when it isn't. The forge path sliced each SHA to 8 characters, so on a repo where git abbreviates to 9 the same commit read `abc1234` at 8 before a fetch and 9 after, and `core.abbrev` never reached the pane at all. ## The fix `Repository::abbrev_len` asks git how wide it abbreviates in this repo and caches the answer on `RepoCache`, so a picker with 30 PR rows probes once — clones share the `Arc<RepoCache>`, and `once_cell::sync::OnceCell` collapses the concurrent background rows onto one fork. The pane wants the width rather than `short_sha` because of the branch it sits on: it runs precisely when the head *isn't* local, and `git rev-parse --short` takes a single revision — there is no batched form for a list of absent commits, and looping it would be one subprocess per commit per row. With no objects to disambiguate against, the width is git's whole answer for these SHAs. Both forge arms now parse the full SHA and share one abbreviation step in `render_commit_lines`. GitLab's ready-made `short_id` goes unused: it's the server's abbreviation, blind to the reader's `core.abbrev`, and taking it printed an MR's commits at a different width from a PR's. ## The audit #8 claimed the `--prs` tab was the last one; that came from a grep. Sweeping `.take(N)`, `[..N]`, `{:.N}`, `truncate(N)`, `get(..N)`, and `--abbrev`/`--short=` across `src/` turned up one more user-visible case: **`wt config state`'s CI cache table**, which sliced `cached.head` to 8 and now truncates to `abbrev_len`. One fixed-width slice over a SHA survives deliberately: `collect/tasks.rs` labels a `tracing::debug!` line with `&sha[..8]` as a fallback when a timed-out task has no branch name. It's a trace field rather than rendered output, and the timeout error path is the wrong place to spawn git. Everything else the sweep found hashes something other than a git object — `config::short_hash`'s base36 branch suffix, `summary.rs`'s content digest — or is a column width rather than a truncation. ## Cost Both call sites are flat in the number of SHAs: one `git rev-parse --short HEAD` per repo per process. The first cut of the CI table called `short_sha` per row instead, to keep git's extension of an ambiguous prefix. That's a fork apiece, and it cost more than the whole command was worth — measured on a repo with a cache entry per branch, `wt config state get` at 50 entries: `wt config state get`, 50 cache entries, release build, hyperfine (warmup 20, 80+ runs, quiet machine): | | mean ± σ | vs. baseline | |---|---:|---:| | before this PR (`.take(8)`) | 22.1 ± 0.8 ms | — | | `abbrev_len` (this PR) | 26.1 ± 1.3 ms | +4.0 ms, **1.18× ± 0.07** | | `short_sha` per row | 266.7 ± 3.9 ms | **12×** | The +18% is one `git rev-parse --short HEAD` against a command whose entire runtime is ~22 ms. For scale, a trace of the same command shows `gh --version` at 15.3 ms and `git config --list -z` running three times for ~12 ms, both of which predate this PR. The probe sits inside the non-empty branch, so a repo with no CI cache pays nothing. No Criterion target covers `wt config state` (`time_to_first_output` covers `remove`/`switch`/`list`; `picker_preview` covers worktree rows, not `--prs`, which needs a forge CLI), hence the standalone measurement. Worth noting against the daily suite's own resolution: run-to-run spread on an unchanged bench (`worktree_scaling/warm/8`, last 10 nightlies) is 18%, so a benchmark would not have caught the +18% either — though it would have caught the 12×. So the form here pays one probe and gives up disambiguation. Absent objects have nothing to collide with, and a live collision at 7–9 characters is rare enough for a display column to wear. On the picker, `abbrev_len` lands on a background pool thread behind a `gh`/`glab` call that costs orders of magnitude more, and never on a first-paint path. #3676 itself cost nothing at runtime, for the record: `%h` was already in the pre-skeleton `git log --no-walk` batch (`%ct` from the same fork drives row order), and the format string is byte-identical across that commit. It moved where the already-fetched string is copied onto the row and swapped a `COMMIT_HASH_WIDTH = 8` constant for an O(N) width pass over the rendered SHAs. No fork added, no phase reordered — the pre-skeleton budget table in `collect/mod.rs` reads 23 commands on both sides. ## Tests - `abbrev_len_follows_core_abbrev_and_covers_absent_objects` — the width matches `%h`, `core.abbrev = 12` reaches it, and it equals what git gives for a SHA with no object behind it. - `render_commits_abbreviates_to_the_given_width` — the pane prints the width it's handed, at 7 and at 12. - `parse_gitlab_commits_keeps_order_and_takes_the_full_id` — `id` over `short_id`. - `test_state_get_ci_head_uses_git_abbreviation` — the CI table's Head cell equals `git rev-parse --short`. It can't be a snapshot: the width scales with the repo's object count and a test repo's SHA isn't fixed. `cargo run -- hook pre-merge --yes`: 4494 passed. > _This was written by Claude Code on behalf of max-sixty_
1 task
social4hyq
pushed a commit
to social4hyq/homebrew-core
that referenced
this pull request
Sep 20, 2026
worktrunk 0.72.0 Created-by: HarmonybrewBot Commit-by: HarmonybrewBot Merged-by: HarmonybrewBot Description: Created by `brew bump` --- Created with `brew bump-formula-pr`.<details> <summary>release notes</summary> <pre>## Release Notes ### Improved - **A host carrying a forge's name anywhere resolves to that forge again**: 0.71.0 required `github`, `gitlab`, or `gitea` as a whole dot-separated label, which read as an ownership check but wasn't one — an attacker controls their own DNS — while shutting out self-hosters with hyphenated names. `github-enterprise.acme.com`, `myhub.lumenfield.work`, and the `github-personal` SSH alias classify again, so CI status, `wt switch --prs`, and `repo.provider` work with no config. ([#3673](max-sixty/worktrunk#3673)) - **One `[projects."…"]` entry can cover every repository on a host, and can set the forge**: A key containing `*` matches any run of characters, `/` included, so `[projects."git.company.example/*"]` covers a whole host; every matching entry applies, least- to most-specific. The table also gained `forge.platform` and `forge.hostname`, so a self-hosted host needs one entry here rather than a block in every repo. [Docs](https://worktrunk.dev/config/#user-project-specific-settings) ([#3701](max-sixty/worktrunk#3701), thanks @chrishas35 for the request and @witt-bit for the workspace-scoped case it partly serves) - **`wt merge` and `wt step push` leave the target worktree's uncommitted changes in place**: The autostash that held a dirty target's changes restored them as unstaged; both now advance the target with a compare-and-swap `update-ref` and `read-tree -m -u`, which leaves uncommitted work untouched. (Breaking: the fast-forward path no longer runs `git push`, so `pre-push` and the receive-side hooks no longer fire, and a failed sync errors with the ref rolled back.) ([#3703](max-sixty/worktrunk#3703), [#3684](max-sixty/worktrunk#3684), [#3693](max-sixty/worktrunk#3693), thanks @gubasso for reporting) - **Approval state and branch-removal outcomes are machine-readable**: `wt config approvals list --format=json` reports whether a non-interactive run would stop for approval. `wt remove` and `wt step prune` replace `branch_deleted` with `branch_outcome`: `deleted`, `deferred`, `not_attempted`, `retained_unmerged`, `retained_checked_out`, `retained_raced`, `retained_failed`. (Breaking.) ([#3710](max-sixty/worktrunk#3710), thanks @NathanaelRea for the requests) - **Every commit hash worktrunk prints follows `core.abbrev`**: The `wt list` table, `wt switch --prs`'s `log` tab, and `wt config state`'s CI cache table sliced to 8 characters while `--format=json` carried git's `%h`. All now ask git how wide it abbreviates in this repo. ([#3676](max-sixty/worktrunk#3676), [#3677](max-sixty/worktrunk#3677)) - **`wt list --format=json` schema 2 has a published JSON Schema**: [worktrunk.dev/schema/list-v2.json](https://worktrunk.dev/schema/list-v2.json) holds the contract, and `wt list --print-schema` prints the same document. Four fields that were bare strings are now enumerated vocabularies; the emitted JSON is unchanged. ([#3747](max-sixty/worktrunk#3747)) - **A detached worktree is named by its commit, not `-`**: The Branch cell hardcoded `-`, which reads as missing data rather than a state; it now carries the row's abbreviated HEAD, and the picker and statusline name the worktree the same way. ([#3675](max-sixty/worktrunk#3675)) ### Fixed - **Piped output is plain and no longer panics**: `wt list | head -3` exited 101 with `failed printing to stdout: Broken pipe`, and `wt list` wrote ANSI to a pipe unconditionally. Every stdout surface now exits cleanly, and the human-read ones are plain when piped unless `CLICOLOR_FORCE=1`. ([#3746](max-sixty/worktrunk#3746), [#3766](max-sixty/worktrunk#3766)) - **A CI check that hasn't finished no longer reads as passed**: Each forge's status parser missed documented values, so a GitHub PR parked on an approval gate showed green, and GitLab's `canceling` and Azure DevOps's `postponed` read as no CI at all. ([#3741](max-sixty/worktrunk#3741), [#3740](max-sixty/worktrunk#3740)) - **The shell wrappers survive an `rm` alias and a failing `--execute`**: Aliases bake into the wrapper at parse time, so `alias rm='rm -v'` reached its cleanup — noise on zsh and bash, and on nushell an abort that leaked three temp files, as a failing `--execute` body also did. ([#3714](max-sixty/worktrunk#3714), thanks @Ar4l), ([#3732](max-sixty/worktrunk#3732), [#3734](max-sixty/worktrunk#3734)) - **An alias or hook wrapping `wt switch` or `wt remove` keeps your subdirectory**: The user's position came from the `wt` process's cwd, which inside an alias body is the worktree root, so an aliased `wt remove` from `feature/apps/gateway` landed at the primary worktree's root. Fixes [#3723](max-sixty/worktrunk#3723). ([#3724](max-sixty/worktrunk#3724), thanks @vivienm for reporting) - **`wt merge` and `wt step push` refuse a target worktree parked mid-operation**: The two-tree sync refuses an unmerged index but not a stopped cherry-pick or rebase whose conflict was already staged, so the push range could land in a paused target and be committed by `--continue`. ([#3759](max-sixty/worktrunk#3759)) - **The Claude plugin's worktree-remove hook resolves against the worktree path**: The hook anchored at `CLAUDE_PROJECT_DIR`, which the `claude agents` view routinely leaves outside any repository, so `wt remove` died with `not a git repository` and the session became undeletable. Its guard now also requires a `.git` entry. ([#3754](max-sixty/worktrunk#3754), [#3767](max-sixty/worktrunk#3767), thanks @judewang for the fix and the report) - **A Gitea API error is reported as one, not as a parse failure**: `tea api` exits 0 whatever the HTTP status, so both call sites guessed from the body's shape and blamed an API change for an API error. `--include` surfaces the status instead. ([#3713](max-sixty/worktrunk#3713), [#3600](max-sixty/worktrunk#3600)) - **`--print-schema` and the doc-generation help flags name the right command**: All three found the subcommand by scanning `argv` for a `/wt` suffix, which never matches `wt.exe` under a backslash path, so on Windows they read the binary's own path as the command. ([#3762](max-sixty/worktrunk#3762)) - **A multibyte shell name no longer panics**: `extract_filename_from_path` sliced at `len() - 4` to test for `.exe` with no char-boundary check: `SHELL=/bin/日本語 wt config show` panicked, and on macOS every process name goes through it during shell detection. ([#3727](max-sixty/worktrunk#3727)) - **`wt` installed under a dotted name generates shell integration for that name**: `binary_name` used `file_stem`, which cuts at the last dot, so `wt config shell init bash` under `wt.old` emitted a wrapper for `wt`. It now strips only the executable suffix. ([#3719](max-sixty/worktrunk#3719)) - **Concurrent `wt step prune` removals no longer race the worktree registry**: `git worktree remove` reads every sibling under `.git/worktrees/`, so two overlapping removals could have one read a sibling mid-teardown. Registry-mutating removals now serialize behind a second lock. ([#3692](max-sixty/worktrunk#3692)) - **The `wt switch` first-run offer previews the legacy files it removes**: Accepting "Install shell integration?" could delete a deprecated worktrunk-managed wrapper the prompt never named. What gets removed is unchanged. ([#3656](max-sixty/worktrunk#3656)) - **`wt config create --project` writes a resolvable link**: The comment it writes into `.config/wt.toml` carried a raw Zola target, because the link-conversion regex stopped at the first `]` — here the one closing a nested code span. ([#3731](max-sixty/worktrunk#3731)) - **`wt list --branches` counts a local branch containing `/` as local**: The summary tally classified branch-only rows by `branch.contains('/')`, so a local `feature/login` counted under "N remote branches". ([#3687](max-sixty/worktrunk#3687)) - **`wt step relocate`'s human summary counts template-error branches as skipped**: `--format=json` already folded them into `skipped`; the human tally undercounted by the number of branches whose `worktree-path` template failed to expand. ([#3688](max-sixty/worktrunk#3688)) ### Documentation - **SignPath attribution appears with the artifacts it describes**: The code-signing notice and a route to the policy now sit in the install section's Windows block on the README and the docs landing page, as SignPath Foundation's OSS program requires. ([#3709](max-sixty/worktrunk#3709)) - **`wt step copy-ignored`'s `--require-include` example renders as a terminal block**: It was the only `console` block in the command's long help missing the `$ ` prefix. ([#3706](max-sixty/worktrunk#3706)) ### Internal - **Library API rework** (Breaking library API): `cargo-semver-checks` fails five lints — `LegacyForgeAlias` and `Repository::legacy_forge_alias` removed with the forge-classification revert, `Repository::forge_platform_override` removed for one shared resolver, `stage_worktree_removal` gained two parameters, `UserProjectOverrides` gained a `forge` field, and the `real-repo-benches` feature was removed. ([#3673](max-sixty/worktrunk#3673), [#3694](htt See merge request: Harmonybrew/homebrew-core!16275
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Commit cell sliced
&head[..8]while--format=json'sshort_shacarried git's%h, so one commit read1b9f1d96in the table and1b9f1d9in JSON, andcore.abbrevreached only the JSON. #3675 gave a detached row's Branch cell the same slice, so the disagreement showed up twice on one row.ListItem::short_shabecomes the only abbreviation ofheadanywhere: the Commit cell, a detached row's Branch cell, the statusline, and JSON all render it.abbreviated_head()is gone.Column widths
COMMIT_HASH_WIDTH = 8is gone. The Commit column and the Branch column's detached budget both measure the SHAs they will render, socore.abbrev = 12no longer truncates mid-hash and the default 7 stops reserving a column nothing fills — the freed character goes to Message.Latency
collect()folds%honto the rows before layout instead of after the skeleton. The batch carrying it already gates the skeleton for%ctsort order, so this is a map lookup rather than new I/O, and both cells are identity columns with no placeholder — they still paint in the first frame.Measured on a 40-worktree / 400-branch fixture: git subprocess counts are identical (5 pre-skeleton, 108 for the full run). Pre-skeleton wall time is unchanged; running both binaries in each order, the sign of the difference follows run order rather than the binary (+1.5 ms with this branch second, −0.5 ms with it first), so the residual sits inside drift.
Behavior change
Where the commit-details batch fails, the Commit cell is now empty rather than a slice of a SHA git refused. Age and Message already report that failure the same way, under the same warning, and two snapshots show it.
render_text_cellalso stops styling empty text, so a blank cell no longer emits an escape pair around nothing.Reading the diff
160 files, but the hand-written part is +91/−79 in
src/commands/list/plus a +71 test. The rest is generated. The docs mirrors and help snapshots are symmetric. Of the snapshot lines, content is +799/−799 — every changed line a 1-for-1 hash swap — while +1396 is instaenv:metadata refreshing on the 128 snapshots this happens to touch.test_list_abbreviated_sha_follows_gitpins the invariant: the table's hash equals JSON'sshort_shaat git's default and atcore.abbrev = 12, and a longer prefix is ruled out. It fails against the old fixed slice.