From c46d01f8c10e6363b680fa6876e91bd8eaf3bb3e Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sat, 29 Sep 2018 20:41:19 +0200 Subject: bug: implement comment edition - add a new operation - add a new "timeline" in the snapshot that hold a processed version of the operations --- bug/snapshot.go | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'bug/snapshot.go') diff --git a/bug/snapshot.go b/bug/snapshot.go index 59dcae7e..df39ff46 100644 --- a/bug/snapshot.go +++ b/bug/snapshot.go @@ -3,6 +3,8 @@ package bug import ( "fmt" "time" + + "github.com/MichaelMure/git-bug/util/git" ) // Snapshot is a compiled form of the Bug data structure used for storage and merge @@ -16,20 +18,22 @@ type Snapshot struct { Author Person CreatedAt time.Time + Timeline []TimelineItem + Operations []Operation } // Return the Bug identifier -func (snap Snapshot) Id() string { +func (snap *Snapshot) Id() string { return snap.id } // Return the Bug identifier truncated for human consumption -func (snap Snapshot) HumanId() string { +func (snap *Snapshot) HumanId() string { return fmt.Sprintf("%.8s", snap.id) } -func (snap Snapshot) Summary() string { +func (snap *Snapshot) Summary() string { return fmt.Sprintf("C:%d L:%d", len(snap.Comments)-1, len(snap.Labels), @@ -37,7 +41,7 @@ func (snap Snapshot) Summary() string { } // Return the last time a bug was modified -func (snap Snapshot) LastEditTime() time.Time { +func (snap *Snapshot) LastEditTime() time.Time { if len(snap.Operations) == 0 { return time.Unix(0, 0) } @@ -46,10 +50,26 @@ func (snap Snapshot) LastEditTime() time.Time { } // Return the last timestamp a bug was modified -func (snap Snapshot) LastEditUnix() int64 { +func (snap *Snapshot) LastEditUnix() int64 { if len(snap.Operations) == 0 { return 0 } return snap.Operations[len(snap.Operations)-1].GetUnixTime() } + +// SearchTimelineItem will search in the timeline for an item matching the given hash +func (snap *Snapshot) SearchTimelineItem(hash git.Hash) (TimelineItem, error) { + for i := range snap.Timeline { + h, err := snap.Timeline[i].Hash() + if err != nil { + return nil, err + } + + if h == hash { + return snap.Timeline[i], nil + } + } + + return nil, fmt.Errorf("timeline item not found") +} -- cgit