aboutsummaryrefslogtreecommitdiffstats
path: root/cache
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2020-06-25 23:18:17 +0200
committerMichael Muré <batolettre@gmail.com>2020-06-25 23:18:17 +0200
commitaab3a04d0c4ddbf97d589ba9048a539c6d7186e9 (patch)
tree5db59215d2c9559c2d33d1a2a2010270a88d669d /cache
parent1d06244c82b18959878cf199cd8dd500bbc46aa7 (diff)
downloadgit-bug-aab3a04d0c4ddbf97d589ba9048a539c6d7186e9.tar.gz
bug: harmonize how time are used, fix some issues in command special formats
This assume that the convertion from time.Time <--> Unix timestamp is lossless which seems to be.
Diffstat (limited to 'cache')
-rw-r--r--cache/bug_excerpt.go21
-rw-r--r--cache/repo_cache.go12
2 files changed, 23 insertions, 10 deletions
diff --git a/cache/bug_excerpt.go b/cache/bug_excerpt.go
index 36c7dcfe..e9d5863f 100644
--- a/cache/bug_excerpt.go
+++ b/cache/bug_excerpt.go
@@ -3,6 +3,7 @@ package cache
import (
"encoding/gob"
"fmt"
+ "time"
"github.com/MichaelMure/git-bug/bug"
"github.com/MichaelMure/git-bug/entity"
@@ -22,8 +23,8 @@ type BugExcerpt struct {
CreateLamportTime lamport.Time
EditLamportTime lamport.Time
- CreateUnixTime int64
- EditUnixTime int64
+ createUnixTime int64
+ editUnixTime int64
Status bug.Status
Labels []bug.Label
@@ -79,8 +80,8 @@ func NewBugExcerpt(b bug.Interface, snap *bug.Snapshot) *BugExcerpt {
Id: b.Id(),
CreateLamportTime: b.CreateLamportTime(),
EditLamportTime: b.EditLamportTime(),
- CreateUnixTime: b.FirstOp().GetUnixTime(),
- EditUnixTime: snap.LastEditUnix(),
+ createUnixTime: b.FirstOp().Time().Unix(),
+ editUnixTime: snap.EditTime().Unix(),
Status: snap.Status,
Labels: snap.Labels,
Actors: actorsIds,
@@ -105,6 +106,14 @@ func NewBugExcerpt(b bug.Interface, snap *bug.Snapshot) *BugExcerpt {
return e
}
+func (b *BugExcerpt) CreateTime() time.Time {
+ return time.Unix(b.createUnixTime, 0)
+}
+
+func (b *BugExcerpt) EditTime() time.Time {
+ return time.Unix(b.editUnixTime, 0)
+}
+
/*
* Sorting
*/
@@ -144,7 +153,7 @@ func (b BugsByCreationTime) Less(i, j int) bool {
// by the first sorting using the logical clock. That means that if users
// synchronize their bugs regularly, the timestamp will rarely be used, and
// should still provide a kinda accurate sorting when needed.
- return b[i].CreateUnixTime < b[j].CreateUnixTime
+ return b[i].createUnixTime < b[j].createUnixTime
}
func (b BugsByCreationTime) Swap(i, j int) {
@@ -172,7 +181,7 @@ func (b BugsByEditTime) Less(i, j int) bool {
// by the first sorting using the logical clock. That means that if users
// synchronize their bugs regularly, the timestamp will rarely be used, and
// should still provide a kinda accurate sorting when needed.
- return b[i].EditUnixTime < b[j].EditUnixTime
+ return b[i].editUnixTime < b[j].editUnixTime
}
func (b BugsByEditTime) Swap(i, j int) {
diff --git a/cache/repo_cache.go b/cache/repo_cache.go
index f2e1c7d0..83ce4802 100644
--- a/cache/repo_cache.go
+++ b/cache/repo_cache.go
@@ -29,7 +29,8 @@ const identityCacheFile = "identity-cache"
// 1: original format
// 2: added cache for identities with a reference in the bug cache
-const formatVersion = 2
+// 3: CreateUnixTime --> createUnixTime, EditUnixTime --> editUnixTime
+const formatVersion = 3
type ErrInvalidCacheFormat struct {
message string
@@ -99,10 +100,13 @@ func NewNamedRepoCache(r repository.ClockedRepo, name string) (*RepoCache, error
if err == nil {
return c, nil
}
- if _, ok := err.(ErrInvalidCacheFormat); ok {
+ if _, ok := err.(ErrInvalidCacheFormat); !ok {
+ // Actual error
return nil, err
}
+ // We have an outdated cache format, rebuilding it.
+
err = c.buildCache()
if err != nil {
return nil, err
@@ -254,7 +258,7 @@ func (c *RepoCache) loadBugCache() error {
return err
}
- if aux.Version != 2 {
+ if aux.Version != formatVersion {
return ErrInvalidCacheFormat{
message: fmt.Sprintf("unknown cache format version %v", aux.Version),
}
@@ -286,7 +290,7 @@ func (c *RepoCache) loadIdentityCache() error {
return err
}
- if aux.Version != 2 {
+ if aux.Version != formatVersion {
return ErrInvalidCacheFormat{
message: fmt.Sprintf("unknown cache format version %v", aux.Version),
}