aboutsummaryrefslogtreecommitdiffstats
path: root/repository
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2019-02-19 00:19:27 +0100
committerMichael Muré <batolettre@gmail.com>2019-03-01 22:40:27 +0100
commit71f9290fdae7551f3d3ada2179ece4084304d734 (patch)
tree3494e4d4491012899ace256f534f5faea1ba2a88 /repository
parentffe35fece1b1526949107f154abc21a1a02fc74d (diff)
downloadgit-bug-71f9290fdae7551f3d3ada2179ece4084304d734.tar.gz
identity: store the times properly
Diffstat (limited to 'repository')
-rw-r--r--repository/git.go12
-rw-r--r--repository/mock_repo.go10
-rw-r--r--repository/repo.go7
3 files changed, 29 insertions, 0 deletions
diff --git a/repository/git.go b/repository/git.go
index 10fddac3..836de8f0 100644
--- a/repository/git.go
+++ b/repository/git.go
@@ -20,6 +20,8 @@ const editClockFile = "/.git/git-bug/edit-clock"
// ErrNotARepo is the error returned when the git repo root wan't be found
var ErrNotARepo = errors.New("not a git repository")
+var _ ClockedRepo = &GitRepo{}
+
// GitRepo represents an instance of a (local) git repository.
type GitRepo struct {
Path string
@@ -440,11 +442,21 @@ func (repo *GitRepo) WriteClocks() error {
return nil
}
+// CreateTime return the current value of the creation clock
+func (repo *GitRepo) CreateTime() lamport.Time {
+ return repo.createClock.Time()
+}
+
// CreateTimeIncrement increment the creation clock and return the new value.
func (repo *GitRepo) CreateTimeIncrement() (lamport.Time, error) {
return repo.createClock.Increment()
}
+// EditTime return the current value of the edit clock
+func (repo *GitRepo) EditTime() lamport.Time {
+ return repo.editClock.Time()
+}
+
// EditTimeIncrement increment the edit clock and return the new value.
func (repo *GitRepo) EditTimeIncrement() (lamport.Time, error) {
return repo.editClock.Increment()
diff --git a/repository/mock_repo.go b/repository/mock_repo.go
index 74de8f57..97a4504f 100644
--- a/repository/mock_repo.go
+++ b/repository/mock_repo.go
@@ -9,6 +9,8 @@ import (
"github.com/MichaelMure/git-bug/util/lamport"
)
+var _ ClockedRepo = &mockRepoForTest{}
+
// mockRepoForTest defines an instance of Repo that can be used for testing.
type mockRepoForTest struct {
config map[string]string
@@ -227,10 +229,18 @@ func (r *mockRepoForTest) WriteClocks() error {
return nil
}
+func (r *mockRepoForTest) CreateTime() lamport.Time {
+ return r.createClock.Time()
+}
+
func (r *mockRepoForTest) CreateTimeIncrement() (lamport.Time, error) {
return r.createClock.Increment(), nil
}
+func (r *mockRepoForTest) EditTime() lamport.Time {
+ return r.editClock.Time()
+}
+
func (r *mockRepoForTest) EditTimeIncrement() (lamport.Time, error) {
return r.editClock.Increment(), nil
}
diff --git a/repository/repo.go b/repository/repo.go
index 100feaed..8a66c320 100644
--- a/repository/repo.go
+++ b/repository/repo.go
@@ -83,6 +83,7 @@ type Repo interface {
GetTreeHash(commit git.Hash) (git.Hash, error)
}
+// ClockedRepo is a Repo that also has Lamport clocks
type ClockedRepo interface {
Repo
@@ -92,9 +93,15 @@ type ClockedRepo interface {
// WriteClocks write the clocks values into the repo
WriteClocks() error
+ // CreateTime return the current value of the creation clock
+ CreateTime() lamport.Time
+
// CreateTimeIncrement increment the creation clock and return the new value.
CreateTimeIncrement() (lamport.Time, error)
+ // EditTime return the current value of the edit clock
+ EditTime() lamport.Time
+
// EditTimeIncrement increment the edit clock and return the new value.
EditTimeIncrement() (lamport.Time, error)