From 1779a0f3b92d58654b43444addeaf437a64d77a8 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Fri, 13 Jul 2018 21:21:24 +0200 Subject: serialize a Bug to git as a blob+tree+commit+ref --- bug/operation_pack.go | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'bug/operation_pack.go') 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 +} -- cgit