Skip to content

Commit

Permalink
fix: format patches input
Browse files Browse the repository at this point in the history
Previously you could not use the original patches names because they were formatted but not the input
  • Loading branch information
oSumAtrIX committed Aug 28, 2023
1 parent f7fcbc5 commit bbb1a63
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/main/kotlin/app/revanced/cli/command/PatchCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,20 @@ internal object PatchCommand : Runnable {
* @return The filtered patches.
*/
private fun Patcher.filterPatchSelection(patches: PatchList) = buildList {
// TODO: Remove this eventually because
// patches named "patch-name" and "patch name" will conflict.
fun String.format() = lowercase().replace(" ", "-")

val formattedExcludedPatches = excludedPatches.map { it.format() }
val formattedIncludedPatches = includedPatches.map { it.format() }

val packageName = context.packageMetadata.packageName
val packageVersion = context.packageMetadata.packageVersion

patches.forEach patch@{ patch ->
val formattedPatchName = patch.patchName.lowercase().replace(" ", "-")
val formattedPatchName = patch.patchName.format()

val explicitlyExcluded = excludedPatches.contains(formattedPatchName)
val explicitlyExcluded = formattedExcludedPatches.contains(formattedPatchName)
if (explicitlyExcluded) return@patch logger.info("Excluding ${patch.patchName}")

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

if (!matchesVersion) return@patch logger.warning("${patch.patchName} is incompatible with version $packageVersion. " + "This patch is only compatible with version " + packages.joinToString(
";"
) { pkg ->
"${pkg.name}: ${pkg.versions.joinToString(", ")}"
})

if (!matchesVersion) return@patch logger.warning(
"${patch.patchName} is incompatible with version $packageVersion. "
+ "This patch is only compatible with version "
+ packages.joinToString(";") { pkg ->
"${pkg.name}: ${pkg.versions.joinToString(", ")}"
}
)
} ?: return@patch logger.fine("${patch.patchName} is incompatible with $packageName. "
+ "This patch is only compatible with "
+ packages.joinToString(", ") { `package` -> `package`.name })
Expand All @@ -264,7 +272,7 @@ internal object PatchCommand : Runnable {
// If the patch is implicitly included, it will be only included if [exclusive] is false.
val implicitlyIncluded = !exclusive && patch.include
// If the patch is explicitly included, it will be included even if [exclusive] is false.
val explicitlyIncluded = includedPatches.contains(formattedPatchName)
val explicitlyIncluded = formattedIncludedPatches.contains(formattedPatchName)

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

1 comment on commit bbb1a63

@NBruderman
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you plan to release it to the main branch soon?

Please sign in to comment.