Skip to content

Commit 0bfd616

Browse files
committed
DfsPackFileMidx: Move implementation to subclass
We expect to have midxs covering a single pack (GC) in the midx chain. With the current implementation, this would load twice the same information, in the midx and in the pack indexes. As a first step, move the DfsPackFileMidx implementation to a subclass, so later we can add the single-pack implementation. We keep DfsPackFileMidx as the superclass with a factory method, as it reads better for callers; they invoke "DfsPackFileMidx.create" and get the right instance. Change-Id: I2ee77a28db35f152a6124c19af91c0906a6a6964
1 parent cf4feed commit 0bfd616

3 files changed

Lines changed: 590 additions & 430 deletions

File tree

org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsPackFileMidxTest.java renamed to org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsPackFileMidxNPacksTest.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@
3636
import java.util.zip.Deflater;
3737

3838
import org.eclipse.jgit.annotations.Nullable;
39+
import org.eclipse.jgit.internal.storage.dfs.DfsPackFileMidx.DfsPackOffset;
3940
import org.eclipse.jgit.internal.storage.dfs.DfsPackFileMidx.VOffsetCalculator;
41+
import org.eclipse.jgit.internal.storage.dfs.DfsPackFileMidxNPacks.VOffsetCalculatorNPacks;
4042
import org.eclipse.jgit.internal.storage.file.PackBitmapIndex;
4143
import org.eclipse.jgit.internal.storage.file.PackIndex;
4244
import org.eclipse.jgit.internal.storage.midx.MultiPackIndex.PackOffset;
@@ -61,7 +63,7 @@
6163
import org.junit.Before;
6264
import org.junit.Test;
6365

