[PATCH v2] Change test suite to read file properties in XML format

Michael Haggerty <[email protected]>
Newsgroups gmane.comp.version-control.subversion.cvs2svn.devel
Message-ID <[email protected]>
James Abbatiello wrote:
> On Mon, Jul 27, 2009 at 11:15 AM, Michael Haggerty<[email protected]> wrote:
>> [...]
>> But even though SVN outputs '\r\n' on Windows, I still don't understand
>> how the '\r\n' characters get through in the test suite.
> 
> This had me stumped for a while too.
> C:>svn --version
> svn, version 1.6.3 (r38063)
>    compiled Jun 18 2009, 12:57:17
> ...
> 
> C:>svn proplist --verbose --xml svntest
> <?xml version="1.0"?>
> <properties>
> <target
>    path="svntest">
> <property
>    name="svn:ignore">*.pyc&#13;
> *.o&#13;
> *~&#13;
> .*~&#13;
> &#13;
> </property>
> </target>
> </properties>
> 
> The '\r\n' sequences are being folded to '\n'.  But then the XML
> parser turns '&#13\n' into '\r\n' in the final output.

Yuck.  I wonder whether the output contains '&#13;\n' or '&#13;\r\n'
(i.e., does the output contain one or two extraneous CR characters?

In any case, I'm defeated.  Attached is a patch like the previous one,
except that it also smashes all EOL combinations into '\n'.  Feedback is
welcome, especially from Windows users.

Michael

[[[
Read svn properties in XML rather than text format in test suite.

This makes the routine shorter and more robust to strange property
values and to format changes in the text output format.

* subversion/tests/cmdline/svntest/tree.py
  (get_props): Read svn properties via "svn proplist -v" using the
  "--xml" option.
]]]

------------------------------------------------------
http://cvs2svn.tigris.org/ds/viewMessage.do?dsForumId=1667&dsMessageId=2376089

To unsubscribe from this discussion, e-mail: [[email protected]].
proplist-xml-2.diff (text/x-diff, 3.3 KB)
Index: subversion/tests/cmdline/svntest/tree.py
===================================================================
--- subversion/tests/cmdline/svntest/tree.py	(revision 38480)
+++ subversion/tests/cmdline/svntest/tree.py	(working copy)
@@ -32,6 +32,8 @@
 else:
   # Python <3.0
   from StringIO import StringIO
+from xml.dom.minidom import parseString
+import base64
 
 import svntest
 
@@ -487,7 +489,6 @@
   return root_node
 
 
-
 # helper for build_tree_from_wc()
 def get_props(paths):
   """Return a hash of hashes of props for PATHS, using the svn client. Convert
@@ -499,47 +500,43 @@
   # respecting the black-box paradigm.
 
   files = {}
-  filename = None
   exit_code, output, errput = svntest.main.run_svn(1,
                                                    "proplist",
                                                    "--verbose",
+                                                   "--xml",
                                                    *paths)
 
-  properties_on_re = re.compile("^Properties on '(.+)':$")
+  output = (line for line in output if not line.startswith('DBG:'))
+  # Convert all end-of-line variants into a single LF:
+  output = ((line.rstrip('\n\r') + '\n') for line in output)
+  dom = parseString(''.join(output))
+  target_nodes = dom.getElementsByTagName('target')
+  for target_node in target_nodes:
+    filename = target_node.attributes['path'].nodeValue
+    file_props = {}
+    for property_node in target_node.getElementsByTagName('property'):
+      name = property_node.attributes['name'].nodeValue
+      if property_node.hasChildNodes():
+        text_node = property_node.firstChild
+        value = text_node.nodeValue
+      else:
+        value = ''
+      try:
+        encoding = property_node.attributes['encoding'].nodeValue
+        if encoding == 'base64':
+          value = base64.b64decode(value)
+        else:
+          raise Exception("Unknown encoding '%s' for file '%s' property '%s'"
+                          % (encoding, filename, name,))
+      except KeyError:
+        pass
+      file_props[name] = value
+    files[filename] = file_props
 
-  # Parse the output
-  for line in output:
-    if line.startswith('DBG:'):
-      continue
-    line = line.rstrip('\r\n')  # ignore stdout's EOL sequence
-
-    match = properties_on_re.match(line)
-    if match:
-      filename = match.group(1)
-
-    elif line.startswith('    '):
-      # It's (part of) the value (strip the indentation)
-      if filename is None:
-        raise Exception("Missing 'Properties on' line: '"+line+"'")
-      files.setdefault(filename, {})[name] += line[4:] + '\n'
-
-    elif line.startswith('  '):
-      # It's the name
-      name = line[2:]  # strip the indentation
-      if filename is None:
-        raise Exception("Missing 'Properties on' line: '"+line+"'")
-      files.setdefault(filename, {})[name] = ''
-
-    else:
-      raise Exception("Malformed line from proplist: '"+line+"'")
-
-  # Strip, from each property value, the final new-line that we added
-  for filename in files:
-    for name in files[filename]:
-      files[filename][name] = files[filename][name][:-1]
-
+  dom.unlink()
   return files
 
+
 ### ridiculous function. callers should do this one line themselves.
 def get_text(path):
   "Return a string with the textual contents of a file at PATH."
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.