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

Commit

Permalink
revlist: add ObjectsWithStorageForIgnores method
Browse files Browse the repository at this point in the history
`ObjectsWithStorageForIgnores` is the same as `Objects`, but a
secondary storage layer can be provided, to be used to finding the
full set of objects to be ignored while finding the reachable objects.
This is useful when the main `s` storage layer is slow and/or remote,
while the ignore list is available somewhere local.

Issue: #909
Signed-off-by: Jeremy Stribling <strib@alum.mit.edu>
  • Loading branch information
strib committed Feb 11, 2019
1 parent dcc9f37 commit efe6c8b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
16 changes: 14 additions & 2 deletions plumbing/revlist/revlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,20 @@ func Objects(
objs,
ignore []plumbing.Hash,
) ([]plumbing.Hash, error) {
ignore, err := objects(s, ignore, nil, true)
return ObjectsWithStorageForIgnores(s, s, objs, ignore)
}

// ObjectsWithStorageForIgnores is the same as Objects, but a
// secondary storage layer can be provided, to be used to finding the
// full set of objects to be ignored while finding the reachable
// objects. This is useful when the main `s` storage layer is slow
// and/or remote, while the ignore list is available somewhere local.
func ObjectsWithStorageForIgnores(
s, ignoreStore storer.EncodedObjectStorer,
objs,
ignore []plumbing.Hash,
) ([]plumbing.Hash, error) {
ignore, err := objects(ignoreStore, ignore, nil, true)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -114,7 +127,6 @@ func reachableObjects(
i := object.NewCommitPreorderIter(commit, seen, ignore)
pending := make(map[plumbing.Hash]bool)
addPendingParents(pending, visited, commit)

for {
commit, err := i.Next()
if err == io.EOF {
Expand Down
26 changes: 26 additions & 0 deletions plumbing/revlist/revlist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,32 @@ func (s *RevListSuite) TestRevListObjectsTagObject(c *C) {
c.Assert(len(hist), Equals, len(expected))
}

func (s *RevListSuite) TestRevListObjectsWithStorageForIgnores(c *C) {
sto := filesystem.NewStorage(
fixtures.ByTag("merge-conflict").One().DotGit(),
cache.NewObjectLRUDefault())

// The "merge-conflict" repo has one extra commit in it, with a
// two files modified in two different subdirs.
expected := map[string]bool{
"1980fcf55330d9d94c34abee5ab734afecf96aba": true, // commit
"73d9cf44e9045254346c73f6646b08f9302c8570": true, // root dir
"e8435d512a98586bd2e4fcfcdf04101b0bb1b500": true, // go/
"257cc5642cb1a054f08cc83f2d943e56fd3ebe99": true, // haskal.hs
"d499a1a0b79b7d87a35155afd0c1cce78b37a91c": true, // example.go
"d108adc364fb6f21395d011ae2c8a11d96905b0d": true, // haskal/
}

hist, err := ObjectsWithStorageForIgnores(sto, s.Storer, []plumbing.Hash{plumbing.NewHash("1980fcf55330d9d94c34abee5ab734afecf96aba")}, []plumbing.Hash{plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5")})
c.Assert(err, IsNil)

for _, h := range hist {
c.Assert(expected[h.String()], Equals, true)
}

c.Assert(len(hist), Equals, len(expected))
}

// ---
// | |\
// | | * b8e471f Creating changelog
Expand Down

0 comments on commit efe6c8b

Please sign in to comment.