aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSantiago M. Mola <santi@mola.io>2017-07-27 14:05:17 +0200
committerSantiago M. Mola <santi@mola.io>2017-07-27 17:43:01 +0200
commita9c3fdc8d70e580173ef21f5c3def8eeca35dcd7 (patch)
tree710ce9a9420cc67787f3d5231d2aa1b6bd06692c
parent854ffa16f650706200a6ebb5505bb448b5c64035 (diff)
downloadgo-git-a9c3fdc8d70e580173ef21f5c3def8eeca35dcd7.tar.gz
revlist: ignore all objects reachable from ignored objects
Usually we call revlist.Objects ignoring a set of commits. This is not enough to ignore everything reachable from such set, so we first get all objects reachable from the ignored set and then walk the tree again ignoring that new set.
-rw-r--r--plumbing/revlist/revlist.go29
1 files changed, 28 insertions, 1 deletions
diff --git a/plumbing/revlist/revlist.go b/plumbing/revlist/revlist.go
index 1bda2fa..f56cf28 100644
--- a/plumbing/revlist/revlist.go
+++ b/plumbing/revlist/revlist.go
@@ -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)
@@ -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
}
}
@@ -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