refactor(redact): remove vestigial shard-scoping from pre-push OPF rewrite · Entire
refactor(redact): remove vestigial shard-scoping from pre-push OPF rewrite
aaddab2→main·
Soph·4w ago·2 files·+34 added/-179 removed
The pre-push rewrite redacts the whole cumulative tree for every unapplied commit (the C1 whole-tree fix), so the shard-scoping path was dead: shardPath was always "", which made shouldDescend/insideShard always return true and left parseShardPathFromCommitMessage uncalled.
Drop the shardPath parameter from collectTreeBlobs and rebuildTreeWithCachedRedaction, delete the unreachable guard branches and the now-unused helpers, and remove the tests that only covered the removed symbols. Behavior is unchanged — both walkers still recurse the whole tree and redact every file except content_hash.txt.
Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com
Sessions
00610aca61afView transcript
Changes
2
cmd/entire/cli/strategy
Mmanual_commit_opf_rewrite.go+26/-106
Mmanual_commit_opf_rewrite_test.go+8/-73
286 unmodified lines
...
179 unmodified lines
// Correctness note: each v1 commit tree is cumulative. During a multi-commit
// rewrite, the newest original commit can still contain older shards that were
// 7-layer-only before this rewrite. The collect/apply walkers redact the whole
// tree (empty shardPath) for every unapplied commit so the final rewritten tip
// cannot reintroduce an older un-OPF-redacted shard.
// tree for every unapplied commit so the final rewritten tip cannot
// reintroduce an older un-OPF-redacted shard.
func rebuildV1Commit(ctx context.Context, repo *git.Repository, oldCommit *object.Commit, parent plumbing.Hash, redactedByPath map[string][]byte) (plumbing.Hash, error) {
newTree := oldCommit.TreeHash
if !trailers.HasOPFApplied(oldCommit.Message) {
// ...
}
}
// ...
func parseShardPathFromCommitMessage(message string) string {
firstLine, _, _ := strings.Cut(message, "\n")
const prefix = "Checkpoint: "
if !strings.HasPrefix(firstLine, prefix) {
return ""
}
id := strings.TrimSpace(firstLine[len(prefix):])
if len(id) != 12 {
return ""
}
for _, c := range id {
if (c < '0' || c > '9') && (c < 'a' || c > 'f') {
return ""
}
}
return id[:2] + "/" + id[2:]
}
// isRedactableBlobName reports whether a file at the given name should
// flow through OPF. The policy is fail-closed: every regular file
// inside the shard is redacted EXCEPT content_hash.txt, which is
// 14 unmodified lines
return name != paths.ContentHashFileName
}
// collectTreeBlobs walks tree and appends every redactable blob's
// content + full tree path to the parallel output slices. The same
// shard-scoping rules as rebuildTreeWithCachedRedaction apply.
// collectTreeBlobs walks the whole tree and appends every redactable
// blob's content + full tree path to the parallel output slices. It
// ...
function collectTreeBlobs(repo *git.Repository, tree *object.Tree, pathPrefix ...
// ...
func shouldDescend(path, shardPath string) bool {
if shardPath == "" || path == "" {
// shardPath="" means "no scoping" (bootstrap fallback);
// path=="" is the root, which is the ancestor of every shard.
return true
}
// ...
}
func insideShard(pathPrefix, shardPath string) bool {
if shardPath == "" {
return true
}
// ...
}
// Tests
func TestParseShardPathFromCommitMessage(t *testing.T) {
t.Parallel()
cases := []struct {
name, msg, want string
}{
{name: "valid", msg: "Checkpoint: a1b2c3d4e5f6\n\nEntire-Session: s\n", want: "a1/b2c3d4e5f6"},
{name: "trailing_space", msg: "Checkpoint: a1b2c3d4e5f6 \n", want: "a1/b2c3d4e5f6"},
// ... other cases ...
}
// ... test string equality checks ...
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
require.Equal(t, tc.want, parseShardPathFromCommitMessage(tc.msg))
})
}
}
// ... other function definitions and tests ...