diff options
author | Michael Muré <batolettre@gmail.com> | 2018-09-30 11:10:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-30 11:10:03 +0200 |
commit | d71bb7dd7632780cf5aad5fda84027fa03a9d0f0 (patch) | |
tree | dba6c3c0bab18f41e21cd36a9fe05d1d27a574d4 /bug/snapshot.go | |
parent | 8fdd6bf99c111c3756056e87ffd9209875ac5c1f (diff) | |
parent | bad9cda969b49bf1bce6799056476ac4684892df (diff) | |
download | git-bug-d71bb7dd7632780cf5aad5fda84027fa03a9d0f0.tar.gz |
Merge pull request #54 from MichaelMure/editablecomment
Core support for editable comments
Diffstat (limited to 'bug/snapshot.go')
-rw-r--r-- | bug/snapshot.go | 30 |
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") +} |