Skip to content

Commit 1b212f5

Browse files
committed
Correctly pass down smaller selection
1 parent 30ed8d4 commit 1b212f5

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

paperweight-core/src/main/kotlin/io/papermc/paperweight/core/tasks/patchroulette/PatchRouletteApply.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ abstract class PatchRouletteApply : AbstractPatchRouletteTask() {
168168
sealed interface PatchSelectionStrategy {
169169
data class NumericInPackage(val count: Int, val enforceCount: Boolean = false) : PatchSelectionStrategy {
170170
override fun select(config: Config, available: List<Path>): Pair<Config, List<Path>> {
171+
return this.select(config, available, this.count)
172+
}
173+
174+
fun select(config: Config, available: List<Path>, count: Int): Pair<Config, List<Path>> {
171175
if (config.suggestedPackage != null) {
172176
val possiblePatches = available.filter { it.parent.equals(config.suggestedPackage) }.take(count)
173177
if (possiblePatches.isNotEmpty()) {
@@ -180,14 +184,15 @@ abstract class PatchRouletteApply : AbstractPatchRouletteTask() {
180184
// config, as the last suggested package is the one to suggest in potentially next runs.
181185
val additionalPatches = select(
182186
config.copy(suggestedPackage = null),
183-
available.filter { !possiblePatches.contains(it) }
187+
available.filter { !possiblePatches.contains(it) },
188+
count - possiblePatches.size
184189
)
185190

186191
return additionalPatches.first to possiblePatches + additionalPatches.second
187192
}
188193
}
189194

190-
return select(config.copy(suggestedPackage = available.first().parent), available)
195+
return select(config.copy(suggestedPackage = available.first().parent), available, count)
191196
}
192197
}
193198

paperweight-core/src/test/kotlin/io/papermc/paperweight/core/tasks/patchroulette/PatchRouletteApplyTest.kt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,29 @@ class PatchRouletteApplyTest {
115115
),
116116
)
117117
),
118+
Arguments.of(
119+
PatchRouletteApply.PatchSelectionStrategy.NumericInPackage(4, true),
120+
listOf(
121+
"io/papermc/paper/block/Block.java",
122+
"io/papermc/paper/block/BlockData.java",
123+
"io/papermc/paper/block/BlockState.java",
124+
"io/papermc/paper/entity/Entity.java",
125+
"io/papermc/paper/entity/Entity2.java",
126+
"io/papermc/paper/entity/Entity3.java"
127+
),
128+
listOf(
129+
listOf(
130+
"io/papermc/paper/block/Block.java",
131+
"io/papermc/paper/block/BlockData.java",
132+
"io/papermc/paper/block/BlockState.java",
133+
"io/papermc/paper/entity/Entity.java",
134+
),
135+
listOf(
136+
"io/papermc/paper/entity/Entity2.java",
137+
"io/papermc/paper/entity/Entity3.java"
138+
)
139+
)
140+
)
118141
)
119142

120143
fun mockAvailablePatches() = listOf(

0 commit comments

Comments
 (0)