Skip to content

Commit bbb1a63

Browse files
committed
fix: format patches input
Previously you could not use the original patches names because they were formatted but not the input
1 parent f7fcbc5 commit bbb1a63

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/main/kotlin/app/revanced/cli/command/PatchCommand.kt

+17-9
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,20 @@ internal object PatchCommand : Runnable {
232232
* @return The filtered patches.
233233
*/
234234
private fun Patcher.filterPatchSelection(patches: PatchList) = buildList {
235+
// TODO: Remove this eventually because
236+
// patches named "patch-name" and "patch name" will conflict.
237+
fun String.format() = lowercase().replace(" ", "-")
238+
239+
val formattedExcludedPatches = excludedPatches.map { it.format() }
240+
val formattedIncludedPatches = includedPatches.map { it.format() }
241+
235242
val packageName = context.packageMetadata.packageName
236243
val packageVersion = context.packageMetadata.packageVersion
237244

238245
patches.forEach patch@{ patch ->
239-
val formattedPatchName = patch.patchName.lowercase().replace(" ", "-")
246+
val formattedPatchName = patch.patchName.format()
240247

241-
val explicitlyExcluded = excludedPatches.contains(formattedPatchName)
248+
val explicitlyExcluded = formattedExcludedPatches.contains(formattedPatchName)
242249
if (explicitlyExcluded) return@patch logger.info("Excluding ${patch.patchName}")
243250

244251
// Make sure the patch is compatible with the supplied APK files package name and version.
@@ -248,12 +255,13 @@ internal object PatchCommand : Runnable {
248255
it.isEmpty() || it.any { version -> version == packageVersion }
249256
}
250257

251-
if (!matchesVersion) return@patch logger.warning("${patch.patchName} is incompatible with version $packageVersion. " + "This patch is only compatible with version " + packages.joinToString(
252-
";"
253-
) { pkg ->
254-
"${pkg.name}: ${pkg.versions.joinToString(", ")}"
255-
})
256-
258+
if (!matchesVersion) return@patch logger.warning(
259+
"${patch.patchName} is incompatible with version $packageVersion. "
260+
+ "This patch is only compatible with version "
261+
+ packages.joinToString(";") { pkg ->
262+
"${pkg.name}: ${pkg.versions.joinToString(", ")}"
263+
}
264+
)
257265
} ?: return@patch logger.fine("${patch.patchName} is incompatible with $packageName. "
258266
+ "This patch is only compatible with "
259267
+ packages.joinToString(", ") { `package` -> `package`.name })
@@ -264,7 +272,7 @@ internal object PatchCommand : Runnable {
264272
// If the patch is implicitly included, it will be only included if [exclusive] is false.
265273
val implicitlyIncluded = !exclusive && patch.include
266274
// If the patch is explicitly included, it will be included even if [exclusive] is false.
267-
val explicitlyIncluded = includedPatches.contains(formattedPatchName)
275+
val explicitlyIncluded = formattedIncludedPatches.contains(formattedPatchName)
268276

269277
val included = implicitlyIncluded || explicitlyIncluded
270278
if (!included) return@patch logger.info("${patch.patchName} excluded by default") // Case 1.

0 commit comments

Comments
 (0)