subrepo: svn xml output is much easier to parse
authorPatrick Mezard <pmezard@gmail.com>
Thu, 21 Jan 2010 15:13:40 +0100
changeset 10272 886858b834da
parent 10271 9b38bec5dc29
child 10273 e898bc7810ad
subrepo: svn xml output is much easier to parse That's especially true with status flags: there are different fields and values for regular changes, meta changes, externals changes and externals meta changes.
mercurial/subrepo.py
--- a/mercurial/subrepo.py	Thu Jan 21 15:13:03 2010 +0100
+++ b/mercurial/subrepo.py	Thu Jan 21 15:13:40 2010 +0100
@@ -5,7 +5,7 @@
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
-import errno, os, re
+import errno, os, re, xml.dom.minidom
 from i18n import _
 import config, util, node, error
 hg = None
@@ -275,24 +275,23 @@
         return retdata
 
     def _wcrev(self):
-        info = self._svncommand(['info'])
-        mat = re.search('Revision: ([\d]+)\n', info)
-        if not mat:
+        output = self._svncommand(['info', '--xml'])
+        doc = xml.dom.minidom.parseString(output)
+        entries = doc.getElementsByTagName('entry')
+        if not entries:
             return 0
-        return mat.groups()[0]
-
-    def _url(self):
-        info = self._svncommand(['info'])
-        mat = re.search('URL: ([^\n]+)\n', info)
-        if not mat:
-            return 0
-        return mat.groups()[0]
+        return int(entries[0].getAttribute('revision') or 0)
 
     def _wcclean(self):
-        status = self._svncommand(['status'])
-        status = '\n'.join([s for s in status.splitlines() if s[0] != '?'])
-        if status.strip():
-            return False
+        output = self._svncommand(['status', '--xml'])
+        doc = xml.dom.minidom.parseString(output)
+        for s in doc.getElementsByTagName('wc-status'):
+            st = s.getAttribute('item')
+            if st and st != 'unversioned':
+                return False
+            props = s.getAttribute('props')
+            if props and props != 'none':
+                return False
         return True
 
     def dirty(self):