diff options
-rw-r--r-- | bridge/core/bridge.go | 6 | ||||
-rw-r--r-- | bridge/core/export.go | 11 | ||||
-rw-r--r-- | bridge/core/import.go | 14 | ||||
-rw-r--r-- | bridge/github/config.go | 6 | ||||
-rw-r--r-- | bridge/github/export.go | 12 | ||||
-rw-r--r-- | bridge/github/export_test.go | 10 | ||||
-rw-r--r-- | bridge/github/import.go | 65 | ||||
-rw-r--r-- | bridge/github/import_test.go | 2 | ||||
-rw-r--r-- | bridge/gitlab/config.go | 6 | ||||
-rw-r--r-- | bridge/gitlab/export.go | 18 | ||||
-rw-r--r-- | bridge/gitlab/export_test.go | 10 | ||||
-rw-r--r-- | bridge/gitlab/gitlab.go | 8 | ||||
-rw-r--r-- | bridge/gitlab/import.go | 34 | ||||
-rw-r--r-- | bridge/gitlab/import_test.go | 2 | ||||
-rw-r--r-- | bridge/launchpad/config.go | 6 | ||||
-rw-r--r-- | bridge/launchpad/import.go | 19 | ||||
-rw-r--r-- | bug/bug.go | 21 | ||||
-rw-r--r-- | bug/bug_actions_test.go | 8 | ||||
-rw-r--r-- | bug/bug_test.go | 9 | ||||
-rw-r--r-- | bug/clocks.go | 4 | ||||
-rw-r--r-- | bug/interface.go | 4 | ||||
-rw-r--r-- | bug/op_set_metadata.go | 2 | ||||
-rw-r--r-- | bug/operation_iterator_test.go | 34 | ||||
-rw-r--r-- | commands/bridge_configure.go | 12 | ||||
-rw-r--r-- | misc/random_bugs/create_random_bugs.go | 31 | ||||
-rw-r--r-- | repository/git.go | 8 | ||||
-rw-r--r-- | repository/mock_repo.go | 4 | ||||
-rw-r--r-- | repository/repo.go | 8 |
28 files changed, 218 insertions, 156 deletions
diff --git a/bridge/core/bridge.go b/bridge/core/bridge.go index e419ed77..a3133b9c 100644 --- a/bridge/core/bridge.go +++ b/bridge/core/bridge.go @@ -20,8 +20,8 @@ var ErrImportNotSupported = errors.New("import is not supported") var ErrExportNotSupported = errors.New("export is not supported") const ( - KeyTarget = "target" - KeyOrigin = "origin" + ConfigKeyTarget = "target" + MetaKeyOrigin = "origin" bridgeConfigKeyPrefix = "git-bug.bridge" ) @@ -102,7 +102,7 @@ func LoadBridge(repo *cache.RepoCache, name string) (*Bridge, error) { return nil, err } - target := conf[KeyTarget] + target := conf[ConfigKeyTarget] bridge, err := NewBridge(repo, target, name) if err != nil { return nil, err diff --git a/bridge/core/export.go b/bridge/core/export.go index 558b3d78..0f45404c 100644 --- a/bridge/core/export.go +++ b/bridge/core/export.go @@ -10,13 +10,24 @@ type ExportEvent int const ( _ ExportEvent = iota + + // Bug has been exported on the remote tracker ExportEventBug + // Comment has been exported on the remote tracker ExportEventComment + // Comment has been edited on the remote tracker ExportEventCommentEdition + // Bug's status has been changed on on the remote tracker ExportEventStatusChange + // Bug's title has been changed on the remote tracker ExportEventTitleEdition + // Bug's labels have been changed on the remote tracker ExportEventLabelChange + + // Nothing changed on the bug ExportEventNothing + + // Error happened during export ExportEventError ) diff --git a/bridge/core/import.go b/bridge/core/import.go index cff30f61..e4771d2c 100644 --- a/bridge/core/import.go +++ b/bridge/core/import.go @@ -10,14 +10,26 @@ type ImportEvent int const ( _ ImportEvent = iota + + // Bug has been created ImportEventBug + // Comment has been created ImportEventComment + // Comment has been edited ImportEventCommentEdition + // Bug's status has changed ImportEventStatusChange + // Bug's title has changed ImportEventTitleEdition + // Bug's labels changed ImportEventLabelChange - ImportEventIdentity + // Nothing happened on a Bug ImportEventNothing + + // Identity has been created + ImportEventIdentity + + // Error happened during import ImportEventError ) diff --git a/bridge/github/config.go b/bridge/github/config.go index 16abfa09..434a2c63 100644 --- a/bridge/github/config.go +++ b/bridge/github/config.go @@ -114,7 +114,7 @@ func (g *Github) Configure(repo repository.RepoCommon, params core.BridgeParams) return nil, fmt.Errorf("project doesn't exist or authentication token has an incorrect scope") } - conf[core.KeyTarget] = target + conf[core.ConfigKeyTarget] = target conf[keyToken] = token conf[keyOwner] = owner conf[keyProject] = project @@ -128,8 +128,8 @@ func (g *Github) Configure(repo repository.RepoCommon, params core.BridgeParams) } func (*Github) ValidateConfig(conf core.Configuration) error { - if v, ok := conf[core.KeyTarget]; !ok { - return fmt.Errorf("missing %s key", core.KeyTarget) + if v, ok := conf[core.ConfigKeyTarget]; !ok { + return fmt.Errorf("missing %s key", core.ConfigKeyTarget) } else if v != target { return fmt.Errorf("unexpected target name: %v", v) } diff --git a/bridge/github/export.go b/bridge/github/export.go index a79256fc..e2a185b0 100644 --- a/bridge/github/export.go +++ b/bridge/github/export.go @@ -174,16 +174,16 @@ func (ge *githubExporter) exportBug(ctx context.Context, b *cache.BugCache, sinc author := snapshot.Author // skip bug if origin is not allowed - origin, ok := snapshot.GetCreateMetadata(keyOrigin) + origin, ok := snapshot.GetCreateMetadata(core.MetaKeyOrigin) if ok && origin != target { out <- core.NewExportNothing(b.Id(), fmt.Sprintf("issue tagged with origin: %s", origin)) return } // get github bug ID - githubID, ok := snapshot.GetCreateMetadata(keyGithubId) + githubID, ok := snapshot.GetCreateMetadata(metaKeyGithubId) if ok { - githubURL, ok := snapshot.GetCreateMetadata(keyGithubUrl) + githubURL, ok := snapshot.GetCreateMetadata(metaKeyGithubUrl) if !ok { // if we find github ID, github URL must be found too err := fmt.Errorf("incomplete Github metadata: expected to find issue URL") @@ -258,7 +258,7 @@ func (ge *githubExporter) exportBug(ctx context.Context, b *cache.BugCache, sinc // ignore operations already existing in github (due to import or export) // cache the ID of already exported or imported issues and events from Github - if id, ok := op.GetMetadata(keyGithubId); ok { + if id, ok := op.GetMetadata(metaKeyGithubId); ok { ge.cachedOperationIDs[op.Id()] = id out <- core.NewExportNothing(op.Id(), "already exported operation") continue @@ -437,8 +437,8 @@ func markOperationAsExported(b *cache.BugCache, target entity.Id, githubID, gith _, err := b.SetMetadata( target, map[string]string{ - keyGithubId: githubID, - keyGithubUrl: githubURL, + metaKeyGithubId: githubID, + metaKeyGithubUrl: githubURL, }, ) diff --git a/bridge/github/export_test.go b/bridge/github/export_test.go index e39ace01..dba72f3f 100644 --- a/bridge/github/export_test.go +++ b/bridge/github/export_test.go @@ -233,27 +233,27 @@ func TestPushPull(t *testing.T) { for _, op := range tt.bug.Snapshot().Operations { // Check if the originals operations (*not* SetMetadata) are tagged properly if _, ok := op.(*bug.SetMetadataOperation); !ok { - _, haveIDMetadata := op.GetMetadata(keyGithubId) + _, haveIDMetadata := op.GetMetadata(metaKeyGithubId) require.True(t, haveIDMetadata) - _, haveURLMetada := op.GetMetadata(keyGithubUrl) + _, haveURLMetada := op.GetMetadata(metaKeyGithubUrl) require.True(t, haveURLMetada) } } // get bug github ID - bugGithubID, ok := tt.bug.Snapshot().GetCreateMetadata(keyGithubId) + bugGithubID, ok := tt.bug.Snapshot().GetCreateMetadata(metaKeyGithubId) require.True(t, ok) // retrieve bug from backendTwo - importedBug, err := backendTwo.ResolveBugCreateMetadata(keyGithubId, bugGithubID) + importedBug, err := backendTwo.ResolveBugCreateMetadata(metaKeyGithubId, bugGithubID) require.NoError(t, err) // verify bug have same number of original operations require.Len(t, importedBug.Snapshot().Operations, tt.numOrOp) // verify bugs are taged with origin=github - issueOrigin, ok := importedBug.Snapshot().GetCreateMetadata(keyOrigin) + issueOrigin, ok := importedBug.Snapshot().GetCreateMetadata(core.MetaKeyOrigin) require.True(t, ok) require.Equal(t, issueOrigin, target) diff --git a/bridge/github/import.go b/bridge/github/import.go index 7c4deb50..d3d56cbc 100644 --- a/bridge/github/import.go +++ b/bridge/github/import.go @@ -15,10 +15,9 @@ import ( ) const ( - keyOrigin = "origin" - keyGithubId = "github-id" - keyGithubUrl = "github-url" - keyGithubLogin = "github-login" + metaKeyGithubId = "github-id" + metaKeyGithubUrl = "github-url" + metaKeyGithubLogin = "github-login" ) // githubImporter implement the Importer interface @@ -92,7 +91,7 @@ func (gi *githubImporter) ensureIssue(repo *cache.RepoCache, issue issueTimeline } // resolve bug - b, err := repo.ResolveBugCreateMetadata(keyGithubUrl, issue.Url.String()) + b, err := repo.ResolveBugCreateMetadata(metaKeyGithubUrl, issue.Url.String()) if err != nil && err != bug.ErrBugNotExist { return nil, err } @@ -119,9 +118,9 @@ func (gi *githubImporter) ensureIssue(repo *cache.RepoCache, issue issueTimeline cleanText, nil, map[string]string{ - keyOrigin: target, - keyGithubId: parseId(issue.Id), - keyGithubUrl: issue.Url.String(), + core.MetaKeyOrigin: target, + metaKeyGithubId: parseId(issue.Id), + metaKeyGithubUrl: issue.Url.String(), }) if err != nil { return nil, err @@ -157,9 +156,9 @@ func (gi *githubImporter) ensureIssue(repo *cache.RepoCache, issue issueTimeline cleanText, nil, map[string]string{ - keyOrigin: target, - keyGithubId: parseId(issue.Id), - keyGithubUrl: issue.Url.String(), + core.MetaKeyOrigin: target, + metaKeyGithubId: parseId(issue.Id), + metaKeyGithubUrl: issue.Url.String(), }, ) @@ -173,7 +172,7 @@ func (gi *githubImporter) ensureIssue(repo *cache.RepoCache, issue issueTimeline } // other edits will be added as CommentEdit operations - target, err := b.ResolveOperationWithMetadata(keyGithubId, parseId(issue.Id)) + target, err := b.ResolveOperationWithMetadata(metaKeyGithubId, parseId(issue.Id)) if err != nil { return nil, err } @@ -206,7 +205,7 @@ func (gi *githubImporter) ensureTimelineItem(repo *cache.RepoCache, b *cache.Bug case "LabeledEvent": id := parseId(item.LabeledEvent.Id) - _, err := b.ResolveOperationWithMetadata(keyGithubId, id) + _, err := b.ResolveOperationWithMetadata(metaKeyGithubId, id) if err == nil { reason := fmt.Sprintf("operation already imported: %v", item.Typename) gi.out <- core.NewImportNothing("", reason) @@ -227,7 +226,7 @@ func (gi *githubImporter) ensureTimelineItem(repo *cache.RepoCache, b *cache.Bug string(item.LabeledEvent.Label.Name), }, nil, - map[string]string{keyGithubId: id}, + map[string]string{metaKeyGithubId: id}, ) if err != nil { return err @@ -238,7 +237,7 @@ func (gi *githubImporter) ensureTimelineItem(repo *cache.RepoCache, b *cache.Bug case "UnlabeledEvent": id := parseId(item.UnlabeledEvent.Id) - _, err := b.ResolveOperationWithMetadata(keyGithubId, id) + _, err := b.ResolveOperationWithMetadata(metaKeyGithubId, id) if err == nil { reason := fmt.Sprintf("operation already imported: %v", item.Typename) gi.out <- core.NewImportNothing("", reason) @@ -259,7 +258,7 @@ func (gi *githubImporter) ensureTimelineItem(repo *cache.RepoCache, b *cache.Bug []string{ string(item.UnlabeledEvent.Label.Name), }, - map[string]string{keyGithubId: id}, + map[string]string{metaKeyGithubId: id}, ) if err != nil { return err @@ -270,7 +269,7 @@ func (gi *githubImporter) ensureTimelineItem(repo *cache.RepoCache, b *cache.Bug case "ClosedEvent": id := parseId(item.ClosedEvent.Id) - _, err := b.ResolveOperationWithMetadata(keyGithubId, id) + _, err := b.ResolveOperationWithMetadata(metaKeyGithubId, id) if err != cache.ErrNoMatchingOp { return err } @@ -286,7 +285,7 @@ func (gi *githubImporter) ensureTimelineItem(repo *cache.RepoCache, b *cache.Bug op, err := b.CloseRaw( author, item.ClosedEvent.CreatedAt.Unix(), - map[string]string{keyGithubId: id}, + map[string]string{metaKeyGithubId: id}, ) if err != nil { @@ -298,7 +297,7 @@ func (gi *githubImporter) ensureTimelineItem(repo *cache.RepoCache, b *cache.Bug case "ReopenedEvent": id := parseId(item.ReopenedEvent.Id) - _, err := b.ResolveOperationWithMetadata(keyGithubId, id) + _, err := b.ResolveOperationWithMetadata(metaKeyGithubId, id) if err != cache.ErrNoMatchingOp { return err } @@ -314,7 +313,7 @@ func (gi *githubImporter) ensureTimelineItem(repo *cache.RepoCache, b *cache.Bug op, err := b.OpenRaw( author, item.ReopenedEvent.CreatedAt.Unix(), - map[string]string{keyGithubId: id}, + map[string]string{metaKeyGithubId: id}, ) if err != nil { @@ -326,7 +325,7 @@ func (gi *githubImporter) ensureTimelineItem(repo *cache.RepoCache, b *cache.Bug case "RenamedTitleEvent": id := parseId(item.RenamedTitleEvent.Id) - _, err := b.ResolveOperationWithMetadata(keyGithubId, id) + _, err := b.ResolveOperationWithMetadata(metaKeyGithubId, id) if err != cache.ErrNoMatchingOp { return err } @@ -343,7 +342,7 @@ func (gi *githubImporter) ensureTimelineItem(repo *cache.RepoCache, b *cache.Bug author, item.RenamedTitleEvent.CreatedAt.Unix(), string(item.RenamedTitleEvent.CurrentTitle), - map[string]string{keyGithubId: id}, + map[string]string{metaKeyGithubId: id}, ) if err != nil { return err @@ -367,7 +366,7 @@ func (gi *githubImporter) ensureTimelineComment(repo *cache.RepoCache, b *cache. return err } - targetOpID, err := b.ResolveOperationWithMetadata(keyGithubId, parseId(item.Id)) + targetOpID, err := b.ResolveOperationWithMetadata(metaKeyGithubId, parseId(item.Id)) if err == nil { gi.out <- core.NewImportNothing("", "comment already imported") } else if err != cache.ErrNoMatchingOp { @@ -390,8 +389,8 @@ func (gi *githubImporter) ensureTimelineComment(repo *cache.RepoCache, b *cache. cleanText, nil, map[string]string{ - keyGithubId: parseId(item.Id), - keyGithubUrl: parseId(item.Url.String()), + metaKeyGithubId: parseId(item.Id), + metaKeyGithubUrl: parseId(item.Url.String()), }, ) if err != nil { @@ -428,8 +427,8 @@ func (gi *githubImporter) ensureTimelineComment(repo *cache.RepoCache, b *cache. cleanText, nil, map[string]string{ - keyGithubId: parseId(item.Id), - keyGithubUrl: item.Url.String(), + metaKeyGithubId: parseId(item.Id), + metaKeyGithubUrl: item.Url.String(), }, ) if err != nil { @@ -451,7 +450,7 @@ func (gi *githubImporter) ensureTimelineComment(repo *cache.RepoCache, b *cache. } func (gi *githubImporter) ensureCommentEdit(repo *cache.RepoCache, b *cache.BugCache, target entity.Id, edit userContentEdit) error { - _, err := b.ResolveOperationWithMetadata(keyGithubId, parseId(edit.Id)) + _, err := b.ResolveOperationWithMetadata(metaKeyGithubId, parseId(edit.Id)) if err == nil { gi.out <- core.NewImportNothing(b.Id(), "edition already imported") return nil @@ -485,7 +484,7 @@ func (gi *githubImporter) ensureCommentEdit(repo *cache.RepoCache, b *cache.BugC target, cleanText, map[string]string{ - keyGithubId: parseId(edit.Id), + metaKeyGithubId: parseId(edit.Id), }, ) @@ -508,7 +507,7 @@ func (gi *githubImporter) ensurePerson(repo *cache.RepoCache, actor *actor) (*ca } // Look first in the cache - i, err := repo.ResolveIdentityImmutableMetadata(keyGithubLogin, string(actor.Login)) + i, err := repo.ResolveIdentityImmutableMetadata(metaKeyGithubLogin, string(actor.Login)) if err == nil { return i, nil } @@ -543,7 +542,7 @@ func (gi *githubImporter) ensurePerson(repo *cache.RepoCache, actor *actor) (*ca string(actor.Login), string(actor.AvatarUrl), map[string]string{ - keyGithubLogin: string(actor.Login), + metaKeyGithubLogin: string(actor.Login), }, ) @@ -557,7 +556,7 @@ func (gi *githubImporter) ensurePerson(repo *cache.RepoCache, actor *actor) (*ca func (gi *githubImporter) getGhost(repo *cache.RepoCache) (*cache.IdentityCache, error) { // Look first in the cache - i, err := repo.ResolveIdentityImmutableMetadata(keyGithubLogin, "ghost") + i, err := repo.ResolveIdentityImmutableMetadata(metaKeyGithubLogin, "ghost") if err == nil { return i, nil } @@ -592,7 +591,7 @@ func (gi *githubImporter) getGhost(repo *cache.RepoCache) (*cache.IdentityCache, string(q.User.Login), string(q.User.AvatarUrl), map[string]string{ - keyGithubLogin: string(q.User.Login), + metaKeyGithubLogin: string(q.User.Login), }, ) } diff --git a/bridge/github/import_test.go b/bridge/github/import_test.go index 41bcb58d..f1558831 100644 --- a/bridge/github/import_test.go +++ b/bridge/github/import_test.go @@ -163,7 +163,7 @@ func Test_Importer(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - b, err := backend.ResolveBugCreateMetadata(keyGithubUrl, tt.url) + b, err := backend.ResolveBugCreateMetadata(metaKeyGithubUrl, tt.url) require.NoError(t, err) ops := b.Snapshot().Operations diff --git a/bridge/gitlab/config.go b/bridge/gitlab/config.go index a673af8c..f2e667a8 100644 --- a/bridge/gitlab/config.go +++ b/bridge/gitlab/config.go @@ -80,7 +80,7 @@ func (g *Gitlab) Configure(repo repository.RepoCommon, params core.BridgeParams) conf[keyProjectID] = strconv.Itoa(id) conf[keyToken] = token - conf[core.KeyTarget] = target + conf[core.ConfigKeyTarget] = target err = g.ValidateConfig(conf) if err != nil { @@ -91,8 +91,8 @@ func (g *Gitlab) Configure(repo repository.RepoCommon, params core.BridgeParams) } func (g *Gitlab) ValidateConfig(conf core.Configuration) error { - if v, ok := conf[core.KeyTarget]; !ok { - return fmt.Errorf("missing %s key", core.KeyTarget) + if v, ok := conf[core.ConfigKeyTarget]; !ok { + return fmt.Errorf("missing %s key", core.ConfigKeyTarget) } else if v != target { return fmt.Errorf("unexpected target name: %v", v) } diff --git a/bridge/gitlab/export.go b/bridge/gitlab/export.go index 251d720a..44778b44 100644 --- a/bridge/gitlab/export.go +++ b/bridge/gitlab/export.go @@ -141,7 +141,7 @@ func (ge *gitlabExporter) exportBug(ctx context.Context, b *cache.BugCache, sinc // from Gitlab) and we do not have the token of the bug author, there is nothing we can do. // skip bug if origin is not allowed - origin, ok := snapshot.GetCreateMetadata(core.KeyOrigin) + origin, ok := snapshot.GetCreateMetadata(core.MetaKeyOrigin) if ok && origin != target { out <- core.NewExportNothing(b.Id(), fmt.Sprintf("issue tagged with origin: %s", origin)) return @@ -152,9 +152,9 @@ func (ge *gitlabExporter) exportBug(ctx context.Context, b *cache.BugCache, sinc author := snapshot.Author // get gitlab bug ID - gitlabID, ok := snapshot.GetCreateMetadata(keyGitlabId) + gitlabID, ok := snapshot.GetCreateMetadata(metaKeyGitlabId) if ok { - projectID, ok := snapshot.GetCreateMetadata(keyGitlabProject) + projectID, ok := snapshot.GetCreateMetadata(metaKeyGitlabProject) if !ok { err := fmt.Errorf("expected to find gitlab project id") out <- core.NewExportError(err, b.Id()) @@ -199,9 +199,9 @@ func (ge *gitlabExporter) exportBug(ctx context.Context, b *cache.BugCache, sinc _, err = b.SetMetadata( createOp.Id(), map[string]string{ - keyGitlabId: idString, - keyGitlabUrl: url, - keyGitlabProject: ge.repositoryID, + metaKeyGitlabId: idString, + metaKeyGitlabUrl: url, + metaKeyGitlabProject: ge.repositoryID, }, ) if err != nil { @@ -235,7 +235,7 @@ func (ge *gitlabExporter) exportBug(ctx context.Context, b *cache.BugCache, sinc // ignore operations already existing in gitlab (due to import or export) // cache the ID of already exported or imported issues and events from Gitlab - if id, ok := op.GetMetadata(keyGitlabId); ok { + if id, ok := op.GetMetadata(metaKeyGitlabId); ok { ge.cachedOperationIDs[op.Id().String()] = id out <- core.NewExportNothing(op.Id(), "already exported operation") continue @@ -378,8 +378,8 @@ func markOperationAsExported(b *cache.BugCache, target entity.Id, gitlabID, gitl _, err := b.SetMetadata( target, map[string]string{ - keyGitlabId: gitlabID, - keyGitlabUrl: gitlabURL, + metaKeyGitlabId: gitlabID, + metaKeyGitlabUrl: gitlabURL, }, ) diff --git a/bridge/gitlab/export_test.go b/bridge/gitlab/export_test.go index 3d3f406f..26b47bfb 100644 --- a/bridge/gitlab/export_test.go +++ b/bridge/gitlab/export_test.go @@ -236,27 +236,27 @@ func TestPushPull(t *testing.T) { for _, op := range tt.bug.Snapshot().Operations { // Check if the originals operations (*not* SetMetadata) are tagged properly if _, ok := op.(*bug.SetMetadataOperation); !ok { - _, haveIDMetadata := op.GetMetadata(keyGitlabId) + _, haveIDMetadata := op.GetMetadata(metaKeyGitlabId) require.True(t, haveIDMetadata) - _, haveURLMetada := op.GetMetadata(keyGitlabUrl) + _, haveURLMetada := op.GetMetadata(metaKeyGitlabUrl) require.True(t, haveURLMetada) } } // get bug gitlab ID - bugGitlabID, ok := tt.bug.Snapshot().GetCreateMetadata(keyGitlabId) + bugGitlabID, ok := tt.bug.Snapshot().GetCreateMetadata(metaKeyGitlabId) require.True(t, ok) // retrieve bug from backendTwo - importedBug, err := backendTwo.ResolveBugCreateMetadata(keyGitlabId, bugGitlabID) + importedBug, err := backendTwo.ResolveBugCreateMetadata(metaKeyGitlabId, bugGitlabID) require.NoError(t, err) // verify bug have same number of original operations require.Len(t, importedBug.Snapshot().Operations, tt.numOpImp) // verify bugs are taged with origin=gitlab - issueOrigin, ok := importedBug.Snapshot().GetCreateMetadata(core.KeyOrigin) + issueOrigin, ok := importedBug.Snapshot().GetCreateMetadata(core.MetaKeyOrigin) require.True(t, ok) require.Equal(t, issueOrigin, target) diff --git a/bridge/gitlab/gitlab.go b/bridge/gitlab/gitlab.go index 05721bfe..d976d813 100644 --- a/bridge/gitlab/gitlab.go +++ b/bridge/gitlab/gitlab.go @@ -12,10 +12,10 @@ import ( const ( target = "gitlab" - keyGitlabId = "gitlab-id" - keyGitlabUrl = "gitlab-url" - keyGitlabLogin = "gitlab-login" - keyGitlabProject = "gitlab-project-id" + metaKeyGitlabId = "gitlab-id" + metaKeyGitlabUrl = "gitlab-url" + metaKeyGitlabLogin = "gitlab-login" + metaKeyGitlabProject = "gitlab-project-id" keyProjectID = "project-id" keyToken = "token" diff --git a/bridge/gitlab/import.go b/bridge/gitlab/import.go index e2015773..e92067af 100644 --- a/bridge/gitlab/import.go +++ b/bridge/gitlab/import.go @@ -97,7 +97,7 @@ func (gi *gitlabImporter) ensureIssue(repo *cache.RepoCache, issue *gitlab.Issue } // resolve bug - b, err := repo.ResolveBugCreateMetadata(keyGitlabUrl, issue.WebURL) + b, err := repo.ResolveBugCreateMetadata(metaKeyGitlabUrl, issue.WebURL) if err == nil { gi.out <- core.NewImportNothing("", "bug already imported") return b, nil @@ -120,10 +120,10 @@ func (gi *gitlabImporter) ensureIssue(repo *cache.RepoCache, issue *gitlab.Issue cleanText, nil, map[string]string{ - core.KeyOrigin: target, - keyGitlabId: parseID(issue.IID), - keyGitlabUrl: issue.WebURL, - keyGitlabProject: gi.conf[keyProjectID], + core.MetaKeyOrigin: target, + metaKeyGitlabId: parseID(issue.IID), + metaKeyGitlabUrl: issue.WebURL, + metaKeyGitlabProject: gi.conf[keyProjectID], }, ) @@ -140,7 +140,7 @@ func (gi *gitlabImporter) ensureIssue(repo *cache.RepoCache, issue *gitlab.Issue func (gi *gitlabImporter) ensureNote(repo *cache.RepoCache, b *cache.BugCache, note *gitlab.Note) error { gitlabID := parseID(note.ID) - id, errResolve := b.ResolveOperationWithMetadata(keyGitlabId, gitlabID) + id, errResolve := b.ResolveOperationWithMetadata(metaKeyGitlabId, gitlabID) if errResolve != nil && errResolve != cache.ErrNoMatchingOp { return errResolve } @@ -162,7 +162,7 @@ func (gi *gitlabImporter) ensureNote(repo *cache.RepoCache, b *cache.BugCache, n author, note.CreatedAt.Unix(), map[string]string{ - keyGitlabId: gitlabID, + metaKeyGitlabId: gitlabID, }, ) if err != nil { @@ -180,7 +180,7 @@ func (gi *gitlabImporter) ensureNote(repo *cache.RepoCache, b *cache.BugCache, n author, note.CreatedAt.Unix(), map[string]string{ - keyGitlabId: gitlabID, + metaKeyGitlabId: gitlabID, }, ) if err != nil { @@ -204,7 +204,7 @@ func (gi *gitlabImporter) ensureNote(repo *cache.RepoCache, b *cache.BugCache, n firstComment.Id(), issue.Description, map[string]string{ - keyGitlabId: gitlabID, + metaKeyGitlabId: gitlabID, }, ) if err != nil { @@ -230,7 +230,7 @@ func (gi *gitlabImporter) ensureNote(repo *cache.RepoCache, b *cache.BugCache, n cleanText, nil, map[string]string{ - keyGitlabId: gitlabID, + metaKeyGitlabId: gitlabID, }, ) if err != nil { @@ -278,7 +278,7 @@ func (gi *gitlabImporter) ensureNote(repo *cache.RepoCache, b *cache.BugCache, n note.CreatedAt.Unix(), body, map[string]string{ - keyGitlabId: gitlabID, + metaKeyGitlabId: gitlabID, }, ) if err != nil { @@ -311,7 +311,7 @@ func (gi *gitlabImporter) ensureNote(repo *cache.RepoCache, b *cache.BugCache, n } func (gi *gitlabImporter) ensureLabelEvent(repo *cache.RepoCache, b *cache.BugCache, labelEvent *gitlab.LabelEvent) error { - _, err := b.ResolveOperationWithMetadata(keyGitlabId, parseID(labelEvent.ID)) + _, err := b.ResolveOperationWithMetadata(metaKeyGitlabId, parseID(labelEvent.ID)) if err != cache.ErrNoMatchingOp { return err } @@ -330,7 +330,7 @@ func (gi *gitlabImporter) ensureLabelEvent(repo *cache.RepoCache, b *cache.BugCa []string{labelEvent.Label.Name}, nil, map[string]string{ - keyGitlabId: parseID(labelEvent.ID), + metaKeyGitlabId: parseID(labelEvent.ID), }, ) @@ -341,7 +341,7 @@ func (gi *gitlabImporter) ensureLabelEvent(repo *cache.RepoCache, b *cache.BugCa nil, []string{labelEvent.Label.Name}, map[string]string{ - keyGitlabId: parseID(labelEvent.ID), + metaKeyGitlabId: parseID(labelEvent.ID), }, ) @@ -354,7 +354,7 @@ func (gi *gitlabImporter) ensureLabelEvent(repo *cache.RepoCache, b *cache.BugCa func (gi *gitlabImporter) ensurePerson(repo *cache.RepoCache, id int) (*cache.IdentityCache, error) { // Look first in the cache - i, err := repo.ResolveIdentityImmutableMetadata(keyGitlabId, strconv.Itoa(id)) + i, err := repo.ResolveIdentityImmutableMetadata(metaKeyGitlabId, strconv.Itoa(id)) if err == nil { return i, nil } @@ -376,8 +376,8 @@ func (gi *gitlabImporter) ensurePerson(repo *cache.RepoCache, id int) (*cache.Id user.AvatarURL, map[string]string{ // because Gitlab - keyGitlabId: strconv.Itoa(id), - keyGitlabLogin: user.Username, + metaKeyGitlabId: strconv.Itoa(id), + metaKeyGitlabLogin: user.Username, }, ) if err != nil { diff --git a/bridge/gitlab/import_test.go b/bridge/gitlab/import_test.go index a6fd8524..8e596349 100644 --- a/bridge/gitlab/import_test.go +++ b/bridge/gitlab/import_test.go @@ -116,7 +116,7 @@ func TestImport(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - b, err := backend.ResolveBugCreateMetadata(keyGitlabUrl, tt.url) + b, err := backend.ResolveBugCreateMetadata(metaKeyGitlabUrl, tt.url) require.NoError(t, err) ops := b.Snapshot().Operations diff --git a/bridge/launchpad/config.go b/bridge/launchpad/config.go index 6669d0fa..be81c0ac 100644 --- a/bridge/launchpad/config.go +++ b/bridge/launchpad/config.go @@ -62,7 +62,7 @@ func (l *Launchpad) Configure(repo repository.RepoCommon, params core.BridgePara } conf[keyProject] = project - conf[core.KeyTarget] = target + conf[core.ConfigKeyTarget] = target err = l.ValidateConfig(conf) if err != nil { @@ -77,8 +77,8 @@ func (*Launchpad) ValidateConfig(conf core.Configuration) error { return fmt.Errorf("missing %s key", keyProject) } - if _, ok := conf[core.KeyTarget]; !ok { - return fmt.Errorf("missing %s key", core.KeyTarget) + if _, ok := conf[core.ConfigKeyTarget]; !ok { + return fmt.Errorf("missing %s key", core.ConfigKeyTarget) } return nil diff --git a/bridge/launchpad/import.go b/bridge/launchpad/import.go index 7f50d898..178945b6 100644 --- a/bridge/launchpad/import.go +++ b/bridge/launchpad/import.go @@ -20,12 +20,14 @@ func (li *launchpadImporter) Init(conf core.Configuration) error { return nil } -const keyLaunchpadID = "launchpad-id" -const keyLaunchpadLogin = "launchpad-login" +const ( + metaKeyLaunchpadID = "launchpad-id" + metaKeyLaunchpadLogin = "launchpad-login" +) func (li *launchpadImporter) ensurePerson(repo *cache.RepoCache, owner LPPerson) (*cache.IdentityCache, error) { // Look first in the cache - i, err := repo.ResolveIdentityImmutableMetadata(keyLaunchpadLogin, owner.Login) + i, err := repo.ResolveIdentityImmutableMetadata(metaKeyLaunchpadLogin, owner.Login) if err == nil { return i, nil } @@ -39,7 +41,7 @@ func (li *launchpadImporter) ensurePerson(repo *cache.RepoCache, owner LPPerson) owner.Login, "", map[string]string{ - keyLaunchpadLogin: owner.Login, + metaKeyLaunchpadLogin: owner.Login, }, ) } @@ -65,7 +67,7 @@ func (li *launchpadImporter) ImportAll(ctx context.Context, repo *cache.RepoCach return default: lpBugID := fmt.Sprintf("%d", lpBug.ID) - b, err := repo.ResolveBugCreateMetadata(keyLaunchpadID, lpBugID) + b, err := repo.ResolveBugCreateMetadata(metaKeyLaunchpadID, lpBugID) if err != nil && err != bug.ErrBugNotExist { out <- core.NewImportError(err, entity.Id(lpBugID)) return @@ -86,7 +88,8 @@ func (li *launchpadImporter) ImportAll(ctx context.Context, repo *cache.RepoCach lpBug.Description, nil, map[string]string{ - keyLaunchpadID: lpBugID, + core.MetaKeyOrigin: target, + metaKeyLaunchpadID: lpBugID, }, ) if err != nil { @@ -108,7 +111,7 @@ func (li *launchpadImporter) ImportAll(ctx context.Context, repo *cache.RepoCach // The Launchpad API returns the bug description as the first // comment, so skip it. for _, lpMessage := range lpBug.Messages[1:] { - _, err := b.ResolveOperationWithMetadata(keyLaunchpadID, lpMessage.ID) + _, err := b.ResolveOperationWithMetadata(metaKeyLaunchpadID, lpMessage.ID) if err != nil && err != cache.ErrNoMatchingOp { out <- core.NewImportError(err, entity.Id(lpMessage.ID)) return @@ -136,7 +139,7 @@ func (li *launchpadImporter) ImportAll(ctx context.Context, repo *cache.RepoCach lpMessage.Content, nil, map[string]string{ - keyLaunchpadID: lpMessage.ID, + metaKeyLaunchpadID: lpMessage.ID, }) if err != nil { out <- core.NewImportError(err, op.Id()) @@ -160,7 +160,7 @@ func readBug(repo repository.ClockedRepo, ref string) (*Bug, error) { rootFound = true } if strings.HasPrefix(entry.Name, createClockEntryPrefix) { - n, err := fmt.Sscanf(string(entry.Name), createClockEntryPattern, &createTime) + n, err := fmt.Sscanf(entry.Name, createClockEntryPattern, &createTime) if err != nil { return nil, errors.Wrap(err, "can't read create lamport time") } @@ -169,7 +169,7 @@ func readBug(repo repository.ClockedRepo, ref string) (*Bug, error) { } } if strings.HasPrefix(entry.Name, editClockEntryPrefix) { - n, err := fmt.Sscanf(string(entry.Name), editClockEntryPattern, &editTime) + n, err := fmt.Sscanf(entry.Name, editClockEntryPattern, &editTime) if err != nil { return nil, errors.Wrap(err, "can't read edit lamport time") } @@ -197,10 +197,10 @@ func readBug(repo repository.ClockedRepo, ref string) (*Bug, error) { } // Update the clocks - if err := repo.CreateWitness(bug.createTime); err != nil { + if err := repo.WitnessCreate(bug.createTime); err != nil { return nil, errors.Wrap(err, "failed to update create lamport clock") } - if err := repo.EditWitness(bug.editTime); err != nil { + if err := repo.WitnessEdit(bug.editTime); err != nil { return nil, errors.Wrap(err, "failed to update edit lamport clock") } @@ -330,12 +330,18 @@ func (bug *Bug) Validate() error { } // Check that there is no more CreateOp op + // Check that there is no colliding operation's ID it := NewOperationIterator(bug) createCount := 0 + ids := make(map[entity.Id]struct{}) for it.Next() { if it.Value().base().OperationType == CreateOp { createCount++ } + if _, ok := ids[it.Value().Id()]; ok { + return fmt.Errorf("id collision: %s", it.Value().Id()) + } + ids[it.Value().Id()] = struct{}{} } if createCount != 1 { @@ -350,11 +356,6 @@ func (bug *Bug) Append(op Operation) { bug.staging.Append(op) } -// HasPendingOp tell if the bug need to be committed -func (bug *Bug) HasPendingOp() bool { - return !bug.staging.IsEmpty() -} - // Commit write the staging area in Git and move the operations to the packs func (bug *Bug) Commit(repo repository.ClockedRepo) error { @@ -592,6 +593,8 @@ func (bug *Bug) Merge(repo repository.Repo, other Interface) (bool, error) { bug.lastCommit = hash } + bug.packs = newPacks + // Update the git ref err = repo.UpdateRef(bugsRefPattern+bug.id.String(), bug.lastCommit) if err != nil { diff --git a/bug/bug_actions_test.go b/bug/bug_actions_test.go index 4bc58aea..38dddce2 100644 --- a/bug/bug_actions_test.go +++ b/bug/bug_actions_test.go @@ -4,6 +4,7 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/MichaelMure/git-bug/identity" @@ -18,8 +19,10 @@ func TestPushPull(t *testing.T) { bug1, _, err := Create(reneA, time.Now().Unix(), "bug1", "message") require.NoError(t, err) + assert.True(t, bug1.NeedCommit()) err = bug1.Commit(repoA) require.NoError(t, err) + assert.False(t, bug1.NeedCommit()) // distribute the identity _, err = identity.Push(repoA, "origin") @@ -91,8 +94,10 @@ func _RebaseTheirs(t testing.TB) { bug1, _, err := Create(reneA, time.Now().Unix(), "bug1", "message") require.NoError(t, err) + assert.True(t, bug1.NeedCommit()) err = bug1.Commit(repoA) require.NoError(t, err) + assert.False(t, bug1.NeedCommit()) // distribute the identity _, err = identity.Push(repoA, "origin") @@ -111,18 +116,21 @@ func _RebaseTheirs(t testing.TB) { bug2, err := ReadLocalBug(repoB, bug1.Id()) require.NoError(t, err) + assert.False(t, bug2.NeedCommit()) reneB, err := identity.ReadLocal(repoA, reneA.Id()) require.NoError(t, err) _, err = AddComment(bug2, reneB, time.Now().Unix(), "message2") require.NoError(t, err) + assert.True(t, bug2.NeedCommit()) _, err = AddComment(bug2, reneB, time.Now().Unix(), "message3") require.NoError(t, err) _, err = AddComment(bug2, reneB, time.Now().Unix(), "message4") require.NoError(t, err) err = bug2.Commit(repoB) require.NoError(t, err) + assert.False(t, bug2.NeedCommit()) // B --> remote _, err = Push(repoB, "origin") diff --git a/bug/bug_test.go b/bug/bug_test.go index 4e8a9440..480d312e 100644 --- a/bug/bug_test.go +++ b/bug/bug_test.go @@ -73,13 +73,14 @@ func TestBugCommitLoad(t *testing.T) { bug1.Append(createOp) bug1.Append(setTitleOp) - bug1.Append(setTitleOp) - bug1.Append(addCommentOp) repo := repository.NewMockRepoForTest() + assert.True(t, bug1.NeedCommit()) + err := bug1.Commit(repo) assert.Nil(t, err) + assert.False(t, bug1.NeedCommit()) bug2, err := ReadLocalBug(repo, bug1.Id()) assert.NoError(t, err) @@ -87,11 +88,13 @@ func TestBugCommitLoad(t *testing.T) { // add more op - bug1.Append(setTitleOp) bug1.Append(addCommentOp) + assert.True(t, bug1.NeedCommit()) + err = bug1.Commit(repo) assert.Nil(t, err) + assert.False(t, bug1.NeedCommit()) bug3, err := ReadLocalBug(repo, bug1.Id()) assert.NoError(t, err) diff --git a/bug/clocks.go b/bug/clocks.go index bb3d81f0..52d23544 100644 --- a/bug/clocks.go +++ b/bug/clocks.go @@ -12,12 +12,12 @@ func Witnesser(repo repository.ClockedRepo) error { return b.Err } - err := repo.CreateWitness(b.Bug.createTime) + err := repo.WitnessCreate(b.Bug.createTime) if err != nil { return err } - err = repo.EditWitness(b.Bug.editTime) + err = repo.WitnessEdit(b.Bug.editTime) if err != nil { return err } diff --git a/bug/interface.go b/bug/interface.go index 8266e99e..796ee569 100644 --- a/bug/interface.go +++ b/bug/interface.go @@ -16,8 +16,8 @@ type Interface interface { // Append an operation into the staging area, to be committed later Append(op Operation) - // Append an operation into the staging area, to be committed later - HasPendingOp() bool + // Indicate that the in-memory state changed and need to be commit in the repository + NeedCommit() bool // Commit write the staging area in Git and move the operations to the packs Commit(repo repository.ClockedRepo) error diff --git a/bug/op_set_metadata.go b/bug/op_set_metadata.go index f99f836b..67f7e009 100644 --- a/bug/op_set_metadata.go +++ b/bug/op_set_metadata.go @@ -34,6 +34,8 @@ func (op *SetMetadataOperation) Apply(snapshot *Snapshot) { base.extraMetadata = make(map[string]string) } + // Apply the metadata in an immutable way: if a metadata already + // exist, it's not possible to override it. for key, val := range op.NewMetadata { if _, exist := base.extraMetadata[key]; !exist { base.extraMetadata[key] = val diff --git a/bug/operation_iterator_test.go b/bug/operation_iterator_test.go index b922bec1..fcc61d0f 100644 --- a/bug/operation_iterator_test.go +++ b/bug/operation_iterator_test.go @@ -1,12 +1,14 @@ package bug import ( - "github.com/MichaelMure/git-bug/identity" - "github.com/MichaelMure/git-bug/repository" - "github.com/stretchr/testify/assert" - + "fmt" "testing" "time" + + "github.com/stretchr/testify/assert" + + "github.com/MichaelMure/git-bug/identity" + "github.com/MichaelMure/git-bug/repository" ) func ExampleOperationIterator() { @@ -29,16 +31,20 @@ func TestOpIterator(t *testing.T) { unix := time.Now().Unix() createOp := NewCreateOp(rene, unix, "title", "message", nil) - setTitleOp := NewSetTitleOp(rene, unix, "title2", "title1") addCommentOp := NewAddCommentOp(rene, unix, "message2", nil) setStatusOp := NewSetStatusOp(rene, unix, ClosedStatus) labelChangeOp := NewLabelChangeOperation(rene, unix, []Label{"added"}, []Label{"removed"}) + var i int + genTitleOp := func() Operation { + i++ + return NewSetTitleOp(rene, unix, fmt.Sprintf("title%d", i), "") + } + bug1 := NewBug() // first pack bug1.Append(createOp) - bug1.Append(setTitleOp) bug1.Append(addCommentOp) bug1.Append(setStatusOp) bug1.Append(labelChangeOp) @@ -46,16 +52,16 @@ func TestOpIterator(t *testing.T) { assert.NoError(t, err) // second pack - bug1.Append(setTitleOp) - bug1.Append(setTitleOp) - bug1.Append(setTitleOp) + bug1.Append(genTitleOp()) + bug1.Append(genTitleOp()) + bug1.Append(genTitleOp()) err = bug1.Commit(mockRepo) assert.NoError(t, err) // staging - bug1.Append(setTitleOp) - bug1.Append(setTitleOp) - bug1.Append(setTitleOp) + bug1.Append(genTitleOp()) + bug1.Append(genTitleOp()) + bug1.Append(genTitleOp()) it := NewOperationIterator(bug1) @@ -65,7 +71,5 @@ func TestOpIterator(t *testing.T) { counter++ } - if counter != 11 { - t.Fatalf("Wrong count of value iterated (%d instead of 8)", counter) - } + assert.Equal(t, 10, counter) } diff --git a/commands/bridge_configure.go b/commands/bridge_configure.go index 12cc35e3..3562af17 100644 --- a/commands/bridge_configure.go +++ b/commands/bridge_configure.go @@ -94,8 +94,14 @@ func promptTarget() (string, error) { } func promptName(repo repository.RepoCommon) (string, error) { + defaultExist := core.BridgeExist(repo, defaultName) + for { - fmt.Printf("name [%s]: ", defaultName) + if defaultExist { + fmt.Printf("name: ") + } else { + fmt.Printf("name [%s]: ", defaultName) + } line, err := bufio.NewReader(os.Stdin).ReadString('\n') if err != nil { @@ -105,6 +111,10 @@ func promptName(repo repository.RepoCommon) (string, error) { line = strings.TrimRight(line, "\n") name := line + if defaultExist && name == "" { + continue + } + if name == "" { name = defaultName } diff --git a/misc/random_bugs/create_random_bugs.go b/misc/random_bugs/create_random_bugs.go index ea8833ee..b5c19e63 100644 --- a/misc/random_bugs/create_random_bugs.go +++ b/misc/random_bugs/create_random_bugs.go @@ -11,7 +11,7 @@ import ( "github.com/icrowley/fake" ) -type opsGenerator func(bug.Interface, identity.Interface) +type opsGenerator func(bug.Interface, identity.Interface, int64) type Options struct { BugNumber int @@ -61,6 +61,12 @@ func generateRandomBugsWithSeed(opts Options, seed int64) []*bug.Bug { rand.Seed(seed) fake.Seed(seed) + // At the moment git-bug has a risk of hash collision is simple + // operation (like open/close) are made with the same timestamp. + // As a temporary workaround, we use here an strictly increasing + // timestamp + timestamp := time.Now().Unix() + opsGenerators := []opsGenerator{ comment, comment, @@ -94,7 +100,8 @@ func generateRandomBugsWithSeed(opts Options, seed int64) []*bug.Bug { for j := 0; j < nOps; j++ { index := rand.Intn(len(opsGenerators)) - opsGenerators[index](b, randomPerson()) + opsGenerators[index](b, randomPerson(), timestamp) + timestamp++ } result[i] = b @@ -177,25 +184,25 @@ func paragraphs() string { return strings.Replace(p, "\t", "\n\n", -1) } -func comment(b bug.Interface, p identity.Interface) { - _, _ = bug.AddComment(b, p, time.Now().Unix(), paragraphs()) +func comment(b bug.Interface, p identity.Interface, timestamp int64) { + _, _ = bug.AddComment(b, p, timestamp, paragraphs()) } -func title(b bug.Interface, p identity.Interface) { - _, _ = bug.SetTitle(b, p, time.Now().Unix(), fake.Sentence()) +func title(b bug.Interface, p identity.Interface, timestamp int64) { + _, _ = bug.SetTitle(b, p, timestamp, fake.Sentence()) } -func open(b bug.Interface, p identity.Interface) { - _, _ = bug.Open(b, p, time.Now().Unix()) +func open(b bug.Interface, p identity.Interface, timestamp int64) { + _, _ = bug.Open(b, p, timestamp) } -func close(b bug.Interface, p identity.Interface) { - _, _ = bug.Close(b, p, time.Now().Unix()) +func close(b bug.Interface, p identity.Interface, timestamp int64) { + _, _ = bug.Close(b, p, timestamp) } var addedLabels []string -func labels(b bug.Interface, p identity.Interface) { +func labels(b bug.Interface, p identity.Interface, timestamp int64) { var removed []string nbRemoved := rand.Intn(3) for nbRemoved > 0 && len(addedLabels) > 0 { @@ -217,5 +224,5 @@ func labels(b bug.Interface, p identity.Interface) { // ignore error // if the randomisation produce no changes, no op // is added to the bug - _, _, _ = bug.ChangeLabels(b, p, time.Now().Unix(), added, removed) + _, _, _ = bug.ChangeLabels(b, p, timestamp, added, removed) } diff --git a/repository/git.go b/repository/git.go index 2c72fccd..d4560805 100644 --- a/repository/git.go +++ b/repository/git.go @@ -461,14 +461,14 @@ func (repo *GitRepo) EditTimeIncrement() (lamport.Time, error) { return repo.editClock.Increment() } -// CreateWitness witness another create time and increment the corresponding clock +// WitnessCreate witness another create time and increment the corresponding clock // if needed. -func (repo *GitRepo) CreateWitness(time lamport.Time) error { +func (repo *GitRepo) WitnessCreate(time lamport.Time) error { return repo.createClock.Witness(time) } -// EditWitness witness another edition time and increment the corresponding clock +// WitnessEdit witness another edition time and increment the corresponding clock // if needed. -func (repo *GitRepo) EditWitness(time lamport.Time) error { +func (repo *GitRepo) WitnessEdit(time lamport.Time) error { return repo.editClock.Witness(time) } diff --git a/repository/mock_repo.go b/repository/mock_repo.go index 26c02ede..88c5a132 100644 --- a/repository/mock_repo.go +++ b/repository/mock_repo.go @@ -236,12 +236,12 @@ func (r *mockRepoForTest) EditTimeIncrement() (lamport.Time, error) { return r.editClock.Increment(), nil } -func (r *mockRepoForTest) CreateWitness(time lamport.Time) error { +func (r *mockRepoForTest) WitnessCreate(time lamport.Time) error { r.createClock.Witness(time) return nil } -func (r *mockRepoForTest) EditWitness(time lamport.Time) error { +func (r *mockRepoForTest) WitnessEdit(time lamport.Time) error { r.editClock.Witness(time) return nil } diff --git a/repository/repo.go b/repository/repo.go index e8c67a5e..71bd7a8e 100644 --- a/repository/repo.go +++ b/repository/repo.go @@ -111,13 +111,13 @@ type ClockedRepo interface { // EditTimeIncrement increment the edit clock and return the new value. EditTimeIncrement() (lamport.Time, error) - // CreateWitness witness another create time and increment the corresponding + // WitnessCreate witness another create time and increment the corresponding // clock if needed. - CreateWitness(time lamport.Time) error + WitnessCreate(time lamport.Time) error - // EditWitness witness another edition time and increment the corresponding + // WitnessEdit witness another edition time and increment the corresponding // clock if needed. - EditWitness(time lamport.Time) error + WitnessEdit(time lamport.Time) error } // Witnesser is a function that will initialize the clocks of a repo |