[meld/Python3] vc: Fix incorrect Subversion XML encoding assumptions (bgo#767810)



commit 0262d3fe3aee06aed134d00ed99e783f5cd63948
Author: Vasily Galkin <galkin-vv ya ru>
Date:   Mon Jun 20 20:37:59 2016 +0300

    vc: Fix incorrect Subversion XML encoding assumptions (bgo#767810)
    
    svn status --xml output is always in utf8 encoding. So it can't be
    treated as text stream in locale encoding to work fine on windows
    systems with non-utf8 locale encoding. Elementtree parses binary xml
    streams just fine.

 meld/vc/_vc.py |   12 +++++++++---
 meld/vc/svn.py |    3 ++-
 2 files changed, 11 insertions(+), 4 deletions(-)
---
diff --git a/meld/vc/_vc.py b/meld/vc/_vc.py
index 94d3311..d0499e1 100644
--- a/meld/vc/_vc.py
+++ b/meld/vc/_vc.py
@@ -381,10 +381,16 @@ class InvalidVCRevision(ValueError):
             (self.vc.NAME, self.revision, self.error)
 
 
-# Return the stdout output of a given command
-def popen(cmd, cwd=None):
+def popen(cmd, cwd=None, use_locale_encoding=True):
+    """Return the stdout output of a given command as a stream.
+
+    If use_locale_encoding is True, the output is parsed to unicode
+    text stream with universal newlines.
+    If use_locale_encoding is False output is treated as binary stream.
+    """
     process = subprocess.Popen(
-        cmd, cwd=cwd, stdout=subprocess.PIPE, universal_newlines=True)
+        cmd, cwd=cwd, stdout=subprocess.PIPE,
+        universal_newlines=use_locale_encoding)
     return process.stdout
 
 
diff --git a/meld/vc/svn.py b/meld/vc/svn.py
index e73bfe6..6ff20f4 100644
--- a/meld/vc/svn.py
+++ b/meld/vc/svn.py
@@ -175,9 +175,10 @@ class Vc(_vc.Vc):
     def _update_tree_state_cache(self, path):
         while 1:
             try:
+                # "svn --xml" outputs utf8, even with Windows non-utf8 locale
                 proc = _vc.popen(
                     [self.CMD, "status", "-v", "--xml", path],
-                    cwd=self.location)
+                    cwd=self.location, use_locale_encoding=False)
                 tree = ElementTree.parse(proc)
                 break
             except OSError as e:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]