Skip to content

Commit 86ae4bd

Browse files
committed
DfsPackFileMidx: Pass the right pack when building single-pack midx
While instantiating a single-pack midx, the code assumes that the incoming list of known packs has only the packs mentioned in the description and takes blindly the first pack in the list. This can pick the wrong pack because that list contains all known packs in the repo in no specific order. This was found out while making MidxTestUtils work with midx as input to build another midx. It needs to take plain packs instead of whatever was given to the midx and that new list doesn't necessarily have the expected pack first. Lookup the pack by pack name before passing it to the DfsPackFileSinglePack instance. Change-Id: I144f15dcaa860367093a141f29152dce6a6a6964
1 parent db7dcf9 commit 86ae4bd

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

org.eclipse.jgit.test/src/org/eclipse/jgit/internal/storage/dfs/MidxTestUtils.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,12 @@ static DfsPackFileMidx writeMultipackIndex(DfsRepository db,
150150
Arrays.asList(packs),
151151
base != null ? base.getPackDescription() : null, packConfig);
152152
db.getObjectDatabase().commitPack(List.of(desc), null);
153+
154+
// "packs" argument can have a midx and its base in the list.
155+
List<DfsPackFile> allPlainPacks = MidxPackList
156+
.create(db.getObjectDatabase().getPacks()).getAllPlainPacks();
153157
return DfsPackFileMidx.create(DfsBlockCache.getInstance(), desc,
154-
Arrays.asList(packs), base);
158+
allPlainPacks, base);
155159
}
156160

157161
record CommitObjects(RevCommit commit, RevTree tree, RevBlob blob) {

org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFileMidx.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ public static DfsPackFileMidx create(DfsBlockCache cache,
5757
DfsPackDescription desc, List<DfsPackFile> requiredPacks,
5858
@Nullable DfsPackFileMidx base) {
5959
if (desc.getCoveredPacks().size() == 1) {
60-
return new DfsPackFileMidxSingle(cache, desc, requiredPacks.get(0),
60+
String coveredPackName = desc.getCoveredPacks().get(0)
61+
.getPackName();
62+
DfsPackFile coveredPack = requiredPacks.stream().filter(p -> p
63+
.getPackDescription().getPackName().equals(coveredPackName))
64+
.findFirst().orElseThrow();
65+
return new DfsPackFileMidxSingle(cache, desc, coveredPack,
6166
base);
6267
}
6368
return new DfsPackFileMidxNPacks(cache, desc, requiredPacks, base);

0 commit comments

Comments
 (0)