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

Commit efe6c8b

Browse files
committed
revlist: add ObjectsWithStorageForIgnores method
`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>
1 parent dcc9f37 commit efe6c8b

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

plumbing/revlist/revlist.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,20 @@ func Objects(
2121
objs,
2222
ignore []plumbing.Hash,
2323
) ([]plumbing.Hash, error) {
24-
ignore, err := objects(s, ignore, nil, true)
24+
return ObjectsWithStorageForIgnores(s, s, objs, ignore)
25+
}
26+
27+
// ObjectsWithStorageForIgnores is the same as Objects, but a
28+
// secondary storage layer can be provided, to be used to finding the
29+
// full set of objects to be ignored while finding the reachable
30+
// objects. This is useful when the main `s` storage layer is slow
31+
// and/or remote, while the ignore list is available somewhere local.
32+
func ObjectsWithStorageForIgnores(
33+
s, ignoreStore storer.EncodedObjectStorer,
34+
objs,
35+
ignore []plumbing.Hash,
36+
) ([]plumbing.Hash, error) {
37+
ignore, err := objects(ignoreStore, ignore, nil, true)
2538
if err != nil {
2639
return nil, err
2740
}
@@ -114,7 +127,6 @@ func reachableObjects(
114127
i := object.NewCommitPreorderIter(commit, seen, ignore)
115128
pending := make(map[plumbing.Hash]bool)
116129
addPendingParents(pending, visited, commit)
117-
118130
for {
119131
commit, err := i.Next()
120132
if err == io.EOF {

plumbing/revlist/revlist_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,32 @@ func (s *RevListSuite) TestRevListObjectsTagObject(c *C) {
129129
c.Assert(len(hist), Equals, len(expected))
130130
}
131131

132+
func (s *RevListSuite) TestRevListObjectsWithStorageForIgnores(c *C) {
133+
sto := filesystem.NewStorage(
134+
fixtures.ByTag("merge-conflict").One().DotGit(),
135+
cache.NewObjectLRUDefault())
136+
137+
// The "merge-conflict" repo has one extra commit in it, with a
138+
// two files modified in two different subdirs.
139+
expected := map[string]bool{
140+
"1980fcf55330d9d94c34abee5ab734afecf96aba": true, // commit
141+
"73d9cf44e9045254346c73f6646b08f9302c8570": true, // root dir
142+
"e8435d512a98586bd2e4fcfcdf04101b0bb1b500": true, // go/
143+
"257cc5642cb1a054f08cc83f2d943e56fd3ebe99": true, // haskal.hs
144+
"d499a1a0b79b7d87a35155afd0c1cce78b37a91c": true, // example.go
145+
"d108adc364fb6f21395d011ae2c8a11d96905b0d": true, // haskal/
146+
}
147+
148+
hist, err := ObjectsWithStorageForIgnores(sto, s.Storer, []plumbing.Hash{plumbing.NewHash("1980fcf55330d9d94c34abee5ab734afecf96aba")}, []plumbing.Hash{plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5")})
149+
c.Assert(err, IsNil)
150+
151+
for _, h := range hist {
152+
c.Assert(expected[h.String()], Equals, true)
153+
}
154+
155+
c.Assert(len(hist), Equals, len(expected))
156+
}
157+
132158
// ---
133159
// | |\
134160
// | | * b8e471f Creating changelog

0 commit comments

Comments
 (0)