From 3cf31fc4049fefc82db0a3d2018b5d98ab77c5d7 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Wed, 1 Jul 2020 19:39:02 +0200 Subject: repository: merge git.Hash in for one less /util package --- bug/bug.go | 7 +++---- bug/comment.go | 7 ++++--- bug/op_add_comment.go | 14 +++++++------- bug/op_create.go | 20 ++++++++++---------- bug/op_edit_comment.go | 22 +++++++++++----------- bug/operation.go | 6 +++--- bug/operation_pack.go | 8 ++++---- bug/operation_pack_test.go | 7 ++++--- bug/operation_test.go | 5 ++--- bug/timeline.go | 4 ++-- 10 files changed, 50 insertions(+), 50 deletions(-) (limited to 'bug') diff --git a/bug/bug.go b/bug/bug.go index 40537b0d..24f0dcd5 100644 --- a/bug/bug.go +++ b/bug/bug.go @@ -11,7 +11,6 @@ import ( "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/identity" "github.com/MichaelMure/git-bug/repository" - "github.com/MichaelMure/git-bug/util/git" "github.com/MichaelMure/git-bug/util/lamport" ) @@ -57,8 +56,8 @@ type Bug struct { // Id used as unique identifier id entity.Id - lastCommit git.Hash - rootPack git.Hash + lastCommit repository.Hash + rootPack repository.Hash // all the committed operations packs []OperationPack @@ -509,7 +508,7 @@ func (bug *Bug) NeedCommit() bool { func makeMediaTree(pack OperationPack) []repository.TreeEntry { var tree []repository.TreeEntry counter := 0 - added := make(map[git.Hash]interface{}) + added := make(map[repository.Hash]interface{}) for _, ops := range pack.Operations { for _, file := range ops.GetFiles() { diff --git a/bug/comment.go b/bug/comment.go index 47c1ff05..4c9d118e 100644 --- a/bug/comment.go +++ b/bug/comment.go @@ -1,11 +1,12 @@ package bug import ( + "github.com/dustin/go-humanize" + "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/identity" - "github.com/MichaelMure/git-bug/util/git" + "github.com/MichaelMure/git-bug/repository" "github.com/MichaelMure/git-bug/util/timestamp" - "github.com/dustin/go-humanize" ) // Comment represent a comment in a Bug @@ -13,7 +14,7 @@ type Comment struct { id entity.Id Author identity.Interface Message string - Files []git.Hash + Files []repository.Hash // Creation time of the comment. // Should be used only for human display, never for ordering as we can't rely on it in a distributed system. diff --git a/bug/op_add_comment.go b/bug/op_add_comment.go index 78c8847a..04965b8c 100644 --- a/bug/op_add_comment.go +++ b/bug/op_add_comment.go @@ -6,7 +6,7 @@ import ( "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/identity" - "github.com/MichaelMure/git-bug/util/git" + "github.com/MichaelMure/git-bug/repository" "github.com/MichaelMure/git-bug/util/text" "github.com/MichaelMure/git-bug/util/timestamp" ) @@ -18,7 +18,7 @@ type AddCommentOperation struct { OpBase Message string `json:"message"` // TODO: change for a map[string]util.hash to store the filename ? - Files []git.Hash `json:"files"` + Files []repository.Hash `json:"files"` } // Sign-post method for gqlgen @@ -53,7 +53,7 @@ func (op *AddCommentOperation) Apply(snapshot *Snapshot) { snapshot.Timeline = append(snapshot.Timeline, item) } -func (op *AddCommentOperation) GetFiles() []git.Hash { +func (op *AddCommentOperation) GetFiles() []repository.Hash { return op.Files } @@ -82,8 +82,8 @@ func (op *AddCommentOperation) UnmarshalJSON(data []byte) error { } aux := struct { - Message string `json:"message"` - Files []git.Hash `json:"files"` + Message string `json:"message"` + Files []repository.Hash `json:"files"` }{} err = json.Unmarshal(data, &aux) @@ -101,7 +101,7 @@ func (op *AddCommentOperation) UnmarshalJSON(data []byte) error { // Sign post method for gqlgen func (op *AddCommentOperation) IsAuthored() {} -func NewAddCommentOp(author identity.Interface, unixTime int64, message string, files []git.Hash) *AddCommentOperation { +func NewAddCommentOp(author identity.Interface, unixTime int64, message string, files []repository.Hash) *AddCommentOperation { return &AddCommentOperation{ OpBase: newOpBase(AddCommentOp, author, unixTime), Message: message, @@ -122,7 +122,7 @@ func AddComment(b Interface, author identity.Interface, unixTime int64, message return AddCommentWithFiles(b, author, unixTime, message, nil) } -func AddCommentWithFiles(b Interface, author identity.Interface, unixTime int64, message string, files []git.Hash) (*AddCommentOperation, error) { +func AddCommentWithFiles(b Interface, author identity.Interface, unixTime int64, message string, files []repository.Hash) (*AddCommentOperation, error) { addCommentOp := NewAddCommentOp(author, unixTime, message, files) if err := addCommentOp.Validate(); err != nil { return nil, err diff --git a/bug/op_create.go b/bug/op_create.go index d63d6d2f..9bb40d35 100644 --- a/bug/op_create.go +++ b/bug/op_create.go @@ -7,7 +7,7 @@ import ( "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/identity" - "github.com/MichaelMure/git-bug/util/git" + "github.com/MichaelMure/git-bug/repository" "github.com/MichaelMure/git-bug/util/text" "github.com/MichaelMure/git-bug/util/timestamp" ) @@ -17,9 +17,9 @@ var _ Operation = &CreateOperation{} // CreateOperation define the initial creation of a bug type CreateOperation struct { OpBase - Title string `json:"title"` - Message string `json:"message"` - Files []git.Hash `json:"files"` + Title string `json:"title"` + Message string `json:"message"` + Files []repository.Hash `json:"files"` } // Sign-post method for gqlgen @@ -57,7 +57,7 @@ func (op *CreateOperation) Apply(snapshot *Snapshot) { } } -func (op *CreateOperation) GetFiles() []git.Hash { +func (op *CreateOperation) GetFiles() []repository.Hash { return op.Files } @@ -98,9 +98,9 @@ func (op *CreateOperation) UnmarshalJSON(data []byte) error { } aux := struct { - Title string `json:"title"` - Message string `json:"message"` - Files []git.Hash `json:"files"` + Title string `json:"title"` + Message string `json:"message"` + Files []repository.Hash `json:"files"` }{} err = json.Unmarshal(data, &aux) @@ -119,7 +119,7 @@ func (op *CreateOperation) UnmarshalJSON(data []byte) error { // Sign post method for gqlgen func (op *CreateOperation) IsAuthored() {} -func NewCreateOp(author identity.Interface, unixTime int64, title, message string, files []git.Hash) *CreateOperation { +func NewCreateOp(author identity.Interface, unixTime int64, title, message string, files []repository.Hash) *CreateOperation { return &CreateOperation{ OpBase: newOpBase(CreateOp, author, unixTime), Title: title, @@ -141,7 +141,7 @@ func Create(author identity.Interface, unixTime int64, title, message string) (* return CreateWithFiles(author, unixTime, title, message, nil) } -func CreateWithFiles(author identity.Interface, unixTime int64, title, message string, files []git.Hash) (*Bug, *CreateOperation, error) { +func CreateWithFiles(author identity.Interface, unixTime int64, title, message string, files []repository.Hash) (*Bug, *CreateOperation, error) { newBug := NewBug() createOp := NewCreateOp(author, unixTime, title, message, files) diff --git a/bug/op_edit_comment.go b/bug/op_edit_comment.go index f82e7590..5bfc36bf 100644 --- a/bug/op_edit_comment.go +++ b/bug/op_edit_comment.go @@ -8,9 +8,9 @@ import ( "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/identity" + "github.com/MichaelMure/git-bug/repository" "github.com/MichaelMure/git-bug/util/timestamp" - "github.com/MichaelMure/git-bug/util/git" "github.com/MichaelMure/git-bug/util/text" ) @@ -19,9 +19,9 @@ var _ Operation = &EditCommentOperation{} // EditCommentOperation will change a comment in the bug type EditCommentOperation struct { OpBase - Target entity.Id `json:"target"` - Message string `json:"message"` - Files []git.Hash `json:"files"` + Target entity.Id `json:"target"` + Message string `json:"message"` + Files []repository.Hash `json:"files"` } // Sign-post method for gqlgen @@ -80,7 +80,7 @@ func (op *EditCommentOperation) Apply(snapshot *Snapshot) { } } -func (op *EditCommentOperation) GetFiles() []git.Hash { +func (op *EditCommentOperation) GetFiles() []repository.Hash { return op.Files } @@ -113,9 +113,9 @@ func (op *EditCommentOperation) UnmarshalJSON(data []byte) error { } aux := struct { - Target entity.Id `json:"target"` - Message string `json:"message"` - Files []git.Hash `json:"files"` + Target entity.Id `json:"target"` + Message string `json:"message"` + Files []repository.Hash `json:"files"` }{} err = json.Unmarshal(data, &aux) @@ -134,7 +134,7 @@ func (op *EditCommentOperation) UnmarshalJSON(data []byte) error { // Sign post method for gqlgen func (op *EditCommentOperation) IsAuthored() {} -func NewEditCommentOp(author identity.Interface, unixTime int64, target entity.Id, message string, files []git.Hash) *EditCommentOperation { +func NewEditCommentOp(author identity.Interface, unixTime int64, target entity.Id, message string, files []repository.Hash) *EditCommentOperation { return &EditCommentOperation{ OpBase: newOpBase(EditCommentOp, author, unixTime), Target: target, @@ -148,7 +148,7 @@ func EditComment(b Interface, author identity.Interface, unixTime int64, target return EditCommentWithFiles(b, author, unixTime, target, message, nil) } -func EditCommentWithFiles(b Interface, author identity.Interface, unixTime int64, target entity.Id, message string, files []git.Hash) (*EditCommentOperation, error) { +func EditCommentWithFiles(b Interface, author identity.Interface, unixTime int64, target entity.Id, message string, files []repository.Hash) (*EditCommentOperation, error) { editCommentOp := NewEditCommentOp(author, unixTime, target, message, files) if err := editCommentOp.Validate(); err != nil { return nil, err @@ -164,7 +164,7 @@ func EditCreateComment(b Interface, author identity.Interface, unixTime int64, m } // Convenience function to edit the body of a bug (the first comment) -func EditCreateCommentWithFiles(b Interface, author identity.Interface, unixTime int64, message string, files []git.Hash) (*EditCommentOperation, error) { +func EditCreateCommentWithFiles(b Interface, author identity.Interface, unixTime int64, message string, files []repository.Hash) (*EditCommentOperation, error) { createOp := b.FirstOp().(*CreateOperation) return EditCommentWithFiles(b, author, unixTime, createOp.Id(), message, files) } diff --git a/bug/operation.go b/bug/operation.go index 91df4ef2..107c954e 100644 --- a/bug/operation.go +++ b/bug/operation.go @@ -10,7 +10,7 @@ import ( "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/identity" - "github.com/MichaelMure/git-bug/util/git" + "github.com/MichaelMure/git-bug/repository" ) // OperationType is an operation type identifier @@ -37,7 +37,7 @@ type Operation interface { // Time return the time when the operation was added Time() time.Time // GetFiles return the files needed by this operation - GetFiles() []git.Hash + GetFiles() []repository.Hash // Apply the operation to a Snapshot to create the final state Apply(snapshot *Snapshot) // Validate check if the operation is valid (ex: a title is a single line) @@ -142,7 +142,7 @@ func (op *OpBase) Time() time.Time { } // GetFiles return the files needed by this operation -func (op *OpBase) GetFiles() []git.Hash { +func (op *OpBase) GetFiles() []repository.Hash { return nil } diff --git a/bug/operation_pack.go b/bug/operation_pack.go index 86e4178e..58c8381c 100644 --- a/bug/operation_pack.go +++ b/bug/operation_pack.go @@ -4,9 +4,9 @@ import ( "encoding/json" "fmt" - "github.com/MichaelMure/git-bug/repository" - "github.com/MichaelMure/git-bug/util/git" "github.com/pkg/errors" + + "github.com/MichaelMure/git-bug/repository" ) const formatVersion = 1 @@ -21,7 +21,7 @@ type OperationPack struct { Operations []Operation // Private field so not serialized - commitHash git.Hash + commitHash repository.Hash } func (opp *OperationPack) MarshalJSON() ([]byte, error) { @@ -135,7 +135,7 @@ func (opp *OperationPack) Validate() error { // Write will serialize and store the OperationPack as a git blob and return // its hash -func (opp *OperationPack) Write(repo repository.ClockedRepo) (git.Hash, error) { +func (opp *OperationPack) Write(repo repository.ClockedRepo) (repository.Hash, error) { // make sure we don't write invalid data err := opp.Validate() if err != nil { diff --git a/bug/operation_pack_test.go b/bug/operation_pack_test.go index 21ac0a00..b6707152 100644 --- a/bug/operation_pack_test.go +++ b/bug/operation_pack_test.go @@ -5,10 +5,11 @@ import ( "testing" "time" - "github.com/MichaelMure/git-bug/identity" - "github.com/MichaelMure/git-bug/util/git" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/MichaelMure/git-bug/identity" + "github.com/MichaelMure/git-bug/repository" ) func TestOperationPackSerialize(t *testing.T) { @@ -33,7 +34,7 @@ func TestOperationPackSerialize(t *testing.T) { assert.Equal(t, 1, len(opMeta.Metadata)) - opFile := NewAddCommentOp(rene, time.Now().Unix(), "message", []git.Hash{ + opFile := NewAddCommentOp(rene, time.Now().Unix(), "message", []repository.Hash{ "abcdef", "ghijkl", }) diff --git a/bug/operation_test.go b/bug/operation_test.go index cfd15e13..285bdbd6 100644 --- a/bug/operation_test.go +++ b/bug/operation_test.go @@ -8,7 +8,6 @@ import ( "github.com/MichaelMure/git-bug/identity" "github.com/MichaelMure/git-bug/repository" - "github.com/MichaelMure/git-bug/util/git" ) func TestValidate(t *testing.T) { @@ -46,7 +45,7 @@ func TestValidate(t *testing.T) { }, NewCreateOp(rene, unix, "multi\nline", "message", nil), - NewCreateOp(rene, unix, "title", "message", []git.Hash{git.Hash("invalid")}), + NewCreateOp(rene, unix, "title", "message", []repository.Hash{repository.Hash("invalid")}), NewCreateOp(rene, unix, "title\u001b", "message", nil), NewCreateOp(rene, unix, "title", "message\u001b", nil), NewSetTitleOp(rene, unix, "multi\nline", "title1"), @@ -54,7 +53,7 @@ func TestValidate(t *testing.T) { NewSetTitleOp(rene, unix, "title\u001b", "title2"), NewSetTitleOp(rene, unix, "title", "title2\u001b"), NewAddCommentOp(rene, unix, "message\u001b", nil), - NewAddCommentOp(rene, unix, "message", []git.Hash{git.Hash("invalid")}), + NewAddCommentOp(rene, unix, "message", []repository.Hash{repository.Hash("invalid")}), NewSetStatusOp(rene, unix, 1000), NewSetStatusOp(rene, unix, 0), NewLabelChangeOperation(rene, unix, []Label{}, []Label{}), diff --git a/bug/timeline.go b/bug/timeline.go index 4af1b92a..5a51f516 100644 --- a/bug/timeline.go +++ b/bug/timeline.go @@ -5,7 +5,7 @@ import ( "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/identity" - "github.com/MichaelMure/git-bug/util/git" + "github.com/MichaelMure/git-bug/repository" "github.com/MichaelMure/git-bug/util/timestamp" ) @@ -29,7 +29,7 @@ type CommentTimelineItem struct { id entity.Id Author identity.Interface Message string - Files []git.Hash + Files []repository.Hash CreatedAt timestamp.Timestamp LastEdit timestamp.Timestamp History []CommentHistoryStep -- cgit