From 4b9a233416ea0502ed6d0c41b740e96e6a5ec7d7 Mon Sep 17 00:00:00 2001 From: okx-code Date: Sat, 28 Sep 2024 03:22:32 +0100 Subject: [PATCH] Specify myers diff algorithm explicitly (#252) * Use myers diff algorithm This is the default Git diff algorithm and by specifying this explicitly we prevent git configs from overriding this setting. As Paper relies on patches generated with Myers, and breaks with other algorithms, it doesn't make sense to allow users to configure this. * Add diff algorithm in generatePatches * Also add to isUnfinishedPatch --- .../kotlin/io/papermc/paperweight/tasks/RebuildGitPatches.kt | 4 ++-- .../io/papermc/paperweight/tasks/patchremap/PatchApplier.kt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/RebuildGitPatches.kt b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/RebuildGitPatches.kt index e09fb89..c62c8c7 100644 --- a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/RebuildGitPatches.kt +++ b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/RebuildGitPatches.kt @@ -97,7 +97,7 @@ abstract class RebuildGitPatches : ControllableOutputTask() { git("fetch", "--all", "--prune").runSilently(silenceErr = true) git( "format-patch", - "--zero-commit", "--full-index", "--no-signature", "--no-stat", "-N", + "--diff-algorithm=myers", "--zero-commit", "--full-index", "--no-signature", "--no-stat", "-N", "-o", patchFolder.absolutePathString(), baseRef.get() ).executeSilently() @@ -131,7 +131,7 @@ abstract class RebuildGitPatches : ControllableOutputTask() { try { for (patch in patchFiles) { futures += executor.submit { - val hasNoChanges = git("diff", "--staged", patch.name).getText().lineSequence() + val hasNoChanges = git("diff", "--diff-algorithm=myers", "--staged", patch.name).getText().lineSequence() .filter { it.startsWith('+') || it.startsWith('-') } .filterNot { it.startsWith("+++") || it.startsWith("---") } .all { it.startsWith("+index") || it.startsWith("-index") } diff --git a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/patchremap/PatchApplier.kt b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/patchremap/PatchApplier.kt index 7b4ec9a..8944f3f 100644 --- a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/patchremap/PatchApplier.kt +++ b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/patchremap/PatchApplier.kt @@ -103,7 +103,7 @@ class PatchApplier( target.createDirectories() git("checkout", remappedBranch).executeSilently() git( - "format-patch", "--zero-commit", "--full-index", "--no-signature", "--no-stat", "-N", "-o", + "format-patch", "--diff-algorith=myers", "--zero-commit", "--full-index", "--no-signature", "--no-stat", "-N", "-o", target.absolutePathString(), remappedBaseTag ).executeOut() } @@ -114,7 +114,7 @@ class PatchApplier( } git("update-index", "--refresh").executeSilently() - if (git("diff-index", "--quiet", "HEAD", "--").runSilently() == 0) { + if (git("diff-index", "--diff-algorithm=myers", "--quiet", "HEAD", "--").runSilently() == 0) { return git("log", unmappedBranch, "-1", "--pretty=%B").getText().trim() != git("log", remappedBranch, "-1", "--pretty=%B").getText().trim() }