From 2e1a5e246ee3589c2f664a62ebd06be7dc69c229 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Wed, 7 Aug 2019 15:31:38 +0200 Subject: bug: compute op's ID based on the serialized data on disk --- bug/op_noop.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'bug/op_noop.go') diff --git a/bug/op_noop.go b/bug/op_noop.go index 3cd9f39a..a1648434 100644 --- a/bug/op_noop.go +++ b/bug/op_noop.go @@ -4,7 +4,6 @@ import ( "encoding/json" "github.com/MichaelMure/git-bug/identity" - "github.com/MichaelMure/git-bug/util/git" ) var _ Operation = &NoOpOperation{} @@ -20,8 +19,8 @@ func (op *NoOpOperation) base() *OpBase { return &op.OpBase } -func (op *NoOpOperation) Hash() (git.Hash, error) { - return hashOperation(op) +func (op *NoOpOperation) ID() string { + return idOperation(op) } func (op *NoOpOperation) Apply(snapshot *Snapshot) { -- cgit From 67a3752e176790e82a48706236f889cab4f8913d Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sun, 11 Aug 2019 14:08:03 +0200 Subject: bug,entity: use a dedicated type to store IDs --- bug/op_noop.go | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) (limited to 'bug/op_noop.go') diff --git a/bug/op_noop.go b/bug/op_noop.go index a1648434..16d32297 100644 --- a/bug/op_noop.go +++ b/bug/op_noop.go @@ -3,6 +3,7 @@ package bug import ( "encoding/json" + "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/identity" ) @@ -19,7 +20,7 @@ func (op *NoOpOperation) base() *OpBase { return &op.OpBase } -func (op *NoOpOperation) ID() string { +func (op *NoOpOperation) Id() entity.Id { return idOperation(op) } @@ -31,25 +32,9 @@ func (op *NoOpOperation) Validate() error { return opBaseValidate(op, NoOpOp) } -// Workaround to avoid the inner OpBase.MarshalJSON overriding the outer op -// MarshalJSON -func (op *NoOpOperation) MarshalJSON() ([]byte, error) { - base, err := json.Marshal(op.OpBase) - if err != nil { - return nil, err - } - - // revert back to a flat map to be able to add our own fields - var data map[string]interface{} - if err := json.Unmarshal(base, &data); err != nil { - return nil, err - } - - return json.Marshal(data) -} - -// Workaround to avoid the inner OpBase.MarshalJSON overriding the outer op -// MarshalJSON +// UnmarshalJSON is a two step JSON unmarshaling +// This workaround is necessary to avoid the inner OpBase.MarshalJSON +// overriding the outer op's MarshalJSON func (op *NoOpOperation) UnmarshalJSON(data []byte) error { // Unmarshal OpBase and the op separately -- cgit