@@ -16,7 +16,26 @@ import (
1616// the reachable objects from the given objects. Ignore param are object hashes
1717// that we want to ignore on the result. All that objects must be accessible
1818// from the object storer.
19- func Objects (s storer.EncodedObjectStorer , objects , ignore []plumbing.Hash ) ([]plumbing.Hash , error ) {
19+ func Objects (
20+ s storer.EncodedObjectStorer ,
21+ objs ,
22+ ignore []plumbing.Hash ,
23+ ) ([]plumbing.Hash , error ) {
24+ ignore , err := objects (s , ignore , nil , true )
25+ if err != nil {
26+ return nil , err
27+ }
28+
29+ return objects (s , objs , ignore , false )
30+ }
31+
32+ func objects (
33+ s storer.EncodedObjectStorer ,
34+ objects ,
35+ ignore []plumbing.Hash ,
36+ allowMissingObjects bool ,
37+ ) ([]plumbing.Hash , error ) {
38+
2039 seen := hashListToSet (ignore )
2140 result := make (map [plumbing.Hash ]bool )
2241
@@ -29,6 +48,10 @@ func Objects(s storer.EncodedObjectStorer, objects, ignore []plumbing.Hash) ([]p
2948
3049 for _ , h := range objects {
3150 if err := processObject (s , h , seen , ignore , walkerFunc ); err != nil {
51+ if allowMissingObjects && err == plumbing .ErrObjectNotFound {
52+ continue
53+ }
54+
3255 return nil , err
3356 }
3457 }
@@ -44,6 +67,10 @@ func processObject(
4467 ignore []plumbing.Hash ,
4568 walkerFunc func (h plumbing.Hash ),
4669) error {
70+ if seen [h ] {
71+ return nil
72+ }
73+
4774 o , err := s .EncodedObject (plumbing .AnyObject , h )
4875 if err != nil {
4976 return err
0 commit comments