aboutsummaryrefslogtreecommitdiffstats
path: root/cache/repo_cache.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2023-01-10 21:36:03 +0100
committerMichael Muré <batolettre@gmail.com>2023-01-11 14:31:22 +0100
commit7df34aa7a40be0d7b759ea3ef42cedf9f25f32b2 (patch)
treea3d1cc77f56814d4ec8838f18cb6768035c1b290 /cache/repo_cache.go
parent9c50a359704f4edd2f33df6d256e032feae3a576 (diff)
downloadgit-bug-7df34aa7a40be0d7b759ea3ef42cedf9f25f32b2.tar.gz
commands: add a nice terminal progress bar when building the cache
One issue remaining is that writing the cache takes significant time, but I don't know how to reflect that nicely to the user.
Diffstat (limited to 'cache/repo_cache.go')
-rw-r--r--cache/repo_cache.go27
1 files changed, 11 insertions, 16 deletions
diff --git a/cache/repo_cache.go b/cache/repo_cache.go
index 99e9abbd..9c7e945a 100644
--- a/cache/repo_cache.go
+++ b/cache/repo_cache.go
@@ -30,7 +30,7 @@ var _ repository.RepoKeyring = &RepoCache{}
type cacheMgmt interface {
Typename() string
Load() error
- Build() error
+ Build() <-chan BuildEvent
SetCacheSize(size int)
MergeAll(remote string) <-chan entity.MergeResult
GetNamespace() string
@@ -212,6 +212,7 @@ const (
BuildEventCacheIsBuilt
BuildEventRemoveLock
BuildEventStarted
+ BuildEventProgress
BuildEventFinished
)
@@ -223,6 +224,10 @@ type BuildEvent struct {
Typename string
// Event is the type of the event.
Event BuildEventType
+ // Total is the total number of element being built. Set if Event is BuildEventStarted.
+ Total int64
+ // Progress is the current count of processed element. Set if Event is BuildEventProgress.
+ Progress int64
}
func (c *RepoCache) buildCache(events chan BuildEvent) {
@@ -233,23 +238,13 @@ func (c *RepoCache) buildCache(events chan BuildEvent) {
wg.Add(1)
go func(subcache cacheMgmt) {
defer wg.Done()
- events <- BuildEvent{
- Typename: subcache.Typename(),
- Event: BuildEventStarted,
- }
- err := subcache.Build()
- if err != nil {
- events <- BuildEvent{
- Typename: subcache.Typename(),
- Err: err,
+ buildEvents := subcache.Build()
+ for buildEvent := range buildEvents {
+ events <- buildEvent
+ if buildEvent.Err != nil {
+ return
}
- return
- }
-
- events <- BuildEvent{
- Typename: subcache.Typename(),
- Event: BuildEventFinished,
}
}(subcache)
}