aboutsummaryrefslogtreecommitdiffstats
path: root/bug/snapshot.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-09-29 20:41:19 +0200
committerMichael Muré <batolettre@gmail.com>2018-09-29 20:41:19 +0200
commitc46d01f8c10e6363b680fa6876e91bd8eaf3bb3e (patch)
treedde41c1253534bf4ff36e39454f2bdbdf4b9590f /bug/snapshot.go
parent41e61a67b63e4d6c517005cf6f427115a664bdb5 (diff)
downloadgit-bug-c46d01f8c10e6363b680fa6876e91bd8eaf3bb3e.tar.gz
bug: implement comment edition
- add a new operation - add a new "timeline" in the snapshot that hold a processed version of the operations
Diffstat (limited to 'bug/snapshot.go')
-rw-r--r--bug/snapshot.go30
1 files changed, 25 insertions, 5 deletions
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")
+}