Skip to content

Commit 2d5a7fd

Browse files
committed
fix: filtration of patches malfunctioning
Apparently, you were not able to include patches explicitly
1 parent be5d812 commit 2d5a7fd

File tree

1 file changed

+21
-70
lines changed

1 file changed

+21
-70
lines changed

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

+21-70
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ internal object PatchCommand : Runnable {
6868
private var exclusive = false
6969

7070
@CommandLine.Option(
71-
names = ["--experimental"],
72-
description = ["Ignore patches incompatibility to versions"],
71+
names = ["-f","--force"],
72+
description = ["Force inclusion of patches that are incompatible with the supplied APK file's version"],
7373
showDefaultValue = ALWAYS
7474
)
75-
private var experimental: Boolean = false
75+
private var force: Boolean = false
7676

7777
@CommandLine.Option(
7878
names = ["-o", "--out"], description = ["Path to save the patched APK file to"], required = true
@@ -225,8 +225,8 @@ internal object PatchCommand : Runnable {
225225
* - [includedPatches] (explicitly included)
226226
* - [excludedPatches] (explicitly excluded)
227227
* - [exclusive] (only include patches that are explicitly included)
228-
* - [experimental] (ignore patches incompatibility to versions)
229-
* - package name and version of the input APK file (if [experimental] is false)
228+
* - [force] (ignore patches incompatibility to versions)
229+
* - Package name and version of the input APK file (if [force] is false)
230230
*
231231
* @param patches The patches to filter.
232232
* @return The filtered patches.
@@ -238,46 +238,22 @@ internal object PatchCommand : Runnable {
238238
patches.forEach patch@{ patch ->
239239
val formattedPatchName = patch.patchName.lowercase().replace(" ", "-")
240240

241-
/**
242-
* Check if the patch is explicitly excluded.
243-
*
244-
* Cases:
245-
* 1. -e patch.name
246-
* 2. -i patch.name -e patch.name
247-
*/
248-
249-
/**
250-
* Check if the patch is explicitly excluded.
251-
*
252-
* Cases:
253-
* 1. -e patch.name
254-
* 2. -i patch.name -e patch.name
255-
*/
256-
257-
val excluded = excludedPatches.contains(formattedPatchName)
258-
if (excluded) return@patch logger.info("Excluding ${patch.patchName}")
259-
260-
/**
261-
* Check if the patch is constrained to packages.
262-
*/
263-
264-
/**
265-
* Check if the patch is constrained to packages.
266-
*/
241+
val explicitlyExcluded = excludedPatches.contains(formattedPatchName)
242+
if (explicitlyExcluded) return@patch logger.info("Excluding ${patch.patchName}")
267243

268-
patch.compatiblePackages?.let { packages ->
269-
packages.singleOrNull { it.name == packageName }?.let { `package` ->
270-
/**
271-
* Check if the package version matches.
272-
* If experimental is true, version matching will be skipped.
273-
*/
244+
// If the patch is explicitly included, it will be included if [exclusive] is false.
245+
val explicitlyIncluded = exclusive && includedPatches.contains(formattedPatchName)
274246

275-
/**
276-
* Check if the package version matches.
277-
* If experimental is true, version matching will be skipped.
278-
*/
247+
// If the patch is implicitly included, it will be only included if [exclusive] is false.
248+
val implicitlyIncluded = !exclusive && patch.include
249+
250+
val included = implicitlyIncluded || explicitlyIncluded
251+
if (!included) return@patch logger.info("${patch.patchName} excluded by default") // Case 1.
279252

280-
val matchesVersion = experimental || `package`.versions.let {
253+
// At last make sure the patch is compatible with the supplied APK files package name and version.
254+
patch.compatiblePackages?.let { packages ->
255+
packages.singleOrNull { it.name == packageName }?.let { `package` ->
256+
val matchesVersion = force || `package`.versions.let {
281257
it.isEmpty() || it.any { version -> version == packageVersion }
282258
}
283259

@@ -287,38 +263,13 @@ internal object PatchCommand : Runnable {
287263
"${pkg.name}: ${pkg.versions.joinToString(", ")}"
288264
})
289265

290-
}
291-
?: return@patch logger.fine("${patch.patchName} is incompatible with $packageName. " + "This patch is only compatible with " + packages.joinToString(
292-
", "
293-
) { `package` -> `package`.name })
266+
} ?: return@patch logger.fine("${patch.patchName} is incompatible with $packageName. "
267+
+ "This patch is only compatible with "
268+
+ packages.joinToString(", ") { `package` -> `package`.name })
294269

295270
return@let
296271
} ?: logger.fine("$formattedPatchName: No constraint on packages.")
297272

298-
/**
299-
* Check if the patch is explicitly included.
300-
*
301-
* Cases:
302-
* 1. --exclusive
303-
* 2. --exclusive -i patch.name
304-
*/
305-
306-
/**
307-
* Check if the patch is explicitly included.
308-
*
309-
* Cases:
310-
* 1. --exclusive
311-
* 2. --exclusive -i patch.name
312-
*/
313-
314-
val explicitlyIncluded = includedPatches.contains(formattedPatchName)
315-
316-
val implicitlyIncluded = !exclusive && patch.include // Case 3.
317-
val exclusivelyIncluded = exclusive && explicitlyIncluded // Case 2.
318-
319-
val included = implicitlyIncluded || exclusivelyIncluded
320-
if (!included) return@patch logger.info("${patch.patchName} excluded by default") // Case 1.
321-
322273
logger.fine("Adding $formattedPatchName")
323274

324275
add(patch)

0 commit comments

Comments
 (0)