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
This commit is contained in:
okx-code 2024-09-28 03:22:32 +01:00 committed by GitHub
parent b3467d9f8d
commit 4b9a233416
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 4 deletions

View file

@ -97,7 +97,7 @@ abstract class RebuildGitPatches : ControllableOutputTask() {
git("fetch", "--all", "--prune").runSilently(silenceErr = true) git("fetch", "--all", "--prune").runSilently(silenceErr = true)
git( git(
"format-patch", "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(), "-o", patchFolder.absolutePathString(),
baseRef.get() baseRef.get()
).executeSilently() ).executeSilently()
@ -131,7 +131,7 @@ abstract class RebuildGitPatches : ControllableOutputTask() {
try { try {
for (patch in patchFiles) { for (patch in patchFiles) {
futures += executor.submit { 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('-') } .filter { it.startsWith('+') || it.startsWith('-') }
.filterNot { it.startsWith("+++") || it.startsWith("---") } .filterNot { it.startsWith("+++") || it.startsWith("---") }
.all { it.startsWith("+index") || it.startsWith("-index") } .all { it.startsWith("+index") || it.startsWith("-index") }

View file

@ -103,7 +103,7 @@ class PatchApplier(
target.createDirectories() target.createDirectories()
git("checkout", remappedBranch).executeSilently() git("checkout", remappedBranch).executeSilently()
git( 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 target.absolutePathString(), remappedBaseTag
).executeOut() ).executeOut()
} }
@ -114,7 +114,7 @@ class PatchApplier(
} }
git("update-index", "--refresh").executeSilently() 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() != return git("log", unmappedBranch, "-1", "--pretty=%B").getText().trim() !=
git("log", remappedBranch, "-1", "--pretty=%B").getText().trim() git("log", remappedBranch, "-1", "--pretty=%B").getText().trim()
} }