diff options
Diffstat (limited to 'bug')
-rw-r--r-- | bug/bug.go | 10 | ||||
-rw-r--r-- | bug/interface.go | 7 | ||||
-rw-r--r-- | bug/operation.go | 13 | ||||
-rw-r--r-- | bug/operations/add_comment.go | 2 | ||||
-rw-r--r-- | bug/operations/create.go | 2 | ||||
-rw-r--r-- | bug/operations/create_test.go | 2 | ||||
-rw-r--r-- | bug/snapshot.go | 11 |
7 files changed, 40 insertions, 7 deletions
@@ -579,6 +579,16 @@ func formatHumanId(id string) string { return fmt.Sprintf(format, id) } +// CreateLamportTime return the Lamport time of creation +func (bug *Bug) CreateLamportTime() util.LamportTime { + return bug.createTime +} + +// EditLamportTime return the Lamport time of the last edit +func (bug *Bug) EditLamportTime() util.LamportTime { + return bug.editTime +} + // Lookup for the very first operation of the bug. // For a valid Bug, this operation should be a CreateOp func (bug *Bug) FirstOp() Operation { diff --git a/bug/interface.go b/bug/interface.go index af10b895..79333d07 100644 --- a/bug/interface.go +++ b/bug/interface.go @@ -2,6 +2,7 @@ package bug import ( "github.com/MichaelMure/git-bug/repository" + "github.com/MichaelMure/git-bug/util" ) type Interface interface { @@ -38,6 +39,12 @@ type Interface interface { // Compile a bug in a easily usable snapshot Compile() Snapshot + + // CreateLamportTime return the Lamport time of creation + CreateLamportTime() util.LamportTime + + // EditLamportTime return the Lamport time of the last edit + EditLamportTime() util.LamportTime } func bugFromInterface(bug Interface) *Bug { diff --git a/bug/operation.go b/bug/operation.go index cdf87931..7d71e352 100644 --- a/bug/operation.go +++ b/bug/operation.go @@ -23,6 +23,8 @@ type Operation interface { OpType() OperationType // Time return the time when the operation was added Time() time.Time + // unixTime return the unix timestamp when the operation was added + UnixTime() int64 // Apply the operation to a Snapshot to create the final state Apply(snapshot Snapshot) Snapshot // Files return the files needed by this operation @@ -36,7 +38,7 @@ type Operation interface { type OpBase struct { OperationType OperationType Author Person - UnixTime int64 + unixTime int64 } // NewOpBase is the constructor for an OpBase @@ -44,7 +46,7 @@ func NewOpBase(opType OperationType, author Person) OpBase { return OpBase{ OperationType: opType, Author: author, - UnixTime: time.Now().Unix(), + unixTime: time.Now().Unix(), } } @@ -55,7 +57,12 @@ func (op OpBase) OpType() OperationType { // Time return the time when the operation was added func (op OpBase) Time() time.Time { - return time.Unix(op.UnixTime, 0) + return time.Unix(op.unixTime, 0) +} + +// unixTime return the unix timestamp when the operation was added +func (op OpBase) UnixTime() int64 { + return op.unixTime } // Files return the files needed by this operation diff --git a/bug/operations/add_comment.go b/bug/operations/add_comment.go index b4126a8e..5ecc471a 100644 --- a/bug/operations/add_comment.go +++ b/bug/operations/add_comment.go @@ -21,7 +21,7 @@ func (op AddCommentOperation) Apply(snapshot bug.Snapshot) bug.Snapshot { Message: op.Message, Author: op.Author, Files: op.files, - UnixTime: op.UnixTime, + UnixTime: op.UnixTime(), } snapshot.Comments = append(snapshot.Comments, comment) diff --git a/bug/operations/create.go b/bug/operations/create.go index ecbafb6f..5fc939dd 100644 --- a/bug/operations/create.go +++ b/bug/operations/create.go @@ -22,7 +22,7 @@ func (op CreateOperation) Apply(snapshot bug.Snapshot) bug.Snapshot { { Message: op.Message, Author: op.Author, - UnixTime: op.UnixTime, + UnixTime: op.UnixTime(), }, } snapshot.Author = op.Author diff --git a/bug/operations/create_test.go b/bug/operations/create_test.go index a20472d3..319cdb7f 100644 --- a/bug/operations/create_test.go +++ b/bug/operations/create_test.go @@ -21,7 +21,7 @@ func TestCreate(t *testing.T) { expected := bug.Snapshot{ Title: "title", Comments: []bug.Comment{ - {Author: rene, Message: "message", UnixTime: create.UnixTime}, + {Author: rene, Message: "message", UnixTime: create.UnixTime()}, }, Author: rene, CreatedAt: create.Time(), diff --git a/bug/snapshot.go b/bug/snapshot.go index 7f1d6099..1ef4534b 100644 --- a/bug/snapshot.go +++ b/bug/snapshot.go @@ -37,10 +37,19 @@ func (snap Snapshot) Summary() string { } // Return the last time a bug was modified -func (snap Snapshot) LastEdit() time.Time { +func (snap Snapshot) LastEditTime() time.Time { if len(snap.Operations) == 0 { return time.Unix(0, 0) } return snap.Operations[len(snap.Operations)-1].Time() } + +// Return the last timestamp a bug was modified +func (snap Snapshot) LastEditUnix() int64 { + if len(snap.Operations) == 0 { + return 0 + } + + return snap.Operations[len(snap.Operations)-1].UnixTime() +} |