From cd339e85a695f40d93b5ce9f4e65075dd979b25b Mon Sep 17 00:00:00 2001
From: Michael Albinus <michael.albinus@gmx.de>
Date: Tue, 29 Jun 2021 17:15:55 +0200
Subject: [PATCH] Sync with Tramp 2.5.1

* doc/misc/trampver.texi:
* lisp/net/trampver.el: Change version to "2.5.1".

* lisp/tramp.el (tramp-handle-write-region):
* lisp/tramp-adb.el (tramp-adb-handle-write-region):
* lisp/tramp-sh.el (tramp-sh-handle-write-region): Call local
`write-region' directly.

* test/lisp/net/tramp-tests.el (tramp--test-utf8): Adapt test for
MS Windows.
---
 doc/misc/trampver.texi       |  2 +-
 lisp/net/tramp-adb.el        |  3 +--
 lisp/net/tramp-sh.el         | 12 +++---------
 lisp/net/tramp.el            |  3 +--
 lisp/net/trampver.el         |  6 +++---
 test/lisp/net/tramp-tests.el |  5 +++--
 6 files changed, 12 insertions(+), 19 deletions(-)

diff --git a/doc/misc/trampver.texi b/doc/misc/trampver.texi
index 827c4773285..10c951d3ccf 100644
--- a/doc/misc/trampver.texi
+++ b/doc/misc/trampver.texi
@@ -8,7 +8,7 @@
 @c In the Tramp GIT, the version numbers are auto-frobbed from
 @c tramp.el, and the bug report address is auto-frobbed from
 @c configure.ac.
-@set trampver 2.5.1-pre
+@set trampver 2.5.1
 @set trampurl https://www.gnu.org/software/tramp/
 @set tramp-bug-report-address tramp-devel@@gnu.org
 @set emacsver 25.1
diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el
index aacf83e663f..7fb0ff57808 100644
--- a/lisp/net/tramp-adb.el
+++ b/lisp/net/tramp-adb.el
@@ -549,8 +549,7 @@ But handle the case, if the \"test\" command is not available."
       (when (and append (file-exists-p filename))
 	(copy-file filename tmpfile 'ok)
 	(set-file-modes tmpfile (logior (or (file-modes tmpfile) 0) #o0600)))
-      (tramp-run-real-handler
-       #'write-region (list start end tmpfile append 'no-message lockname))
+      (write-region start end tmpfile append 'no-message lockname)
       (with-tramp-progress-reporter
         v 3 (format-message
              "Moving tmp file `%s' to `%s'" tmpfile filename)
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index b613ad3f8e7..ebd0fbfd2d9 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -3225,7 +3225,6 @@ implementation will be used."
       (run-hooks 'tramp-handle-file-local-copy-hook)
       tmpfile)))
 
-;; CCC grok LOCKNAME
 (defun tramp-sh-handle-write-region
   (start end filename &optional append visit lockname mustbenew)
   "Like `write-region' for Tramp files."
@@ -3254,9 +3253,7 @@ implementation will be used."
 		  (or (file-directory-p localname)
 		      (file-writable-p localname)))))
 	  ;; Short track: if we are on the local host, we can run directly.
-	  (tramp-run-real-handler
-	   #'write-region
-	   (list start end localname append 'no-message lockname))
+	  (write-region start end localname append 'no-message lockname)
 
 	(let* ((modes (tramp-default-file-modes
 		       filename (and (eq mustbenew 'excl) 'nofollow)))
@@ -3289,13 +3286,10 @@ implementation will be used."
 	  ;; file.  We call `set-visited-file-modtime' ourselves later
 	  ;; on.  We must ensure that `file-coding-system-alist'
 	  ;; matches `tmpfile'.
-	  (let (file-name-handler-alist
-		(file-coding-system-alist
+	  (let ((file-coding-system-alist
 		 (tramp-find-file-name-coding-system-alist filename tmpfile)))
 	    (condition-case err
-		(tramp-run-real-handler
-		 #'write-region
-		 (list start end tmpfile append 'no-message lockname))
+		(write-region start end tmpfile append 'no-message lockname)
 	      ((error quit)
 	       (setq tramp-temp-buffer-file-name nil)
 	       (delete-file tmpfile)
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index c3b088aebb7..ee7e0cf2c3b 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -4393,8 +4393,7 @@ of."
       ;; We say `no-message' here because we don't want the visited file
       ;; modtime data to be clobbered from the temp file.  We call
       ;; `set-visited-file-modtime' ourselves later on.
-      (tramp-run-real-handler
-       #'write-region (list start end tmpfile append 'no-message lockname))
+      (write-region start end tmpfile append 'no-message lockname)
       (condition-case nil
 	  (rename-file tmpfile filename 'ok-if-already-exists)
 	(error
diff --git a/lisp/net/trampver.el b/lisp/net/trampver.el
index abd92219b27..e6cf4c6ac53 100644
--- a/lisp/net/trampver.el
+++ b/lisp/net/trampver.el
@@ -7,7 +7,7 @@
 ;; Maintainer: Michael Albinus <michael.albinus@gmx.de>
 ;; Keywords: comm, processes
 ;; Package: tramp
-;; Version: 2.5.1-pre
+;; Version: 2.5.1
 ;; Package-Requires: ((emacs "25.1"))
 ;; Package-Type: multi
 ;; URL: https://www.gnu.org/software/tramp/
@@ -40,7 +40,7 @@
 ;; ./configure" to change them.
 
 ;;;###tramp-autoload
-(defconst tramp-version "2.5.1-pre"
+(defconst tramp-version "2.5.1"
   "This version of Tramp.")
 
 ;;;###tramp-autoload
@@ -76,7 +76,7 @@
 ;; Check for Emacs version.
 (let ((x   (if (not (string-lessp emacs-version "25.1"))
       "ok"
-    (format "Tramp 2.5.1-pre is not fit for %s"
+    (format "Tramp 2.5.1 is not fit for %s"
             (replace-regexp-in-string "\n" "" (emacs-version))))))
   (unless (string-equal "ok" x) (error "%s" x)))
 
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el
index 37cd7011618..6aa8629f334 100644
--- a/test/lisp/net/tramp-tests.el
+++ b/test/lisp/net/tramp-tests.el
@@ -6280,8 +6280,9 @@ Use the `ls' command."
 		      x ""))
              (not (string-empty-p x))
 	     ;; ?\n and ?/ shouldn't be part of any file name.  ?\t,
-	     ;; ?. and ?? do not work for "smb" method.
-	     (replace-regexp-in-string "[\t\n/.?]" "" x)))
+	     ;; ?. and ?? do not work for "smb" method.  " " does not
+	     ;; work at begin or end of the string for MS Windows.
+	     (replace-regexp-in-string "[ \t\n/.?]" "" x)))
 	  language-info-alist)))))))
 
 (ert-deftest tramp-test41-utf8 ()
-- 
2.39.5