mirror of
https://github.com/restic/restic.git
synced 2026-06-27 11:04:17 +00:00
restic: speed up repository config initialization in tests
Avoid redundant polynomial generation, which takes a millisecond or so.
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user