diff options
| -rw-r--r-- | internal/testgit/repo_from_fixture.go | 1 | ||||
| -rw-r--r-- | reachability/reachability.go | 71 | ||||
| -rw-r--r-- | reachability/walk.go | 14 |
3 files changed, 44 insertions, 42 deletions
diff --git a/internal/testgit/repo_from_fixture.go b/internal/testgit/repo_from_fixture.go index 887bf9a3..4a022bc5 100644 --- a/internal/testgit/repo_from_fixture.go +++ b/internal/testgit/repo_from_fixture.go @@ -18,6 +18,7 @@ func NewRepoFromFixture(tb testing.TB, algo objectid.Algorithm, fixtureDir strin dst := tb.TempDir() srcFS := os.DirFS(fixtureDir) + err := copyFS(dst, srcFS) if err != nil { tb.Fatalf("copy fixture %q: %v", fixtureDir, err) diff --git a/reachability/reachability.go b/reachability/reachability.go index 9126ee84..29ac2a93 100644 --- a/reachability/reachability.go +++ b/reachability/reachability.go @@ -71,6 +71,42 @@ func (r *Reachability) IsAncestor(ancestor, descendant objectid.ObjectID) (bool, return false, nil } +// CheckConnected verifies that all objects reachable from wants (under the +// selected domain) can be fully traversed without missing-object/type/parse +// errors, excluding subgraphs rooted at haves. +// +// Even with commit-graph acceleration available, each visited commit is +// still validated against the object store. +func (r *Reachability) CheckConnected(domain Domain, haves, wants map[objectid.ObjectID]struct{}) error { + walk := r.Walk(domain, haves, wants) + + walk.strict = true + for range walk.Seq() { + } + + return walk.Err() +} + +// Walk creates one single-use traversal over the selected domain. +// +// In DomainCommits, when a commit-graph reader is attached, parent expansion +// may use commit-graph metadata for speed. +func (r *Reachability) Walk(domain Domain, haves, wants map[objectid.ObjectID]struct{}) *Walk { + walk := &Walk{ + reachability: r, + domain: domain, + haves: haves, + wants: wants, + } + + err := validateDomain(domain) + if err != nil { + walk.err = err + } + + return walk +} + func (r *Reachability) isAncestorGraph(ancestor, descendant objectid.ObjectID) (bool, bool, error) { if r.graph == nil { return false, false, nil @@ -141,38 +177,3 @@ func (r *Reachability) isAncestorGraph(ancestor, descendant objectid.ObjectID) ( return false, true, nil } - -// CheckConnected verifies that all objects reachable from wants (under the -// selected domain) can be fully traversed without missing-object/type/parse -// errors, excluding subgraphs rooted at haves. -// -// Even with commit-graph acceleration available, each visited commit is -// still validated against the object store. -func (r *Reachability) CheckConnected(domain Domain, haves, wants map[objectid.ObjectID]struct{}) error { - walk := r.Walk(domain, haves, wants) - walk.strict = true - for range walk.Seq() { - } - - return walk.Err() -} - -// Walk creates one single-use traversal over the selected domain. -// -// In DomainCommits, when a commit-graph reader is attached, parent expansion -// may use commit-graph metadata for speed. -func (r *Reachability) Walk(domain Domain, haves, wants map[objectid.ObjectID]struct{}) *Walk { - walk := &Walk{ - reachability: r, - domain: domain, - haves: haves, - wants: wants, - } - - err := validateDomain(domain) - if err != nil { - walk.err = err - } - - return walk -} diff --git a/reachability/walk.go b/reachability/walk.go index e96a8b44..4611e46e 100644 --- a/reachability/walk.go +++ b/reachability/walk.go @@ -111,20 +111,20 @@ func (walk *Walk) expand(item walkItem) ([]walkItem, error) { } func (walk *Walk) expandCommits(item walkItem) ([]walkItem, error) { - if walk.reachability.graph != nil { + if walk.reachability.graph != nil { //nolint:nestif next, graphUsed, err := walk.expandCommitsFromGraph(item.id) if err != nil { return nil, err } - if graphUsed { - if walk.strict { - err := walk.validateCommitObject(item.id) - if err != nil { - return nil, err - } + if graphUsed && walk.strict { + err = walk.validateCommitObject(item.id) + if err != nil { + return nil, err } + } + if graphUsed { return next, nil } } |
