Author: futatuki
Date: Fri Oct 23 09:31:25 2020
New Revision: 1882780

URL: http://svn.apache.org/viewvc?rev=1882780&view=rev
Log:
Avoid UnicodeDecodeError when svnlook returns error message.

* tools/backup/hot-backup.py.in
  (): Import locale moule for locale.getpreferredencoding.
  (get_youngest_revision): Use str for I/O in subprocess.Popen on Python 3. 

Modified:
    subversion/trunk/tools/backup/hot-backup.py.in

Modified: subversion/trunk/tools/backup/hot-backup.py.in
URL: 
http://svn.apache.org/viewvc/subversion/trunk/tools/backup/hot-backup.py.in?rev=1882780&r1=1882779&r2=1882780&view=diff
==============================================================================
--- subversion/trunk/tools/backup/hot-backup.py.in (original)
+++ subversion/trunk/tools/backup/hot-backup.py.in Fri Oct 23 09:31:25 2020
@@ -36,6 +36,7 @@
 ######################################################################
 
 import sys, os, getopt, stat, re, time, shutil, subprocess
+import locale
 import functools
 
 ######################################################################
@@ -204,10 +205,18 @@ def get_youngest_revision():
   """Examine the repository REPO_DIR using the svnlook binary
   specified by SVNLOOK, and return the youngest revision."""
 
-  p = subprocess.Popen([svnlook, 'youngest', '--', repo_dir],
-                       stdin=subprocess.PIPE,
-                       stdout=subprocess.PIPE,
-                       stderr=subprocess.PIPE)
+  if b'' == '':
+    p = subprocess.Popen([svnlook, 'youngest', '--', repo_dir],
+                         stdin=subprocess.PIPE,
+                         stdout=subprocess.PIPE,
+                         stderr=subprocess.PIPE)
+  else:
+    p = subprocess.Popen([svnlook, 'youngest', '--', repo_dir],
+                         stdin=subprocess.PIPE,
+                         stdout=subprocess.PIPE,
+                         stderr=subprocess.PIPE,
+                         errors='backslashreplace', # foolproof
+                         encoding=locale.getpreferredencoding())
   infile, outfile, errfile = p.stdin, p.stdout, p.stderr
 
   stdout_lines = outfile.readlines()
@@ -220,7 +229,7 @@ def get_youngest_revision():
     raise Exception("Unable to find the youngest revision for repository '%s'"
                     ": %s" % (repo_dir, stderr_lines[0].rstrip()))
 
-  return stdout_lines[0].strip().decode()
+  return stdout_lines[0].strip()
 
 ######################################################################
 # Main


Reply via email to