Repository navigation
feat(list): expose worktree last activity in schema 2 JSON - #4699
Conversation
worktrunk-bot
left a comment
There was a problem hiding this comment.
The field works, and the -z migration of the status consumers looks right. Two costs remain, and both land on every wt list render, not just schema 2 JSON consumers. That trade belongs to a maintainer, so I'm not approving yet. On #4515, switching the shared status call to =all was raised as the open maintainer decision, and nobody has made it on the thread.
--untracked-files=allon the shared status query.status_porcelain_cachedbacks the table, the statusline (re-rendered on every agent prompt), and the picker's diff state, as well as the JSON output. A new untracked directory that isn't ignored used to be oned/record and is now one record per file. Each of those records is held in the per-worktree cache and cloned on every cache hit.- The mtime stat loop runs whenever the worktree is dirty.
newest_changed_file_mtimeis called fromcompute_working_tree_diff, so the table, statusline, and picker all pay onesymlink_metadataper changed or untracked file and then discard the result. Onlyjson_worktreereads it. With=all, a worktree holding 20k untracked generated files costs 20k stats per render. Computing it only when JSON output is requested would keep the other paths at their old cost. Whether the=allswitch should also apply only to JSON is the same decision as above.
f9ba4ce to
0ed8417
Compare
worktrunk-bot
left a comment
There was a problem hiding this comment.
This commit is based on current main (79f19f6) but undoes four changes already merged there. That looks like stale copies of whole files from an older checkout. As a result the crate doesn't compile, and lint, fast-checks, feature-check, code-coverage and the macOS/Windows tests are all red. The CI error:
error[E0599]: no method named `create_removal_backup` found for struct `WorkingTree<'a>`
--> src/git/remove.rs:517:22
What the diff undoes, apart from the modified_at work:
- #4545, the
wt remove --forcebackup. It deletesWorkingTree::create_removal_backup,record_backupandSafetyBackup::print_recovery_hintsfromsrc/git/repository/working_tree.rs. It also deletes their unborn-branch test, and puts back the oldercreate_safety_backupthat can't handle an unborn branch.src/git/remove.rsandsrc/commands/step/squash.rsstill call the deleted methods. Don't fix the build by removing those calls: that would make--forcediscard uncommitted changes without a backup. - #4694, the IPv6 loopback probe. In
src/commands/list/collect/tasks.rsit removesprobe_addr, the::1probe incompute_url_status, and bothurl_status_detects_*tests. - #4703 and #4545 help text. In
src/cli/mod.rsit drops theAlt-xpicker sentence and therefs/wt-backup/<branch>sentence fromwt removehelp. - The
wt switchfork-branch paragraph. It restores the older "requires renaming first" wording in place of the current text about falling back to a prefixed branch, which #4542 added.
The help_list_long snapshot change probably carries the same reverted lines. Re-applying only the modified_at changes onto current main should clear all of this.
The earlier concerns about --untracked-files=all and the mtime loop are settled. Both now run only when json_schema == Some(2), and the table and picker keep the normal cache entry.
Because the diff currently removes the --force backup path, I've asked @max-sixty to review.
0ed8417 to
9cdd035
Compare
|
Thanks for the review — both points are addressed in the latest push (rebased onto current main, single commit):
Verified locally: |
worktrunk-bot
left a comment
There was a problem hiding this comment.
In schema 2, wt list statusline --format=json emits the same JsonItemV2, but it never sets needs_mtime. As a result, a dirty worktree reports modified_at equal to head.committed_at, which is wrong. run_json in src/commands/statusline.rs builds its options with statusline_options, which is CollectOptions::for_columns(...), and that defaults needs_mtime: false. With the flag off, compute_working_tree_diff returns newest_file_mtime: None, drain_results_with_timings stores it as Some(None), and modified_at() treats that as "resolved, no file mtimes", so it falls back to the commit time. A consumer reading the statusline JSON would conclude the worktree hasn't been touched since its last commit even when it has uncommitted edits. There are two possible fixes:
- Set
needs_mtimeinrun_jsonwhenjson_schema == 2. That costs one worktree's stats, not the whole repo's. - Keep the outer
Nonewhen mtimes weren't collected, so the field readsnullrather than a confident wrong value.
Either way, a statusline JSON case in test_list_json_modified_at, or next to the existing statusline JSON tests, would pin it.
The latest push no longer reverts the --force backup, the IPv6 probe or the help-text changes, and nothing in the diff now widens a deletion. The PR description still says the shared status query moves to --untracked-files=all. Now only the schema 2 JSON path uses all, and every other caller stays on normal (with -z added).
9cdd035 to
33505c8
Compare
|
Fixed the statusline path: Also updated the PR description: the Rebased onto current main ( Local verification: statusline + list integration modules 202 passed; lib/bins 1570 + 1017 passed (the one failure is the known root-environment picker write test); |
worktrunk-bot
left a comment
There was a problem hiding this comment.
test (windows) fails on test_list_json_modified_at: Windows rejects a newline in a filename, so File::create returns InvalidFilename (os error 123) before wt list runs (job log). The rest of the suite passes on Windows, and Linux and macOS are green. Keeping the newline everywhere except Windows still covers the -z path parsing on the platforms where such names can exist.
CI failed — test_list_json_modified_at can't create a newline filename on Windows.
33505c8 to
8180172
Compare
|
Fixed the Windows failure in |
) `parse_untracked_files` had its own loop over `git status --porcelain -z` records, including the rule that skips a rename's or copy's source field. `porcelain_entries_z`, added in #4699, already implements that walk. `parse_untracked_files` now keeps that iterator's `??` records and drops its own copy. Behavior is unchanged, and the existing `parse_untracked_files` unit tests, including the rename-source case, pass unmodified. Its only caller is the auto-staging warning in `warn_about_untracked_files`. `parse_porcelain_z` still walks the records itself, because it returns rename source paths too and the shared iterator drops them. Co-authored-by: worktrunk-bot <[email protected]>
Closes #4515.
Problem
Dashboards and cleanup tooling that want a per-worktree last-activity timestamp currently have to re-run
git statusper worktree, because schema 2 list JSON has no such field.Change
Adds
worktree.modified_atto schema 2 list JSON: the later ofhead.committed_atand the newest mtime among the changed or untracked filesgit statusreports for that worktree. The statusline's schema 2 JSON envelope carries the same field for its single item and collects the mtimes as well — before this, it never setneeds_mtime, so a dirty worktree silently reported the HEAD commit time.No-value semantics follow the existing
Tripattern:nullwhen the status is unresolved.To collect the file mtimes reliably, the shared cached status query behind
wt listgains-z, and the paths that collect mtimes run it with--untracked-files=allinstead ofnormal, still one subprocess per worktree. Only the schema 2 JSON paths collect mtimes —wt list --format=jsonand the statusline's schema 2 JSON — so the table, the text statusline, and the picker keep thenormalquery and never pay the per-file stat loop. The old text output quoted unusual filenames and collapsed untracked directories, so paths could not be trusted for stat calls; the NUL-delimited form also expands untracked directories into individual files.parse_working_tree_status, the conflict checks, and the picker diff state all read the same byte-oriented records now. Missing or deleted files are skipped rather than failing the row, and renames use the destination path.Docs: the worktree field table in the list command help (source for the generated command page and skill mirrors) gains the
modified_atrow, anddocs/public/schema/list-v2.jsonis regenerated.Verification
Validated with Rust 1.99 (the pinned 1.98 toolchain install is broken in this environment; no toolchain files were changed):
cargo fmt --check— passcargo clippy --all-targets -- -D warnings— passcargo test --lib --bins commands::list— 300 passedcargo test --lib --bins— 2597 passed (run with root'scap_dac_overridedropped; one permission-based picker test fails under unrestricted root because a read-only directory stays writable there, unrelated to this change)cargo test --test integration integration_tests::list::— 103 passed, including a new test proving a clean worktree reports the commit time and a dirty worktree with a nested untracked file (with a newline in its name) reports that file's mtimecargo test --test integration integration_tests::readme_sync::test_docs_are_in_sync— passmodified_atlinesNot run: the full
hook pre-mergegate —pre-commitandcargo-nextestare unavailable in this environment, so its all-feature, doctest, and documentation checks remain unrun.Follow-up (statusline
modified_atfix):test_statusline_json_modified_atfails before the fix (a dirty worktree's statusline JSON reports the HEAD commit time) and passes aftercargo test --test integrationfor the statusline and list modules — 202 passedcargo test --lib --bins— 1570 + 1017 passed, with only the pre-existing root-environment picker failure noted abovecargo fmt --checkandcargo clippy --all-targets -- -D warnings— pass