From 71f9290fdae7551f3d3ada2179ece4084304d734 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Tue, 19 Feb 2019 00:19:27 +0100 Subject: identity: store the times properly --- repository/git.go | 12 ++++++++++++ repository/mock_repo.go | 10 ++++++++++ repository/repo.go | 7 +++++++ 3 files changed, 29 insertions(+) (limited to 'repository') 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) -- cgit