neilbrown / wiggle

apply rejected patches and perform word-wise diffs
http://neil.brown.name/wiggle
GNU General Public License v2.0
91 stars 8 forks source link

ignore new white space in the patch context #27

Open john-peterson opened 1 month ago

john-peterson commented 1 month ago

unexpected new line in context

if a new line has appeared in the patch context since the patch was created the patch is not cleanly applied

there could be a flag to ignore this type of conflict instead of forcing a manual edit

proposed solution: compare the found and expected section. if the difference is only white space characters write the replacement without a conflict message

in this example i would like to use the replacement as it is without creating a conflict message that an extra new line is now in the context that was not there before

alias copy=termux-clipboard-set
alias ws="sed 's/ /·/g;s/\t/→/g;s/\r/§/g;s/$/¶/g'"

printf "a\n\nc">orig
printf "a\n\nb\n\nc">new
diff orig new -Naru>patch

cat patch|ws|copy
---·orig→2024-05-19·00:06:29.249319646·+0300¶
+++·new→2024-05-19·00:06:29.249319646·+0300¶
@@·-1,3·+1,5·@@¶
·a¶
·¶
+b¶
+¶
·c¶
\·No·newline·at·end·of·file¶

printf "a\n\n\nc">new
rm new.porig
wiggle -rp patch
1 unresolved conflict found

cat new|ws|copy
<<<<<<<·found¶
a¶
¶
¶
c|||||||·expected¶
a¶
¶
c¶
=======¶
a¶
¶
b¶
¶
c¶
>>>>>>>·replacement¶

and again almost the same

this might be redundant

the actual problem is the same but i also introduce a harmless mistake of removing a space from indentation

the found and expected message is still correct with context unlike the actual conflict further down

printf "  a\nc">orig
printf " a\nb\nc">new
diff orig new -Naru>patch
printf "  a\n\nc">new
rm new.porig
wiggle -rp patch
1 unresolved conflict found

cat new|ws|copy
<<<<<<<·found¶
··a¶
¶
c|||||||·expected¶
··a¶
c¶
=======¶
·a¶
b¶
c¶
>>>>>>>·replacement¶

the actual conflict

all the conflicts from these patches seemed to be caused by new white space in the context that i would like to ignore

git clone --depth 1 https://github.com/termux/termux-app

git remote add jp https://github.com/john-peterson/termux-app

git pull jp day key

unexpected new line in context

there was one empty line in the context when i patched it but now there are three.

this happens in two places but i show only one for brevity

the message context is stripped but it is correct about two new empty lines

git format-patch jp/day -2

ack "Integer getTerminalCursorStyle" terminal-emulator/src/main/java/com/termux/terminal/TerminalSessionClient.java -A2|ws
····Integer·getTerminalCursorStyle();¶
¶
¶
¶
····void·logError(String·tag,·String·message);¶

ack shouldEnableDarkTheme 0001* -C2|ws
·····Integer·getTerminalCursorStyle();¶
·¶
+····boolean·shouldEnableDarkTheme();¶
+¶
·····void·logError(String·tag,·String·message);¶
--¶

wiggle -rp 0001*
1 unresolved conflict found
1 unresolved conflict found

ack -A 10 "<<<" --heading|ws|copy
terminal-emulator/src/main/java/com/termux/terminal/TerminalSessionClient.java
<<<<<<<·found¶
¶
¶
|||||||·expected¶
=======¶
····boolean·shouldEnableDarkTheme();¶
¶
>>>>>>>·replacement¶
····void·logError(String·tag,·String·message);¶
¶
····void·logWarn(String·tag,·String·message);¶

same problem again

a conflict is generated because a new line has appeared in the context

in this case also the replacement would be fine there was no need to generate a conflict

the first line in the patch is an accidentally removed space but it is irrelevant to the problem

the found and expected message is incorrect in this case it should indicate the new line with context preferably not the first line of the patch context that contains nothing interesting


