aboutsummaryrefslogtreecommitdiffstats
path: root/bug/op_set_metadata.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2019-08-07 15:31:38 +0200
committerMichael Muré <batolettre@gmail.com>2019-08-08 19:02:46 +0200
commit2e1a5e246ee3589c2f664a62ebd06be7dc69c229 (patch)
tree03e69d6991fb4b9f9a159ba2d7b74b5f36d5069d /bug/op_set_metadata.go
parent2c3034a0abe13eb6b07d8dd13041e7be4adc6f93 (diff)
downloadgit-bug-2e1a5e246ee3589c2f664a62ebd06be7dc69c229.tar.gz
bug: compute op's ID based on the serialized data on disk
Diffstat (limited to 'bug/op_set_metadata.go')
-rw-r--r--bug/op_set_metadata.go24
1 files changed, 8 insertions, 16 deletions
diff --git a/bug/op_set_metadata.go b/bug/op_set_metadata.go
index 7616a591..19ddc3e3 100644
--- a/bug/op_set_metadata.go
+++ b/bug/op_set_metadata.go
@@ -5,14 +5,13 @@ import (
"fmt"
"github.com/MichaelMure/git-bug/identity"
- "github.com/MichaelMure/git-bug/util/git"
)
var _ Operation = &SetMetadataOperation{}
type SetMetadataOperation struct {
OpBase
- Target git.Hash
+ Target string
NewMetadata map[string]string
}
@@ -20,20 +19,13 @@ func (op *SetMetadataOperation) base() *OpBase {
return &op.OpBase
}
-func (op *SetMetadataOperation) Hash() (git.Hash, error) {
- return hashOperation(op)
+func (op *SetMetadataOperation) ID() string {
+ return idOperation(op)
}
func (op *SetMetadataOperation) Apply(snapshot *Snapshot) {
for _, target := range snapshot.Operations {
- hash, err := target.Hash()
- if err != nil {
- // Should never error unless a programming error happened
- // (covered in OpBase.Validate())
- panic(err)
- }
-
- if hash == op.Target {
+ if target.ID() == op.Target {
base := target.base()
if base.extraMetadata == nil {
@@ -56,7 +48,7 @@ func (op *SetMetadataOperation) Validate() error {
return err
}
- if !op.Target.IsValid() {
+ if !IDIsValid(op.Target) {
return fmt.Errorf("target hash is invalid")
}
@@ -95,7 +87,7 @@ func (op *SetMetadataOperation) UnmarshalJSON(data []byte) error {
}
aux := struct {
- Target git.Hash `json:"target"`
+ Target string `json:"target"`
NewMetadata map[string]string `json:"new_metadata"`
}{}
@@ -114,7 +106,7 @@ func (op *SetMetadataOperation) UnmarshalJSON(data []byte) error {
// Sign post method for gqlgen
func (op *SetMetadataOperation) IsAuthored() {}
-func NewSetMetadataOp(author identity.Interface, unixTime int64, target git.Hash, newMetadata map[string]string) *SetMetadataOperation {
+func NewSetMetadataOp(author identity.Interface, unixTime int64, target string, newMetadata map[string]string) *SetMetadataOperation {
return &SetMetadataOperation{
OpBase: newOpBase(SetMetadataOp, author, unixTime),
Target: target,
@@ -123,7 +115,7 @@ func NewSetMetadataOp(author identity.Interface, unixTime int64, target git.Hash
}
// Convenience function to apply the operation
-func SetMetadata(b Interface, author identity.Interface, unixTime int64, target git.Hash, newMetadata map[string]string) (*SetMetadataOperation, error) {
+func SetMetadata(b Interface, author identity.Interface, unixTime int64, target string, newMetadata map[string]string) (*SetMetadataOperation, error) {
SetMetadataOp := NewSetMetadataOp(author, unixTime, target, newMetadata)
if err := SetMetadataOp.Validate(); err != nil {
return nil, err