aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/revlist
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-07-19 14:15:34 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2017-07-19 14:15:34 +0200
commitd851b90f5e832fa1edeb0d408bd56ed6c1fd5e7a (patch)
treeab25942ff243173a27979bc357d6bc516dda65d1 /plumbing/revlist
parent95bfc7e1c1b7101f2cd605cda58c1fb43d501d35 (diff)
downloadgo-git-d851b90f5e832fa1edeb0d408bd56ed6c1fd5e7a.tar.gz
repository: allow push from shallow repositories
Diffstat (limited to 'plumbing/revlist')
-rw-r--r--plumbing/revlist/revlist.go39
1 files changed, 19 insertions, 20 deletions
diff --git a/plumbing/revlist/revlist.go b/plumbing/revlist/revlist.go
index 20bc99d..1bda2fa 100644
--- a/plumbing/revlist/revlist.go
+++ b/plumbing/revlist/revlist.go
@@ -16,11 +16,7 @@ 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 []plumbing.Hash,
- ignore []plumbing.Hash) ([]plumbing.Hash, error) {
-
+func Objects(s storer.EncodedObjectStorer, objects, ignore []plumbing.Hash) ([]plumbing.Hash, error) {
seen := hashListToSet(ignore)
result := make(map[plumbing.Hash]bool)
@@ -32,7 +28,7 @@ func Objects(
}
for _, h := range objects {
- if err := processObject(s, h, seen, walkerFunc); err != nil {
+ if err := processObject(s, h, seen, ignore, walkerFunc); err != nil {
return nil, err
}
}
@@ -45,6 +41,7 @@ func processObject(
s storer.EncodedObjectStorer,
h plumbing.Hash,
seen map[plumbing.Hash]bool,
+ ignore []plumbing.Hash,
walkerFunc func(h plumbing.Hash),
) error {
o, err := s.EncodedObject(plumbing.AnyObject, h)
@@ -59,12 +56,12 @@ func processObject(
switch do := do.(type) {
case *object.Commit:
- return reachableObjects(do, seen, walkerFunc)
+ return reachableObjects(do, seen, ignore, walkerFunc)
case *object.Tree:
return iterateCommitTrees(seen, do, walkerFunc)
case *object.Tag:
walkerFunc(do.Hash)
- return processObject(s, do.Target, seen, walkerFunc)
+ return processObject(s, do.Target, seen, ignore, walkerFunc)
case *object.Blob:
walkerFunc(do.Hash)
default:
@@ -82,22 +79,24 @@ func processObject(
func reachableObjects(
commit *object.Commit,
seen map[plumbing.Hash]bool,
+ ignore []plumbing.Hash,
cb func(h plumbing.Hash)) error {
- return object.NewCommitPreorderIter(commit).
- ForEach(func(commit *object.Commit) error {
- if seen[commit.Hash] {
- return nil
- }
- cb(commit.Hash)
+ i := object.NewCommitPreorderIter(commit, ignore)
+ return i.ForEach(func(commit *object.Commit) error {
+ if seen[commit.Hash] {
+ return nil
+ }
+
+ cb(commit.Hash)
- tree, err := commit.Tree()
- if err != nil {
- return err
- }
+ tree, err := commit.Tree()
+ if err != nil {
+ return err
+ }
- return iterateCommitTrees(seen, tree, cb)
- })
+ return iterateCommitTrees(seen, tree, cb)
+ })
}
// iterateCommitTrees iterate all reachable trees from the given commit