Subject: Re: bug#79024: 31.0.50; Multiple working trees support for VC

From: Sean Whitton <[email-masked]>
Date: Thu, 14 Aug 2025 13:26:44 +0100

Hello,

On Wed 13 Aug 2025 at 02:17pm +03, Eli Zaretskii wrote:

> but the temporary file's name could still include non-ASCII characters
> (e.g., if the user's name includes them).

This is the point I was missing, thanks.

Could you test the attached, please?

I've also realised that vc-git-modify-change-comment needs the command
line argument encoding, which I'll fix separately.

-- 
Sean Whitton
>From 76c3d9cbd6478ba5229744372b712d65bdafbaed Mon Sep 17 00:00:00 2001
From: Sean Whitton <[email-masked]>
Date: Thu, 14 Aug 2025 13:23:24 +0100
Subject: [PATCH] * lisp/vc/vc-hg.el (vc-hg-checkin): Fix on MS-Windows
 (bug#79024).

---
 lisp/vc/vc-hg.el | 58 ++++++++++++++++++++++++++++++++++++------------
 1 file changed, 44 insertions(+), 14 deletions(-)

diff --git a/lisp/vc/vc-hg.el b/lisp/vc/vc-hg.el
index 3a6580c16f4..dabf42757ce 100644
--- a/lisp/vc/vc-hg.el
+++ b/lisp/vc/vc-hg.el
@@ -1216,20 +1216,50 @@ 'vc-hg-async-checkins
 (defun vc-hg-checkin (files comment &optional _rev)
   "Hg-specific version of `vc-BACKEND-checkin'.
 REV is ignored."
-  (let ((args (nconc (list "commit" "-A" "-m")
-                     (vc-hg--extract-headers comment))))
-    (if vc-async-checkin
-        (let ((buffer (vc-hg--async-buffer)))
-          (vc-wait-for-process-before-save
-           (apply #'vc-hg--async-command buffer (nconc args files))
-           "Finishing checking in files...")
-          (with-current-buffer buffer
-            (vc-run-delayed
-              (vc-compilation-mode 'hg)))
-          (vc-set-async-update buffer)
-          (list 'async (get-buffer-process buffer)))
-      (apply #'vc-hg-command nil 0 files args))))
-
+  (let* ((args (vc-hg--extract-headers comment))
+         (file1 (or (car files) default-directory))
+         (msg-file
+          ;; On MS-Windows, pass the commit log message through a file,
+          ;; to work around the limitation that command-line arguments
+          ;; must be in the system codepage, and therefore might not
+          ;; support non-ASCII characters in the log message.
+          ;; Also handle remote files.
+          (and (eq system-type 'windows-nt)
+               (let ((default-directory (or (file-name-directory file1)
+                                            default-directory)))
+                 (make-nearby-temp-file "hg-msg")))))
+    (when msg-file
+      (write-region (car args) nil msg-file))
+    (let ((coding-system-for-write
+           ;; On MS-Windows, we must encode command-line arguments in
+           ;; the system codepage.
+           (if (eq system-type 'windows-nt)
+               locale-coding-system
+             coding-system-for-write))
+          (args (if msg-file
+                    (cl-list* "commit" "-A" "-l" (file-local-name msg-file)
+                              (cdr args))
+                  (cl-list* "commit" "-A" "-m" args)))
+          (post (lambda ()
+                  (when (and msg-file (file-exists-p msg-file))
+                    (delete-file msg-file)))))
+      (if vc-async-checkin
+          (let ((buffer (vc-hg--async-buffer)))
+            (vc-wait-for-process-before-save
+             (apply #'vc-hg--async-command buffer (nconc args files))
+             "Finishing checking in files...")
+            (with-current-buffer buffer
+              (vc-run-delayed
+                (vc-compilation-mode 'hg)
+                (funcall post)))
+            (vc-set-async-update buffer)
+            (list 'async (get-buffer-process buffer)))
+        (apply #'vc-hg-command nil 0 files args)
+        (funcall post)))))
+
+;; FIXME: Needs MS-Windows encoding issues handling.
+;; Possibly we want fix this by merging this function into the preceeding one.
+;; Figure out resolution of #79235 first.
 (defun vc-hg-checkin-patch (patch-string comment)
   (let ((patch-file (make-nearby-temp-file "hg-patch")))
     (write-region patch-string nil patch-file)
-- 
2.47.2