Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

revlist: ignore all objects reachable from ignored objects #516

Merged
merged 1 commit into from
Jul 28, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion plumbing/revlist/revlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,26 @@ import (
// the reachable objects from the given objects. Ignore param are object hashes
// that we want to ignore on the result. All that objects must be accessible
// from the object storer.
func Objects(s storer.EncodedObjectStorer, objects, ignore []plumbing.Hash) ([]plumbing.Hash, error) {
func Objects(
s storer.EncodedObjectStorer,
objs,
ignore []plumbing.Hash,
) ([]plumbing.Hash, error) {
ignore, err := objects(s, ignore, nil, true)
if err != nil {
return nil, err
}

return objects(s, objs, ignore, false)
}

func objects(
s storer.EncodedObjectStorer,
objects,
ignore []plumbing.Hash,
allowMissingObjects bool,
) ([]plumbing.Hash, error) {

seen := hashListToSet(ignore)
result := make(map[plumbing.Hash]bool)

Expand All @@ -29,6 +48,10 @@ func Objects(s storer.EncodedObjectStorer, objects, ignore []plumbing.Hash) ([]p

for _, h := range objects {
if err := processObject(s, h, seen, ignore, walkerFunc); err != nil {
if allowMissingObjects && err == plumbing.ErrObjectNotFound {
continue
}

return nil, err
}
}
Expand All @@ -44,6 +67,10 @@ func processObject(
ignore []plumbing.Hash,
walkerFunc func(h plumbing.Hash),
) error {
if seen[h] {
return nil
}

o, err := s.EncodedObject(plumbing.AnyObject, h)
if err != nil {
return err
Expand Down