Work on trim_excess_metadata.sh. Bumped to v1.12.0.
Owners: and user opted to keep the rule simple. Groups are kept only via the keep_groups.txt file.errmsg vs msg) is intentional. In the context of this script, a server with zero submitted changes or zero local/remote/stream depots means something is very wrong upstream — those should remain errors. Do not normalize them.Owner: via p4 -ztag -F %Owner% <spec> -o <name>. If the owner is in KeepUsersFile, skip deletion and bump *KeptByOwner.grep -q "^$Name$" to grep -Fxq -- "$Name" "$KeepFile". Affects Phases 2, 3, 4, 5, 7. Avoids regex injection from spec names containing ., [, *, etc.p4 depots | grep ... > TmpFile inherited grep's exit status, so a zero-match grep falsely triggered "Could not get list of depots." Rewritten: capture p4 depots first, filter local|remote|stream types inside the loop. New post-loop check fires errmsg "No local/remote/stream depots detected." if nothing of the right type was found.p4 -ztag -F %userName% info and aborts during preflight if that user is missing from KeepUsersFile. Prevents Phase 5 from deleting the script's own running user mid-run.-man text had two "Phase 9" lines. Streams now correctly listed as Phase 8.-man "FILES" section gained a paragraph explaining the owner-based keep behavior, including the group exception.Per-type counts now printed before the final pass/fail line:
In Dry Run mode the "Deleted" label switches to "Would delete" automatically. Note: cmd() returns 0 in NoOp mode without acting, so dry-run "Failed" counts will be 0 — that's working as intended.
bash -n clean.shellcheck clean../trim_excess_metadata.sh -man > trim_excess_metadata.command_summary.txttrim_excess_metadata.sh opened for edit.trim_excess_metadata.command_summary.txt opened for edit (still to regenerate).trim_excess_metadata.sh.bak not on client — untouched.# Session Log — 2026-05-21 Work on `trim_excess_metadata.sh`. Bumped to **v1.12.0**. ## Ask 1. Review the script. 2. Implement enhancement: don't delete labels/groups/clients/branches owned by a kept user. 3. General review — flag obvious bugs and suggest fixes. 4. Add a count-rich summary at the end. 5. Ignore intentionally incomplete features (Streams, Jobs and Fixes). ## Decisions - **Owner-based keep**: applied to clients, branches, labels only. Groups intentionally **excluded** — they have multi-valued `Owners:` and user opted to keep the rule simple. Groups are kept only via the `keep_groups.txt` file. - **Scope of bug fixes**: do #1, #2, #6 from my review. Skip #3. - #3 (the asymmetric "No X detected" being `errmsg` vs `msg`) is **intentional**. In the context of this script, a server with zero submitted changes or zero local/remote/stream depots means something is very wrong upstream — those should remain errors. Do not normalize them. ## Changes made ### Enhancement (owner-based keep, Phases 2/3/4) - After the existing keep-file check, look up `Owner:` via `p4 -ztag -F %Owner% <spec> -o <name>`. If the owner is in `KeepUsersFile`, skip deletion and bump `*KeptByOwner`. ### Bug fixes - **#1: Unsafe grep anchors.** All keep-file membership checks switched from `grep -q "^$Name$"` to `grep -Fxq -- "$Name" "$KeepFile"`. Affects Phases 2, 3, 4, 5, 7. Avoids regex injection from spec names containing `.`, `[`, `*`, etc. - **#2: Phase 11 depot pipeline bug.** Old form `p4 depots | grep ... > TmpFile` inherited `grep`'s exit status, so a zero-match grep falsely triggered `"Could not get list of depots."` Rewritten: capture `p4 depots` first, filter `local|remote|stream` types inside the loop. New post-loop check fires `errmsg "No local/remote/stream depots detected."` if nothing of the right type was found. - **#6: Self-delete preflight.** New check after access-level verification: fetches the operating P4 user via `p4 -ztag -F %userName% info` and aborts during preflight if that user is missing from `KeepUsersFile`. Prevents Phase 5 from deleting the script's own running user mid-run. ### Cosmetic - `-man` text had two "Phase 9" lines. Streams now correctly listed as **Phase 8**. ### Documentation - `-man` "FILES" section gained a paragraph explaining the owner-based keep behavior, including the group exception. ### Summary rework (replaces the trailing block) Per-type counts now printed before the final pass/fail line: - LDAP specs: Deleted, Failed - Clients: Total examined, Ignored (non-empty view), Kept (keep file), Kept (owned by kept user), Deleted, Failed - Branches: same shape as Clients - Labels: same shape as Clients - Users: Total, Kept, Deleted, Failed - Shelved changelists: Deleted, Failed - Groups: Total, Kept, Deleted, Failed - Submitted changelists: Delete attempts (only empties succeed) - Depots: Total examined, Empty, Non-empty (ignored), Deleted, Failed In Dry Run mode the "Deleted" label switches to "Would delete" automatically. Note: `cmd()` returns 0 in NoOp mode without acting, so dry-run "Failed" counts will be 0 — that's working as intended. ## Validation - `bash -n` clean. - `shellcheck` clean. ## Open items before submit - Regenerate the doc file: `./trim_excess_metadata.sh -man > trim_excess_metadata.command_summary.txt` - User to test (Dry Run first, then Live). ## P4 status going into testing - `trim_excess_metadata.sh` opened for edit. - `trim_excess_metadata.command_summary.txt` opened for edit (still to regenerate). - `trim_excess_metadata.sh.bak` not on client — untouched.
| # | Change | User | Description | Committed | |
|---|---|---|---|---|---|
| #1 | 32736 | C. Thomas Tyler | Added AGENDS.md and session log from earlier session. |