From mboxrd@z Thu Jan  1 00:00:00 1970
Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail
From: Eli Zaretskii <eliz@gnu.org>
Newsgroups: gmane.emacs.bugs
Subject: bug#68377: Cannot commit parts of *vc-diff* on Microsoft Windows
Date: Thu, 11 Jan 2024 14:28:49 +0200
Message-ID: <83r0iokq9q.fsf@gnu.org>
References: <87le8wy65p.fsf@gnu.org>
Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214";
	logging-data="2493"; mail-complaints-to="usenet@ciao.gmane.io"
Cc: 68377@debbugs.gnu.org
To: sds@gnu.org
Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jan 11 13:30:30 2024
Return-path: <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org>
Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org
Original-Received: from lists.gnu.org ([209.51.188.17])
	by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
	(Exim 4.92)
	(envelope-from <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org>)
	id 1rNuCb-0000K6-TI
	for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 11 Jan 2024 13:30:30 +0100
Original-Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <bug-gnu-emacs-bounces@gnu.org>)
	id 1rNuCF-0002U5-IB; Thu, 11 Jan 2024 07:30:07 -0500
Original-Received: from eggs.gnu.org ([2001:470:142:3::10])
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <Debian-debbugs@debbugs.gnu.org>)
 id 1rNuCD-0002TO-Jy
 for bug-gnu-emacs@gnu.org; Thu, 11 Jan 2024 07:30:05 -0500
Original-Received: from debbugs.gnu.org ([2001:470:142:5::43])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <Debian-debbugs@debbugs.gnu.org>)
 id 1rNuCD-0004mg-AI
 for bug-gnu-emacs@gnu.org; Thu, 11 Jan 2024 07:30:05 -0500
Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2)
 (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1rNuCA-0001OU-BW
 for bug-gnu-emacs@gnu.org; Thu, 11 Jan 2024 07:30:02 -0500
X-Loop: help-debbugs@gnu.org
Resent-From: Eli Zaretskii <eliz@gnu.org>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@gnu.org
Resent-Date: Thu, 11 Jan 2024 12:30:02 +0000
Resent-Message-ID: <handler.68377.B68377.17049761705255@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 68377
X-GNU-PR-Package: emacs
Original-Received: via spool by 68377-submit@debbugs.gnu.org id=B68377.17049761705255
 (code B ref 68377); Thu, 11 Jan 2024 12:30:02 +0000
Original-Received: (at 68377) by debbugs.gnu.org; 11 Jan 2024 12:29:30 +0000
Original-Received: from localhost ([127.0.0.1]:58956 helo=debbugs.gnu.org)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
 id 1rNuBe-0001Mf-2c
 for submit@debbugs.gnu.org; Thu, 11 Jan 2024 07:29:30 -0500
Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:43606)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@gnu.org>) id 1rNuBb-0001MS-4f
 for 68377@debbugs.gnu.org; Thu, 11 Jan 2024 07:29:29 -0500
Original-Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@gnu.org>)
 id 1rNuBW-0004X9-IP; Thu, 11 Jan 2024 07:29:24 -0500
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=3p7ihYQ/qotXQjm2KXCOyYhHoknptlWYMJJsVuJEA+U=; b=OoaVNuT0UpvK
 MNnFjdmf8GcsyOFtCTVWp5TixEtuFld/X5NdUA7a9BnHWTYc0VOB81L7O1zDJDwEWRIUBG9JaeF2s
 xxaPXuRjWbpQG5lLVexmlrzQJIjJlESnrCvYmhoBRtEuFZZpcLuKr+anoQp2fC8AaG1PssOad2TUK
 AXR1KRBMpU3VOgWqh0oRkgKypxeSd/YmJF8G2XSVptkXg7syD7xcsVRpfRcv4CxEUQGZSv2jKAOBM
 p9cwibOgvGI5SP9KF7pbG/FH2sjOzJTLSFnc1g2uv23V+TAlOUrINmZPBIwW1CgFALB7UMpq/3sqU
 PX64h7qQ2oqLYCoY+GGrqQ==;
In-Reply-To: <87le8wy65p.fsf@gnu.org> (message from Sam Steingold on Wed, 10
 Jan 2024 21:07:14 -0500)
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
X-BeenThere: bug-gnu-emacs@gnu.org
List-Id: "Bug reports for GNU Emacs,
 the Swiss army knife of text editors" <bug-gnu-emacs.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-gnu-emacs>,
 <mailto:bug-gnu-emacs-request@gnu.org?subject=unsubscribe>
List-Archive: <https://lists.gnu.org/archive/html/bug-gnu-emacs>
List-Post: <mailto:bug-gnu-emacs@gnu.org>
List-Help: <mailto:bug-gnu-emacs-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-gnu-emacs>,
 <mailto:bug-gnu-emacs-request@gnu.org?subject=subscribe>
Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org
Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org
Xref: news.gmane.io gmane.emacs.bugs:277888
Archived-At: <http://permalink.gmane.org/gmane.emacs.bugs/277888>

