Bug 256606 - textproc/kdiff3: missing/extra newlines when merging
Summary: textproc/kdiff3: missing/extra newlines when merging
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-kde (group)
URL: https://bugs.kde.org/show_bug.cgi?id=...
Keywords:
Depends on:
Blocks:
 
Reported: 2021-06-14 17:20 UTC by Ed Maste
Modified: 2021-06-14 23:59 UTC (History)
2 users (show)

See Also:
bugzilla: maintainer-feedback? (kde)


Attachments
revert to 1.8.5 (3.25 KB, patch)
2021-06-14 18:24 UTC, Ed Maste
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ed Maste freebsd_committer freebsd_triage 2021-06-14 17:20:23 UTC
kdiff3 1.9.2 on FreeBSD 13.0 + some minor kernel changes

Using kdiff3 for resolving git merge conflicts I noticed that output files sometimes have extra whitespace, and are missing a newline at EOF. I encountered this within the last month or two.

Reproduction steps - create test files:

printf 'line 1\nline 2-base\nline 3-base\nline 4\n' > base
printf 'line 1\nline 2-theirs\nline 4\n' > theirs
printf 'line 1\nline 2-mine\nline 4\n' > mine

Invoke kdiff3:

kdiff3 -o out base theirs mine

Resolve the conflict choosing 'mine', save output

Observe that the output file has a blank 3rd line, and has no \x0a at EOF. By default I have LANG=en_CA.UTF-8 but observed also with LANG unset.
Comment 1 Ed Maste freebsd_committer freebsd_triage 2021-06-14 18:00:48 UTC
Could we perhaps revert to the old version, until this is fixed?
Comment 2 Ed Maste freebsd_committer freebsd_triage 2021-06-14 18:24:21 UTC
Created attachment 225807 [details]
revert to 1.8.5

Patch applied locally to revert to 1.8.5, which fixes the problem for me.

I set PORTEPOCH to 1 to handle the now-lower version number, but need a ports committer to check.
Comment 3 Adriaan de Groot freebsd_committer freebsd_triage 2021-06-14 20:51:59 UTC
For those not conversant with kdiff3:

- invoke kdiff3 as Ed says, `kdiff3 -o out base theirs mine`
- it comes up with a "Conflicts" dialog, saying Total 2, auto-solved 1, 1 unsolved; click *ok*
- the lower half of the window shows the *output* part, with each line displayed

```
line 1
<Merge Conflict>
<No src line>
line 4
```

There's a kind of highlight on the first conflict line. Press ctrl-3 **or** right-mouse-click on that line and select *C* (with the files in the order given in the command, *base* is *A*, *theirs* is *B*, and *mine* is *C*). The conflict marker is replaced by the content of the line from file *C*.

Now the number at the bottom says "0 unresolved", and you can hit ctrl-S to save and ctrl-Q to quit.

Output of `od -c` on the result:

```
0000000    l   i   n   e       1  \n   l   i   n   e       2   -   m   i
0000020    n   e  \n  \n   l   i   n   e       4                        
```
Comment 4 Adriaan de Groot freebsd_committer freebsd_triage 2021-06-14 22:34:37 UTC
I'm going to apply https://invent.kde.org/sdk/kdiff3/-/merge_requests/31 to packaging instead, since that fixes the problem in 1.9.2 and we don't need to mess with PORTEPOCH.
Comment 5 commit-hook freebsd_committer freebsd_triage 2021-06-14 23:03:28 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=efda9660cc81115e5b149426287b09e44a25f388

commit efda9660cc81115e5b149426287b09e44a25f388
Author:     Adriaan de Groot <adridg@FreeBSD.org>
AuthorDate: 2021-06-14 23:00:52 +0000
Commit:     Adriaan de Groot <adridg@FreeBSD.org>
CommitDate: 2021-06-14 23:03:16 +0000

    textproc/kdiff3: fix output of merged file

    Fix spurious newlines and missing newline at the end of file.

    Upstream report:        https://bugs.kde.org/show_bug.cgi?id=437570
    Upstream merge request: https://invent.kde.org/sdk/kdiff3/-/merge_requests/31

    PR:                     256606
    Reported by:            emaste

 textproc/kdiff3/Makefile                           |  1 +
 .../files/patch-src_mergeresultwindow.cpp (new)    | 50 ++++++++++++++++++++++
 2 files changed, 51 insertions(+)
Comment 6 Adriaan de Groot freebsd_committer freebsd_triage 2021-06-14 23:18:26 UTC
I've checked that this fixes at least the example Ed gave and some other weirdness.
Comment 7 Ed Maste freebsd_committer freebsd_triage 2021-06-14 23:59:21 UTC
Most excellent, thank you!