Skip to content

Commit

Permalink
Specify myers diff algorithm explicitly (#252)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
okx-code authored Sep 28, 2024
1 parent b3467d9 commit 4b9a233
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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") }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -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()
}
Expand Down

0 comments on commit 4b9a233

Please sign in to comment.