64-
public class DfsPackFileMidxTest {
66+
public class DfsPackFileMidxNPacksTest {
6567

6668
private static final ObjectId NOT_IN_PACK = ObjectId
6769
.fromString("3f306cb3fcd5116919fecad615524bd6e6ea4ba7");
@@ -315,7 +317,7 @@ public void midx_findOffset() throws IOException {
315317

316318
try (DfsReader ctx = db.getObjectDatabase().newReader()) {
317319
long posOne = midx.findOffset(ctx, o1);
318-
DfsPackFileMidx.DfsPackOffset po = midx.getOffsetCalculator()
320+
DfsPackOffset po = midx.getOffsetCalculator()
319321
.decode(posOne);
320322
assertEquals(12, po.getPackOffset());
321323
assertEquals(packThreeSize + packTwoSize, po.getPackStart());
@@ -980,7 +982,7 @@ public void voffsetcalculator_encode() {
980982
DfsPackFile two = createDfsPackFile(1200);
981983
DfsPackFile three = createDfsPackFile(900);
982984

983-
VOffsetCalculator calc = VOffsetCalculator
985+
VOffsetCalculatorNPacks calc = VOffsetCalculatorNPacks
984986
.fromPacks(new DfsPackFile[] { one, two, three }, null);
985987

986988
PackOffset po = PackOffset.create(0, 12);
@@ -997,11 +999,11 @@ public void voffsetcalculator_decode() {
997999
DfsPackFile two = createDfsPackFile(1200);
9981000
DfsPackFile three = createDfsPackFile(900);
9991001

1000-
VOffsetCalculator calc = VOffsetCalculator
1002+
VOffsetCalculator calc = VOffsetCalculatorNPacks
10011003
.fromPacks(new DfsPackFile[] { one, two, three }, null);
10021004

10031005
// In first pack
1004-
DfsPackFileMidx.DfsPackOffset decoded = calc.decode(130);
1006+
DfsPackOffset decoded = calc.decode(130);
10051007
assertEquals(one.getPackDescription(),
10061008
decoded.getPack().getPackDescription());
10071009
assertEquals(130, decoded.getPackOffset());
@@ -1028,7 +1030,7 @@ public void voffsetcalculator_notFound() {
10281030
DfsPackFile two = createDfsPackFile(1200);
10291031
DfsPackFile three = createDfsPackFile(900);
10301032

1031-
VOffsetCalculator calc = VOffsetCalculator
1033+
VOffsetCalculatorNPacks calc = VOffsetCalculatorNPacks
10321034
.fromPacks(new DfsPackFile[] { one, two, three }, null);
10331035

10341036
assertEquals(-1, calc.encode(null));
@@ -1045,7 +1047,7 @@ public void voffsetcalculator_maxOffset() {
10451047
+ two.getPackDescription().getFileSize(PACK)
10461048
+ three.getPackDescription().getFileSize(PACK);
10471049

1048-
VOffsetCalculator calc = VOffsetCalculator
1050+
VOffsetCalculator calc = VOffsetCalculatorNPacks
10491051
.fromPacks(new DfsPackFile[] { one, two, three }, null);
10501052

10511053
assertEquals(totalSize, calc.getMaxOffset());
@@ -1057,14 +1059,14 @@ public void voffsetcalculator_withBase_encode() {
10571059
DfsPackFile two = createDfsPackFile(1200);
10581060
DfsPackFile three = createDfsPackFile(900);
10591061

1060-
VOffsetCalculator baseCalc = VOffsetCalculator
1062+
VOffsetCalculator baseCalc = VOffsetCalculatorNPacks
10611063
.fromPacks(new DfsPackFile[] { one, two, three }, null);
10621064

10631065
DfsPackFile four = createDfsPackFile(900);
10641066
DfsPackFile five = createDfsPackFile(1300);
10651067
DfsPackFile six = createDfsPackFile(1000);
10661068

1067-
VOffsetCalculator calc = VOffsetCalculator
1069+
VOffsetCalculatorNPacks calc = VOffsetCalculatorNPacks
10681070
.fromPacks(new DfsPackFile[] { four, five, six }, baseCalc);
10691071

10701072
// These packIds are now from the second top midx
@@ -1082,18 +1084,18 @@ public void voffsetcalculator_withBase_decode() {
10821084
DfsPackFile one = createDfsPackFile(800);
10831085
DfsPackFile two = createDfsPackFile(1200);
10841086
DfsPackFile three = createDfsPackFile(900);
1085-
VOffsetCalculator baseCalc = VOffsetCalculator
1087+
VOffsetCalculator baseCalc = VOffsetCalculatorNPacks
10861088
.fromPacks(new DfsPackFile[] { one, two, three }, null);
10871089

10881090
DfsPackFile four = createDfsPackFile(900);
10891091
DfsPackFile five = createDfsPackFile(1300);
10901092
DfsPackFile six = createDfsPackFile(1000);
10911093

1092-
VOffsetCalculator calc = VOffsetCalculator
1094+
VOffsetCalculator calc = VOffsetCalculatorNPacks
10931095
.fromPacks(new DfsPackFile[] { four, five, six }, baseCalc);
10941096

10951097
// In pack 1
1096-
DfsPackFileMidx.DfsPackOffset decoded = calc.decode(130);
1098+
DfsPackOffset decoded = calc.decode(130);
10971099
assertEquals(one.getPackDescription(),
10981100
decoded.getPack().getPackDescription());
10991101
assertEquals(130, decoded.getPackOffset());
@@ -1128,14 +1130,14 @@ public void voffsetcalculator_withBase_maxOffset() {
11281130
DfsPackFile two = createDfsPackFile(1200);
11291131
DfsPackFile three = createDfsPackFile(900);
11301132

1131-
VOffsetCalculator baseCalc = VOffsetCalculator
1133+
VOffsetCalculator baseCalc = VOffsetCalculatorNPacks
11321134
.fromPacks(new DfsPackFile[] { one, two, three }, null);
11331135

11341136
DfsPackFile four = createDfsPackFile(900);
11351137
DfsPackFile five = createDfsPackFile(1300);
11361138
DfsPackFile six = createDfsPackFile(1000);
11371139

1138-
VOffsetCalculator calc = VOffsetCalculator
1140+
VOffsetCalculator calc = VOffsetCalculatorNPacks
11391141
.fromPacks(new DfsPackFile[] { four, five, six }, baseCalc);
11401142

11411143
int expectedMaxOffset = 800 + 1200 + 900 + 900 + 1300 + 1000;

0 commit comments

Comments
 (0)