@@ -213,7 +213,6 @@ public void jgit_resolve() throws IOException {
213213 MultiPackIndex midx = MultiPackIndexLoader
214214 .read (new ByteArrayInputStream (out .toByteArray ()));
215215
216-
217216 Set <ObjectId > results = new HashSet <>();
218217 midx .resolve (results , abbrev , 100 );
219218
@@ -257,7 +256,6 @@ public void jgit_resolve_matchLimit() throws IOException {
257256 MultiPackIndex midx = MultiPackIndexLoader
258257 .read (new ByteArrayInputStream (out .toByteArray ()));
259258
260-
261259 Set <ObjectId > results = new HashSet <>();
262260 midx .resolve (results , abbrev , 2 );
263261
@@ -273,8 +271,7 @@ public void jgit_resolve_noMatches() throws IOException {
273271 AbbreviatedObjectId abbrev = AbbreviatedObjectId
274272 .fromString ("4400000000" );
275273
276- PackIndex idxOne = indexWith (
277- "0000000000000000000000000000000000000001" ,
274+ PackIndex idxOne = indexWith ("0000000000000000000000000000000000000001" ,
278275 "3000000000000000000000000000000000000005" ,
279276 "32fe829a1b000000000000000000000000000001" ,
280277 "32fe829a1c000000000000000000000000000001" ,
@@ -315,13 +312,67 @@ public void jgit_resolve_empty() throws IOException {
315312 MultiPackIndex midx = MultiPackIndexLoader
316313 .read (new ByteArrayInputStream (out .toByteArray ()));
317314
318-
319315 Set <ObjectId > results = new HashSet <>();
320316 midx .resolve (results , abbrev , 200 );
321317
322318 assertEquals (0 , results .size ());
323319 }
324320
321+ @ Test
322+ public void jgit_findPosition () throws IOException {
323+ PackIndex idxOne = FakeIndexFactory .indexOf (List .of (
324+ new FakeIndexFactory .IndexObject (
325+ "0000000000000000000000000000000000000001" , 500 ),
326+ new FakeIndexFactory .IndexObject (
327+ "0000000000000000000000000000000000000005" , 12 ),
328+ new FakeIndexFactory .IndexObject (
329+ "0000000000000000000000000000000000000010" , 1500 )));
330+ PackIndex idxTwo = FakeIndexFactory .indexOf (List .of (
331+ new FakeIndexFactory .IndexObject (
332+ "0000000000000000000000000000000000000002" , 501 ),
333+ new FakeIndexFactory .IndexObject (
334+ "0000000000000000000000000000000000000003" , 13 ),
335+ new FakeIndexFactory .IndexObject (
336+ "0000000000000000000000000000000000000015" , 1501 )));
337+ PackIndex idxThree = FakeIndexFactory .indexOf (List .of (
338+ new FakeIndexFactory .IndexObject (
339+ "0000000000000000000000000000000000000004" , 502 ),
340+ new FakeIndexFactory .IndexObject (
341+ "0000000000000000000000000000000000000007" , 14 ),
342+ new FakeIndexFactory .IndexObject (
343+ "0000000000000000000000000000000000000012" , 1502 )));
344+
345+ Map <String , PackIndex > packs = Map .of ("p1" , idxOne , "p2" , idxTwo , "p3" ,
346+ idxThree );
347+ MultiPackIndexWriter writer = new MultiPackIndexWriter ();
348+ ByteArrayOutputStream out = new ByteArrayOutputStream ();
349+ writer .write (NullProgressMonitor .INSTANCE , out , packs );
350+
351+ MultiPackIndex midx = MultiPackIndexLoader
352+ .read (new ByteArrayInputStream (out .toByteArray ()));
353+ assertEquals (3 , midx .getPackNames ().length );
354+ assertEquals (0 , midx .findPosition (ObjectId
355+ .fromString ("0000000000000000000000000000000000000001" )));
356+ assertEquals (1 , midx .findPosition (ObjectId
357+ .fromString ("0000000000000000000000000000000000000002" )));
358+ assertEquals (2 , midx .findPosition (ObjectId
359+ .fromString ("0000000000000000000000000000000000000003" )));
360+ assertEquals (3 , midx .findPosition (ObjectId
361+ .fromString ("0000000000000000000000000000000000000004" )));
362+ assertEquals (4 , midx .findPosition (ObjectId
363+ .fromString ("0000000000000000000000000000000000000005" )));
364+ assertEquals (5 , midx .findPosition (ObjectId
365+ .fromString ("0000000000000000000000000000000000000007" )));
366+ assertEquals (6 , midx .findPosition (ObjectId
367+ .fromString ("0000000000000000000000000000000000000010" )));
368+ assertEquals (7 , midx .findPosition (ObjectId
369+ .fromString ("0000000000000000000000000000000000000012" )));
370+ assertEquals (8 , midx .findPosition (ObjectId
371+ .fromString ("0000000000000000000000000000000000000015" )));
372+
373+ assertNull (midx .find (ObjectId .zeroId ()));
374+ }
375+
325376 private static PackIndex indexWith (String ... oids ) {
326377 List <FakeIndexFactory .IndexObject > idxObjs = new ArrayList <>(
327378 oids .length );
0 commit comments