From 1174e97b309e37a33a2850cfc25fef1ad95b6e8f Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sun, 14 Jun 2026 21:38:09 +0200 Subject: [PATCH] restic: speed up repository config initialization in tests Avoid redundant polynomial generation, which takes a millisecond or so. --- internal/repository/repository.go | 5 +---- internal/restic/config.go | 12 ++++++++---- internal/restic/config_test.go | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/internal/repository/repository.go b/internal/repository/repository.go index 35f5c78f5..889c76049 100644 --- a/internal/repository/repository.go +++ b/internal/repository/repository.go @@ -919,13 +919,10 @@ func (r *Repository) Init(ctx context.Context, version uint, password string, ch return err } - cfg, err := restic.CreateConfig(version) + cfg, err := restic.CreateConfig(version, chunkerPolynomial) if err != nil { return err } - if chunkerPolynomial != nil { - cfg.ChunkerPolynomial = *chunkerPolynomial - } return r.init(ctx, password, cfg) } diff --git a/internal/restic/config.go b/internal/restic/config.go index 8af09c908..4c6c97a08 100644 --- a/internal/restic/config.go +++ b/internal/restic/config.go @@ -28,15 +28,19 @@ const StableRepoVersion = 2 // CreateConfig creates a config file with a randomly selected polynomial and // ID. -func CreateConfig(version uint) (Config, error) { +func CreateConfig(version uint, pol *chunker.Pol) (Config, error) { var ( err error cfg Config ) - cfg.ChunkerPolynomial, err = chunker.RandomPolynomial() - if err != nil { - return Config{}, errors.Wrap(err, "chunker.RandomPolynomial") + if pol == nil { + cfg.ChunkerPolynomial, err = chunker.RandomPolynomial() + if err != nil { + return Config{}, errors.Wrap(err, "chunker.RandomPolynomial") + } + } else { + cfg.ChunkerPolynomial = *pol } cfg.ID = NewRandomID().String() diff --git a/internal/restic/config_test.go b/internal/restic/config_test.go index 5a7f6b0ae..54d3db2fc 100644 --- a/internal/restic/config_test.go +++ b/internal/restic/config_test.go @@ -43,7 +43,7 @@ func TestConfig(t *testing.T) { return restic.ID{}, nil } - cfg1, err := restic.CreateConfig(restic.MaxRepoVersion) + cfg1, err := restic.CreateConfig(restic.MaxRepoVersion, nil) rtest.OK(t, err) err = restic.SaveConfig(context.TODO(), saver{save}, cfg1)