> From: Sam Steingold <sds@gnu.org>
> Date: Wed, 10 Jan 2024 21:07:14 -0500
> 
> https://emacs.stackexchange.com/q/80039/795
> 
> Emacs has a beautiful feature: in the `*vc-diff*` buffer (generated by [`vc-diff`](https://www.gnu.org/software/emacs/manual/html_node/emacs/Old-Revisions.html) either by <kbd>C-x v =</kbd> in a file buffer or by <kbd>=</kbd> in a `*vc-dir*` buffer), kill unwanted hunks with <kbd>k</kbd> (i.e., [`diff-hunk-kill`](https://www.gnu.org/software/emacs/manual/html_node/emacs/Diff-Mode.html)) and then commit the remaining hunks with <kbd>C-x v v</kbd> (i.e., [`vc-next-action`](https://www.gnu.org/software/emacs/manual/html_node/emacs/Basic-VC-Editing.html)). If you don't know about it -- try it, it is incredibly useful!

(I must say that formatting of this report is AWFUL!  How can a human
being be expected to read and understand it it??  PLEASE try to make
bug reports more readable in the future.)

> Alas, it does _not_ work for me on windows: after <kbd>C-c C-c</kbd> (i.e., [`log-edit-done`](https://www.gnu.org/software/emacs/manual/html_node/emacs/Log-Buffer.html)) in `*vc-log*`, I get 
> > vc-do-command: Failed (status 1): c:/Users/ssteingold/AppData/Local/Git/bin/git.exe --no-pager apply --cached c:/msys64/tmp/git-patchPbbWgJ
> 
> and `*vc*` buffer is
> ```
> error: patch failed: fxpy/model.py:1071
> error: fxpy/model.py: patch does not apply
> ```
> 
> ***Additionally***: 
> 
> 1. Software:
>    * [`GNU Emacs 29.1 (build 2, x86_64-w64-mingw32) of 2023-08-02`](https://ftp.gnu.org/gnu/emacs/windows/emacs-29/)
>    * [`git version 2.42.0.windows.2`](https://gitforwindows.org/)
> 1. *normal* commits work just **fine**, using `vc-next-action` from either file buffer or `*vc-dir*`.
> 1. All my files have unix line terminators (`LF`) as indicated in the mode line as `(Unix)`
> 1. I set `autocrlf` to `false` globally
> 1. I have `(prefer-coding-system 'utf-8-unix)` in `.emacs`
> 1. `vc-coding-system-inherit-eol` is `t`, I did not touch it
> 1. When I add `"-v"` to `git apply` invocation in `vc-git-checkin` (`vc-git.el`), `*vc*` buffer contains `error: while searching for:.....` and every line in `.....` is terminated with `?` - which seems to indicate line-ending problems... (!!!)
> 
> ***Q***: how do I fix this?
> (This is a work box, I cannot send email from Emacs, so I cannot even file an Emacs bug report!)
> 
> # work-around 1
> 
> Add 
> ```
> (setq coding-system-for-write 'utf-8-unix)
> ```
> inside `(with-temp-file patch-file ...)` in `vc-git-checkin`

The code in question already does:

        (let ((patch-file (make-nearby-temp-file "git-patch"))
              ;; Temporarily countermand the let-binding at the
              ;; beginning of this function.
              (coding-system-for-write
               (coding-system-change-eol-conversion
                ;; On DOS/Windows, it is important for the patch file
                ;; to have the Unix EOL format, because Git expects
                ;; that, even on Windows.
                (or pcsw vc-git-commits-coding-system) 'unix)))
          (with-temp-file patch-file
            (insert vc-git-patch-string))

So coding-system-for-write should already be -unix when with-temp-file
runs.  I guess there's more here than meets the eye, or maybe I'm
missing something.

> # work-around 2
> 
> Add
> ```
> ;; replace `undecided`:
> (setf (cadr (assoc "" file-coding-system-alist)) 'utf-8-unix)
> ```
> to `.emacs`

That can't be right.

> # Emacs bug
> 
> `vc-git-checkin` should respect `vc-coding-system-inherit-eol` and set [`coding-system-for-write`](https://www.gnu.org/software/emacs/manual/html_node/elisp/Specifying-Coding-Systems.html) when writing the patch.

This variable is for _reading_ diffs from a VC command, not about
_writing_ them.  So it is not appropriate in this case, and the diffs
shown in the *vc-diff* buffer have correct EOLs.

> Also, it does not seem reasonable that [`prefer-coding-system`](https://www.gnu.org/software/emacs/manual/html_node/emacs/Output-Coding.html) does not affect [`file-coding-system-alist`](https://www.gnu.org/software/emacs/manual/html_node/elisp/Default-Coding-Systems.html).

Using prefer-coding-system to make utf-8 the preferred encoding is
wrong on MS-Windows in the first place: UTF-8 is not yet supported by
Windows well enough to allow that.  In particular, encoding program
arguments in UTF-8 will cause failures in Emacs commands that run
subprocesses.