Skip to content

Commit 0dfcba0

Browse files
peyton-altclaude
andcommitted
style: simplify ComputePatchID output parsing and fix minor issues
- Replace unreachable Fields/len guard with strings.Cut in ComputePatchID - Use logCtx variable in linkageForSession for logging consistency - Use strings.TrimSpace in revParse test helper instead of raw byte slice Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Entire-Checkpoint: 91b06c4aabdb
1 parent ec9d0b3 commit 0dfcba0

3 files changed

Lines changed: 7 additions & 7 deletions

File tree

cmd/entire/cli/gitops/diff.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,9 @@ func ComputePatchID(ctx context.Context, repoDir, parentHash, commitHash string)
173173
if output == "" {
174174
return "", nil
175175
}
176-
fields := strings.Fields(output)
177-
if len(fields) < 1 {
178-
return "", fmt.Errorf("unexpected git patch-id output: %q", output)
179-
}
180-
return fields[0], nil
176+
// git patch-id outputs "<patch-id> <commit-id>"; we want the first field.
177+
patchID, _, _ := strings.Cut(output, " ")
178+
return patchID, nil
181179
}
182180

183181
// ComputeFilesChangedHash computes a SHA256 hash of the given files' blob hashes

cmd/entire/cli/gitops/diff_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os/exec"
77
"path/filepath"
88
"sort"
9+
"strings"
910
"testing"
1011
)
1112

@@ -94,7 +95,7 @@ func revParse(t *testing.T, dir, ref string) string {
9495
if err != nil {
9596
t.Fatalf("git rev-parse %s failed: %v", ref, err)
9697
}
97-
return string(out[:len(out)-1])
98+
return strings.TrimSpace(string(out))
9899
}
99100

100101
func gitCheckoutBranch(t *testing.T, dir, branchName string) {

cmd/entire/cli/strategy/manual_commit_hooks.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,11 +696,12 @@ func (h *postCommitActionHandler) linkageForSession(ctx context.Context, session
696696
}
697697

698698
// Copy base linkage so each session gets its own SessionFilesHash
699+
logCtx := logging.WithComponent(ctx, "checkpoint")
699700
linkage := *h.baseLinkage
700701
if len(sessionFilesTouched) > 0 {
701702
sfh, err := gitops.ComputeFilesChangedHash(ctx, h.repoDir, h.newHead, sessionFilesTouched)
702703
if err != nil {
703-
logging.Warn(logging.WithComponent(ctx, "checkpoint"), "failed to compute session files hash for linkage",
704+
logging.Warn(logCtx, "failed to compute session files hash for linkage",
704705
slog.String("commit", h.newHead),
705706
slog.String("error", err.Error()),
706707
)

0 commit comments

Comments
 (0)