| 1 | package checkpoint |
| 2 | |
| 3 | import "time" |
| 4 | |
| 5 | func newRewindTransaction(root string, plan RewindPlan) *TransactionManifest { |
| 6 | scope := plan.Scope |
| 7 | hasBoundary := plan.HasBoundary |
| 8 | boundaryIndex := plan.BoundaryIndex |
| 9 | if plan.ConversationAction == "fork" { |
| 10 | // The fork is durable before this transaction starts and the parent is |
| 11 | // unchanged. Keep file undo/compensation entirely conversation-free. |
| 12 | if scope == RewindBoth { |
| 13 | scope = RewindCode |
| 14 | } |
| 15 | hasBoundary = false |
| 16 | boundaryIndex = 0 |
| 17 | } |
| 18 | return &TransactionManifest{ |
| 19 | SchemaVersion: SchemaV2, |
| 20 | ID: newID("tx"), |
| 21 | WorkspaceRoot: root, |
| 22 | State: TxPrepared, |
| 23 | Kind: "rewind", |
| 24 | Turn: plan.Turn, |
| 25 | Scope: scope, |
| 26 | CreatedAt: time.Now(), |
| 27 | UpdatedAt: time.Now(), |
| 28 | SessionRevision: plan.SessionRevision, |
| 29 | WorkspaceToken: plan.WorkspaceToken, |
| 30 | Coverage: plan.Coverage, |
| 31 | CoverageGaps: append([]CoverageGap(nil), plan.CoverageGaps...), |
| 32 | BoundaryIndex: boundaryIndex, |
| 33 | HasBoundary: hasBoundary, |
| 34 | ConversationAction: plan.ConversationAction, |
| 35 | TruncateFrom: plan.Turn, |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | func setTransactionConversationForward(tx *TransactionManifest, forward []byte) { |
| 40 | if shouldTruncateConversation(tx) { |
| 41 | tx.ConversationForward = forward |
| 42 | } |
| 43 | } |
| 44 |