aboutsummaryrefslogtreecommitdiffstats
path: root/repository/repo.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2020-06-23 18:02:54 +0200
committerMichael Muré <batolettre@gmail.com>2020-06-26 19:14:22 +0200
commit88ad7e606f1cbf9e47b968a208e3510f7f9a81c5 (patch)
tree00e847500b34c6f9a721c71474993d1c08ae8fb1 /repository/repo.go
parent2dd0dbb1344ae9293aae05346f977b5d5907934b (diff)
downloadgit-bug-88ad7e606f1cbf9e47b968a208e3510f7f9a81c5.tar.gz
repository: remove tie to Bug, improved and reusable testing
- allow the creation of arbitrary Lamport clocks, freeing the way to new entities and removing Bug specific (upper layer) code. - generalize the memory-only and persisted Lamport clocks behind a common interface - rework the tests to provide reusable testing code for a Repo, a Clock, a Config, opening a path to add a new Repo implementation more easily - test previously untested components with those new tests Note: one problem found during this endeavor is that `identity.Version` also need to store one time + Lamport time for each other Entity (Bug, config, PR ...). This could possibly done without breaking change but it would be much easier to wait for https://github.com/MichaelMure/git-bug-migration to happen.
Diffstat (limited to 'repository/repo.go')
-rw-r--r--repository/repo.go54
1 files changed, 26 insertions, 28 deletions
diff --git a/repository/repo.go b/repository/repo.go
index e8517508..561fc1c5 100644
--- a/repository/repo.go
+++ b/repository/repo.go
@@ -13,6 +13,10 @@ import (
var (
ErrNoConfigEntry = errors.New("no config entry for the given key")
ErrMultipleConfigEntry = errors.New("multiple config entry for the given key")
+ // ErrNotARepo is the error returned when the git repo root wan't be found
+ ErrNotARepo = errors.New("not a git repository")
+ // ErrClockNotExist is the error returned when a clock can't be found
+ ErrClockNotExist = errors.New("clock doesn't exist")
)
// RepoConfig access the configuration of a repository
@@ -97,36 +101,22 @@ type Repo interface {
type ClockedRepo interface {
Repo
- // LoadClocks read the clocks values from the on-disk repo
- LoadClocks() error
-
- // 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)
-
- // WitnessCreate witness another create time and increment the corresponding
- // clock if needed.
- WitnessCreate(time lamport.Time) error
-
- // WitnessEdit witness another edition time and increment the corresponding
- // clock if needed.
- WitnessEdit(time lamport.Time) error
+ // GetOrCreateClock return a Lamport clock stored in the Repo.
+ // If the clock doesn't exist, it's created.
+ GetOrCreateClock(name string) (lamport.Clock, error)
}
-// Witnesser is a function that will initialize the clocks of a repo
-// from scratch
-type Witnesser func(repo ClockedRepo) error
+// ClockLoader hold which logical clock need to exist for an entity and
+// how to create them if they don't.
+type ClockLoader struct {
+ // Clocks hold the name of all the clocks this loader deal with.
+ // Those clocks will be checked when the repo load. If not present or broken,
+ // Witnesser will be used to create them.
+ Clocks []string
+ // Witnesser is a function that will initialize the clocks of a repo
+ // from scratch
+ Witnesser func(repo ClockedRepo) error
+}
func prepareTreeEntries(entries []TreeEntry) bytes.Buffer {
var buffer bytes.Buffer
@@ -158,3 +148,11 @@ func readTreeEntries(s string) ([]TreeEntry, error) {
return casted, nil
}
+
+// TestedRepo is an extended ClockedRepo with function for testing only
+type TestedRepo interface {
+ ClockedRepo
+
+ // AddRemote add a new remote to the repository
+ AddRemote(name string, url string) error
+}