diff options
author | Michael Muré <batolettre@gmail.com> | 2018-09-08 14:17:08 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2018-09-08 14:17:08 +0200 |
commit | 6d7e79a277fe6f3d137fc76588599c965fa5b2ee (patch) | |
tree | 7a392b6a12041fa8a1178980ba181c9ed5f5313c /cache/repo_cache.go | |
parent | 61a1173ec3f202b9dc71236205de785e2a454791 (diff) | |
download | git-bug-6d7e79a277fe6f3d137fc76588599c965fa5b2ee.tar.gz |
cache: refactor to handle bug changes during Pull
Diffstat (limited to 'cache/repo_cache.go')
-rw-r--r-- | cache/repo_cache.go | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/cache/repo_cache.go b/cache/repo_cache.go index a187b43c..2f565935 100644 --- a/cache/repo_cache.go +++ b/cache/repo_cache.go @@ -261,9 +261,43 @@ func (c *RepoCache) Fetch(remote string) (string, error) { return bug.Fetch(c.repo, remote) } +// MergeAll will merge all the available remote bug func (c *RepoCache) MergeAll(remote string) <-chan bug.MergeResult { - // Todo: update the cache properly - return bug.MergeAll(c.repo, remote) + out := make(chan bug.MergeResult) + + // Intercept merge results to update the cache properly + go func() { + defer close(out) + + results := bug.MergeAll(c.repo, remote) + for result := range results { + if result.Err != nil { + continue + } + + id := result.Id + + switch result.Status { + case bug.MsgMergeNew, bug.MsgMergeUpdated: + b := result.Bug + snap := b.Compile() + c.excerpts[id] = NewBugExcerpt(b, &snap) + + default: + } + + out <- result + } + + err := c.writeExcerpts() + + // No easy way out here .. + if err != nil { + panic(err) + } + }() + + return out } // Push update a remote with the local changes |