diff options
author | Michael Muré <michael.mure@consensys.net> | 2019-03-27 21:44:11 +0100 |
---|---|---|
committer | Michael Muré <michael.mure@consensys.net> | 2019-03-27 21:44:11 +0100 |
commit | 24d6714dd59a5c385c21991caa47e5727de043d0 (patch) | |
tree | 154306261bf98b599e1f3465940bb46c290b8c72 /cache/repo_cache.go | |
parent | d27e3849b826309bdf2dbf6f30f2a8ac9db71649 (diff) | |
download | git-bug-24d6714dd59a5c385c21991caa47e5727de043d0.tar.gz |
cache: properly push/pull identities and bugs
Diffstat (limited to 'cache/repo_cache.go')
-rw-r--r-- | cache/repo_cache.go | 60 |
1 files changed, 46 insertions, 14 deletions
diff --git a/cache/repo_cache.go b/cache/repo_cache.go index bec733e3..fce473f4 100644 --- a/cache/repo_cache.go +++ b/cache/repo_cache.go @@ -14,6 +14,7 @@ import ( "time" "github.com/MichaelMure/git-bug/bug" + "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/identity" "github.com/MichaelMure/git-bug/repository" "github.com/MichaelMure/git-bug/util/git" @@ -593,23 +594,31 @@ func (c *RepoCache) NewBugRaw(author *IdentityCache, unixTime int64, title strin return cached, nil } -// Fetch retrieve update from a remote -// This does not change the local bugs state +// Fetch retrieve updates from a remote +// This does not change the local bugs or identities state func (c *RepoCache) Fetch(remote string) (string, error) { - return bug.Fetch(c.repo, remote) -} + stdout1, err := identity.Fetch(c.repo, remote) + if err != nil { + return stdout1, err + } + + stdout2, err := bug.Fetch(c.repo, remote) + if err != nil { + return stdout2, err + } -// MergeAll will merge all the available remote bug -func (c *RepoCache) MergeAll(remote string) <-chan bug.MergeResult { - // TODO: add identities + return stdout1 + stdout2, nil +} - out := make(chan bug.MergeResult) +// MergeAll will merge all the available remote bug and identities +func (c *RepoCache) MergeAll(remote string) <-chan entity.MergeResult { + out := make(chan entity.MergeResult) // Intercept merge results to update the cache properly go func() { defer close(out) - results := bug.MergeAll(c.repo, remote) + results := identity.MergeAll(c.repo, remote) for result := range results { out <- result @@ -617,13 +626,26 @@ func (c *RepoCache) MergeAll(remote string) <-chan bug.MergeResult { continue } - id := result.Id + switch result.Status { + case entity.MergeStatusNew, entity.MergeStatusUpdated: + i := result.Entity.(*identity.Identity) + c.identitiesExcerpts[result.Id] = NewIdentityExcerpt(i) + } + } + + results = bug.MergeAll(c.repo, remote) + for result := range results { + out <- result + + if result.Err != nil { + continue + } switch result.Status { - case bug.MergeStatusNew, bug.MergeStatusUpdated: - b := result.Bug + case entity.MergeStatusNew, entity.MergeStatusUpdated: + b := result.Entity.(*bug.Bug) snap := b.Compile() - c.bugExcerpts[id] = NewBugExcerpt(b, &snap) + c.bugExcerpts[result.Id] = NewBugExcerpt(b, &snap) } } @@ -640,7 +662,17 @@ func (c *RepoCache) MergeAll(remote string) <-chan bug.MergeResult { // Push update a remote with the local changes func (c *RepoCache) Push(remote string) (string, error) { - return bug.Push(c.repo, remote) + stdout1, err := identity.Push(c.repo, remote) + if err != nil { + return stdout1, err + } + + stdout2, err := bug.Push(c.repo, remote) + if err != nil { + return stdout2, err + } + + return stdout1 + stdout2, nil } func repoLockFilePath(repo repository.Repo) string { |