mirror of
https://github.com/restic/restic.git
synced 2025-12-12 08:31:51 +00:00
repository: deduplicate index progress bar initializaton
This commit is contained in:
@@ -93,11 +93,16 @@ func computePackTypes(ctx context.Context, idx restic.ListBlobser) (map[restic.I
|
||||
}
|
||||
|
||||
// LoadIndex loads all index files.
|
||||
func (c *Checker) LoadIndex(ctx context.Context, p *progress.Counter) (hints []error, errs []error) {
|
||||
func (c *Checker) LoadIndex(ctx context.Context, p restic.TerminalCounterFactory) (hints []error, errs []error) {
|
||||
debug.Log("Start")
|
||||
|
||||
var bar *progress.Counter
|
||||
if p != nil {
|
||||
bar = p.NewCounterTerminalOnly("index files loaded")
|
||||
}
|
||||
|
||||
packToIndex := make(map[restic.ID]restic.IDSet)
|
||||
err := c.masterIndex.Load(ctx, c.repo, p, func(id restic.ID, idx *index.Index, err error) error {
|
||||
err := c.masterIndex.Load(ctx, c.repo, bar, func(id restic.ID, idx *index.Index, err error) error {
|
||||
debug.Log("process index %v, err %v", id, err)
|
||||
err = errors.Wrapf(err, "error loading index %v", id)
|
||||
|
||||
|
||||
@@ -639,13 +639,18 @@ func (r *Repository) clearIndex() {
|
||||
}
|
||||
|
||||
// LoadIndex loads all index files from the backend in parallel and stores them
|
||||
func (r *Repository) LoadIndex(ctx context.Context, p *progress.Counter) error {
|
||||
func (r *Repository) LoadIndex(ctx context.Context, p restic.TerminalCounterFactory) error {
|
||||
debug.Log("Loading index")
|
||||
|
||||
// reset in-memory index before loading it from the repository
|
||||
r.clearIndex()
|
||||
|
||||
err := r.idx.Load(ctx, r, p, nil)
|
||||
var bar *progress.Counter
|
||||
if p != nil {
|
||||
bar = p.NewCounterTerminalOnly("index files loaded")
|
||||
}
|
||||
|
||||
err := r.idx.Load(ctx, r, bar, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ type Repository interface {
|
||||
Config() Config
|
||||
Key() *crypto.Key
|
||||
|
||||
LoadIndex(ctx context.Context, p *progress.Counter) error
|
||||
LoadIndex(ctx context.Context, p TerminalCounterFactory) error
|
||||
SetIndex(mi MasterIndex) error
|
||||
|
||||
LookupBlob(t BlobType, id ID) []PackedBlob
|
||||
@@ -131,6 +131,12 @@ type PackBlobs struct {
|
||||
Blobs []Blob
|
||||
}
|
||||
|
||||
type TerminalCounterFactory interface {
|
||||
// NewCounterTerminalOnly returns a new progress counter that is only shown if stdout points to a
|
||||
// terminal. It is not shown if --quiet or --json is specified.
|
||||
NewCounterTerminalOnly(description string) *progress.Counter
|
||||
}
|
||||
|
||||
// MasterIndex keeps track of the blobs are stored within files.
|
||||
type MasterIndex interface {
|
||||
Has(bh BlobHandle) bool
|
||||
|
||||
@@ -76,7 +76,3 @@ func NewProgressPrinter(json bool, verbosity uint, term Terminal) progress.Print
|
||||
show: verbosity > 0,
|
||||
}
|
||||
}
|
||||
|
||||
func NewIndexCounter(printer progress.Printer) *progress.Counter {
|
||||
return printer.NewCounterTerminalOnly("index files loaded")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user