aboutsummaryrefslogtreecommitdiffstats
path: root/bug/snapshot.go
diff options
context:
space:
mode:
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")
+}