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

Commit e4a931c

Browse files
authored
Merge pull request #516 from smola/revlist-perf
revlist: ignore all objects reachable from ignored objects
2 parents 86f33ed + a9c3fdc commit e4a931c

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

plumbing/revlist/revlist.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)