Subject: bug#20892: closed (Re: bug#20892: 25.0.50; Applying vc-diff hunks on CRLF tracked files)

From: [email-masked] (GNU bug Tracking System)
Date: Sat, 02 Apr 2016 14:29:01 +0000

Your bug report

#20892: 25.0.50; Applying vc-diff hunks on CRLF tracked files

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
20892: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=20892
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#20892: 25.0.50; Applying vc-diff hunks on CRLF tracked files
From: Eli Zaretskii <[email-masked]>
To: João Távora <[email-masked]>
Cc: [email-masked], [email-masked]
Date: Sat, 02 Apr 2016 17:27:20 +0300
List-Id: <debbugs-submit.debbugs.gnu.org>

> From: João Távora <[email-masked]>
> Date: Sat, 2 Apr 2016 14:42:48 +0100
> Cc: Stefan Monnier <[email-masked]>, [email-masked]
> 
> 1. Sometime in June 2015, upgrade my emacs. vc-diff some CRLF file
> 
> 2. "Cool, a new feature now makes it show precisely which chars were
>    added and deleted even the CRs"
> 
> 3. "Oh, but vc-apply-hunk stopped working, let's open bug 20892"
> 
> 4. Discuss bug, argue that showing ^M is cool for when you really want
>    to apply patches that add and remove just one or two of those.
> 
> 5. Apply some reasonable fix to my config. Be side-tracked by
>    dayjob. Lose interest in discussing the bug,
> 
> 6. Eventually, realize 4 is silly and if you're mixing CRLF and
>    non-CRLF line endings you've already lost.
> 
> 7. Recently, March 2016, also realize that diacritics are also wrong
>    in latin-1 files.
> 
> 8. Decide to reevaluate situation, read some code and commit messages,
>    and propose a new fix that makes the vc-diff buffer have the same
>    encoding as the originating file, as apparently was intended.
>    vc-apply-hunk is fixed, if I ever need to do something like 4
>    I'll do it outside of emacs.
> 
> I think you can close the bug.

Thanks, closing.

Subject: 25.0.50; Applying vc-diff hunks on CRLF tracked files
From: [email-masked] (João Távora)
To: [email-masked]
Date: Wed, 24 Jun 2015 12:29:05 +0100
List-Id: <debbugs-submit.debbugs.gnu.org>

Hello maintainers,

1. Navigate to a repository where files are tracked with CRLF line
   endings.
   
2. Modify one of those files.

3. Use M-x vc-root-diff. Observe how, in the latest trunk, the carriage
   return (represented as ^M) are visible as a part of the diff hunk's
   content. This is correct, in my opinion, if a little visually
   distracting.

4. Undo of of those diffs with C-c C-a

5. Redo the same hunk with C-c C-a again

6. Notive how diff-apply-hunk incorrectly applies the carriage return
   characters themselves.

Here's a trivial patch to lisp/vc/diff-mode.el, or simply cherry-pick
the commit 

  7ed2b6299425c4b2ea6bd8d8e8eb5eaa5e5ddf7e

which is available in this url

   https://github.com/capitaomorte/emacs.git

 @@ -1799,7 +1799,8 @@ 
       (with-current-buffer buf
 	(goto-char (car pos))
 	(delete-region (car pos) (cdr pos))
-	(insert (car new)))
+	(insert (decode-coding-string (car new)
+	                              buffer-file-coding-system)))
       ;; Display BUF in a window
       (set-window-point (display-buffer buf) (+ (car pos) (cdr new)))
       (diff-hunk-status-msg line-offset (diff-xor switched reverse) nil)

The commit message is

    Consider coding system when applying diff-mode hunks.
     
    Without this, applying hunks may garble line endings in the
    destination buffer.
     
    * lisp/vc/diff-mode.el (diff-apply-hunk): Use decode-coding-string and
      buffer-file-coding-system.
      
Sorry I couldn't properly inline a patch,

Thanks,
João