git checkout .
git clean -f
git format-patch jp/key -3

wiggle -rp 0001*
1 unresolved conflict found

ack mExtraKeysView.reload -A10 --heading --break|ws|copy

app/src/main/java/com/termux/app/TermuxActivity.java¶
1013:················mExtraKeysView.reload(mTermuxTerminalExtraKeys.getExtraKeysInfo(),·mTerminalToolbarDefaultHeight);¶
1014-············}¶
1015-¶
1016-|||||||·expected¶
1017:················mExtraKeysView.reload(mTermuxTerminalExtraKeys.getExtraKeysInfo(),·mTerminalToolbarDefaultHeight);¶
1018-············}¶
1019-=======¶
1020:···············mExtraKeysView.reload(mTermuxTerminalExtraKeys.getExtraKeysInfo(),·mTerminalToolbarDefaultHeight);¶
1021-············}¶
1022-············if·(mExtraKeysView2·!=·null)·{¶
1023-················mExtraKeysView2.setButtonTextAllCaps(mProperties.shouldExtraKeysTextBeAllCaps());¶
1024-···············mExtraKeysView2.reload(mTermuxTerminalExtraKeys2.getExtraKeysInfo(),·mTerminalToolbarDefaultHeight);¶
1025-············}¶
1026->>>>>>>·replacement¶
1027-············//·Update·NightMode.APP_NIGHT_MODE¶
1028-············TermuxThemeUtils.setAppNightMode(mProperties.getNightMode());¶
1029-········}¶
1030-¶
¶
app/src/main/java/com/termux/app/TermuxActivity.java.porig¶
985:················mExtraKeysView.reload(mTermuxTerminalExtraKeys.getExtraKeysInfo(),·mTerminalToolbarDefaultHeight);¶
986-············}¶
987-¶
988-············//·Update·NightMode.APP_NIGHT_MODE¶
989-············TermuxThemeUtils.setAppNightMode(mProperties.getNightMode());¶
990-········}¶
991-¶

¶
0001-Add-a-second-keyboard.patch¶
102:-················mExtraKeysView.reload(mTermuxTerminalExtraKeys.getExtraKeysInfo(),·mTerminalToolbarDefaultHeight);¶
103:+···············mExtraKeysView.reload(mTermuxTerminalExtraKeys.getExtraKeysInfo(),·mTerminalToolbarDefaultHeight);¶
104-+············}¶
105-+············if·(mExtraKeysView2·!=·null)·{¶
106-+················mExtraKeysView2.setButtonTextAllCaps(mProperties.shouldExtraKeysTextBeAllCaps());¶
107-+···············mExtraKeysView2.reload(mTermuxTerminalExtraKeys2.getExtraKeysInfo(),·mTerminalToolbarDefaultHeight);¶
108-·············}¶
109-·············//·Update·NightMode.APP_NIGHT_MODE¶
110-·············TermuxThemeUtils.setAppNightMode(mProperties.getNightMode());¶
neilbrown commented 1 month ago

Hi, thanks for you interest in making wiggle better. I tried your first example but with a "\n" at the end of each file, and it worked as you would like (which surprised me a little). I'll probably enhance wiggle to add a "\n" to the end of the file if there isn't one (and the file isn't empty).

I tried your second example and it behaves as you say, but if I use "-b" or "--ignore-blanks" then it does what you want.

Similarly the final example gives the found/expected content that you wanted if you use "-b".

But both examples from termux code do, as you say, give the unwanted conflict even if I specify "-b".

The reasoning is that wiggle sees that the patch adds lines where someone else added lines, and it cannot deduce which of the insertions should be first, and which should be second. You want to say that you don't care when one of the insertions is simply blank lines.

It probably makes sense to enhance "-b" to also ignore blank lines. I'll try to find time to work on that.

neilbrown commented 1 month ago

I've pushed a few changes to wiggle on github. The "-b" option should now do what you want. Please test and confirm.