Merge pull request #5075 from greatroar/idset

internal/restic: Use IDSet.Clone + use maps package
This commit is contained in:
Michael Eischer 2024-10-09 19:55:26 +00:00 committed by GitHub
commit 96c1c1a0fc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 11 additions and 27 deletions

View file

@ -347,6 +347,9 @@ func (mi *MasterIndex) Rewrite(ctx context.Context, repo restic.Unpacked, exclud
// copy excludePacks to prevent unintended sideeffects
excludePacks = excludePacks.Clone()
if excludePacks == nil {
excludePacks = restic.NewIDSet()
}
debug.Log("start rebuilding index of %d indexes, excludePacks: %v", len(indexes), excludePacks)
wg, wgCtx := errgroup.WithContext(ctx)

View file

@ -1,6 +1,9 @@
package restic
import "sort"
import (
"maps"
"sort"
)
// IDSet is a set of IDs.
type IDSet map[ID]struct{}
@ -44,28 +47,10 @@ func (s IDSet) List() IDs {
}
// Equals returns true iff s equals other.
func (s IDSet) Equals(other IDSet) bool {
if len(s) != len(other) {
return false
}
for id := range s {
if _, ok := other[id]; !ok {
return false
}
}
// length + one-way comparison is sufficient implication of equality
return true
}
func (s IDSet) Equals(other IDSet) bool { return maps.Equal(s, other) }
// Merge adds the blobs in other to the current set.
func (s IDSet) Merge(other IDSet) {
for id := range other {
s.Insert(id)
}
}
func (s IDSet) Merge(other IDSet) { maps.Copy(s, other) }
// Intersect returns a new set containing the IDs that are present in both sets.
func (s IDSet) Intersect(other IDSet) (result IDSet) {
@ -106,8 +91,4 @@ func (s IDSet) String() string {
return "{" + str[1:len(str)-1] + "}"
}
func (s IDSet) Clone() IDSet {
c := NewIDSet()
c.Merge(s)
return c
}
func (s IDSet) Clone() IDSet { return maps.Clone(s) }

View file

@ -187,7 +187,7 @@ func (l *Lock) checkForOtherLocks(ctx context.Context) error {
// Store updates in new IDSet to prevent data races
var m sync.Mutex
newCheckedIDs := NewIDSet(checkedIDs.List()...)
newCheckedIDs := checkedIDs.Clone()
err = ForAllLocks(ctx, l.repo, checkedIDs, func(id ID, lock *Lock, err error) error {
if err != nil {
// if we cannot load a lock then it is unclear whether it can be ignored