diff --git a/bug/bug.go b/bug/bug.go index b252b1764d2011c6f7b4cdf389f44de2ea756a33..f29c04b4ae8cfa8b1bae9d850e6f642a849438dc 100644 --- a/bug/bug.go +++ b/bug/bug.go @@ -641,7 +641,7 @@ func (bug *Bug) Compile() Snapshot { for it.Next() { op := it.Value() - snap = op.Apply(snap) + op.Apply(&snap) snap.Operations = append(snap.Operations, op) } diff --git a/bug/op_add_comment.go b/bug/op_add_comment.go index 300609fba7ad8df1e49dd33a703c21020f4030bb..e5622073df55ef5774e479339dcef3abb5c7f087 100644 --- a/bug/op_add_comment.go +++ b/bug/op_add_comment.go @@ -26,7 +26,7 @@ func (op AddCommentOperation) Hash() (git.Hash, error) { return hashOperation(op) } -func (op AddCommentOperation) Apply(snapshot Snapshot) Snapshot { +func (op AddCommentOperation) Apply(snapshot *Snapshot) { comment := Comment{ Message: op.Message, Author: op.Author, @@ -35,8 +35,6 @@ func (op AddCommentOperation) Apply(snapshot Snapshot) Snapshot { } snapshot.Comments = append(snapshot.Comments, comment) - - return snapshot } func (op AddCommentOperation) GetFiles() []git.Hash { diff --git a/bug/op_create.go b/bug/op_create.go index c65b3bd8a235f3b630108c29474e401f1d4cb655..70ca724281b24ec284aa43d94dbb91441eeb27a3 100644 --- a/bug/op_create.go +++ b/bug/op_create.go @@ -27,7 +27,7 @@ func (op CreateOperation) Hash() (git.Hash, error) { return hashOperation(op) } -func (op CreateOperation) Apply(snapshot Snapshot) Snapshot { +func (op CreateOperation) Apply(snapshot *Snapshot) { snapshot.Title = op.Title snapshot.Comments = []Comment{ { @@ -38,7 +38,6 @@ func (op CreateOperation) Apply(snapshot Snapshot) Snapshot { } snapshot.Author = op.Author snapshot.CreatedAt = op.Time() - return snapshot } func (op CreateOperation) GetFiles() []git.Hash { diff --git a/bug/op_create_test.go b/bug/op_create_test.go index 338067aa1cfabd89406af3e87fb635a8fd9c92d5..2c5ae35b8d8f9dd5088d2a166d9186b95a6f5ea2 100644 --- a/bug/op_create_test.go +++ b/bug/op_create_test.go @@ -18,7 +18,7 @@ func TestCreate(t *testing.T) { create := NewCreateOp(rene, unix, "title", "message", nil) - snapshot = create.Apply(snapshot) + create.Apply(&snapshot) expected := Snapshot{ Title: "title", diff --git a/bug/op_label_change.go b/bug/op_label_change.go index c245d1a544658a99a64431b3c99d5fc15fb4d73c..8909cf56d757efeed0a7bc124e76d10eaf1c2e65 100644 --- a/bug/op_label_change.go +++ b/bug/op_label_change.go @@ -26,7 +26,7 @@ func (op LabelChangeOperation) Hash() (git.Hash, error) { } // Apply apply the operation -func (op LabelChangeOperation) Apply(snapshot Snapshot) Snapshot { +func (op LabelChangeOperation) Apply(snapshot *Snapshot) { // Add in the set AddLoop: for _, added := range op.Added { @@ -54,8 +54,6 @@ AddLoop: sort.Slice(snapshot.Labels, func(i, j int) bool { return string(snapshot.Labels[i]) < string(snapshot.Labels[j]) }) - - return snapshot } func (op LabelChangeOperation) Validate() error { diff --git a/bug/op_set_status.go b/bug/op_set_status.go index 19af46c26d84cfaa1fa8e5ca334351a8f08e6fb2..1fb9cab63ecd8118f4964cde8715337f59fc7f50 100644 --- a/bug/op_set_status.go +++ b/bug/op_set_status.go @@ -22,10 +22,8 @@ func (op SetStatusOperation) Hash() (git.Hash, error) { return hashOperation(op) } -func (op SetStatusOperation) Apply(snapshot Snapshot) Snapshot { +func (op SetStatusOperation) Apply(snapshot *Snapshot) { snapshot.Status = op.Status - - return snapshot } func (op SetStatusOperation) Validate() error { diff --git a/bug/op_set_title.go b/bug/op_set_title.go index a4912143062c61d39b5e53dcc72cef3eb838c0bb..6049ebd04aa1c015fa9ee833bf31a19a1c9df536 100644 --- a/bug/op_set_title.go +++ b/bug/op_set_title.go @@ -26,10 +26,8 @@ func (op SetTitleOperation) Hash() (git.Hash, error) { return hashOperation(op) } -func (op SetTitleOperation) Apply(snapshot Snapshot) Snapshot { +func (op SetTitleOperation) Apply(snapshot *Snapshot) { snapshot.Title = op.Title - - return snapshot } func (op SetTitleOperation) Validate() error { diff --git a/bug/operation.go b/bug/operation.go index 4c6f2e5a3d2c822b686d21598db0c7e2fbc40556..d7d5af51db75277b1fbd0f1496760e3ca88664e5 100644 --- a/bug/operation.go +++ b/bug/operation.go @@ -35,7 +35,7 @@ type Operation interface { // GetFiles return the files needed by this operation GetFiles() []git.Hash // Apply the operation to a Snapshot to create the final state - Apply(snapshot Snapshot) Snapshot + Apply(snapshot *Snapshot) // Validate check if the operation is valid (ex: a title is a single line) Validate() error // SetMetadata store arbitrary metadata about the operation diff --git a/bug/with_snapshot.go b/bug/with_snapshot.go index 48274ed512162e01cdad0ddf66ee46a59d8aa803..2b2439df85861a33c76598031797efc86c05628a 100644 --- a/bug/with_snapshot.go +++ b/bug/with_snapshot.go @@ -27,10 +27,8 @@ func (b *WithSnapshot) Append(op Operation) { return } - snap := op.Apply(*b.snap) - snap.Operations = append(snap.Operations, op) - - b.snap = &snap + op.Apply(b.snap) + b.snap.Operations = append(b.snap.Operations, op) } // Commit intercept Bug.Commit() to update the snapshot efficiently