aboutsummaryrefslogtreecommitdiffstats
path: root/bug/operation_pack.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-07-13 21:21:24 +0200
committerMichael Muré <batolettre@gmail.com>2018-07-13 21:21:24 +0200
commit1779a0f3b92d58654b43444addeaf437a64d77a8 (patch)
tree9f973413454894f0456d7379425070d468712242 /bug/operation_pack.go
parent289f8d53ee960d35c1f0c42e8753ad536737b875 (diff)
downloadgit-bug-1779a0f3b92d58654b43444addeaf437a64d77a8.tar.gz
serialize a Bug to git as a blob+tree+commit+ref
Diffstat (limited to 'bug/operation_pack.go')
-rw-r--r--bug/operation_pack.go39
1 files changed, 38 insertions, 1 deletions
diff --git a/bug/operation_pack.go b/bug/operation_pack.go
index 21376b9c..67a2a072 100644
--- a/bug/operation_pack.go
+++ b/bug/operation_pack.go
@@ -1,5 +1,11 @@
package bug
+import (
+ "encoding/json"
+ "github.com/MichaelMure/git-bug/repository"
+ "github.com/MichaelMure/git-bug/util"
+)
+
// OperationPack represent an ordered set of operation to apply
// to a Bug. These operations are stored in a single Git commit.
//
@@ -7,7 +13,22 @@ package bug
// inside Git to form the complete ordered chain of operation to
// apply to get the final state of the Bug
type OperationPack struct {
- Operations []Operation
+ Operations []Operation `json:"ops"`
+ hash util.Hash
+}
+
+func Parse() (OperationPack, error) {
+ // TODO
+ return OperationPack{}, nil
+}
+
+func (opp *OperationPack) Serialize() ([]byte, error) {
+ jsonBytes, err := json.Marshal(*opp)
+ if err != nil {
+ return nil, err
+ }
+
+ return jsonBytes, nil
}
// Append a new operation to the pack
@@ -22,3 +43,19 @@ func (opp *OperationPack) IsEmpty() bool {
func (opp *OperationPack) IsValid() bool {
return !opp.IsEmpty()
}
+
+func (opp *OperationPack) Write(repo repository.Repo) (util.Hash, error) {
+ data, err := opp.Serialize()
+
+ if err != nil {
+ return "", err
+ }
+
+ hash, err := repo.StoreData(data)
+
+ if err != nil {
+ return "", err
+ }
+
+ return hash, nil
+}