Commits

anatoly techtonik committed b7714ef

LogEntry data container for parsed log message
just for clarity

  • Participants
  • Parent commits b38257e

Comments (0)

Files changed (1)

File hgsvn/svnclient.py

 )
 
 
+class LogEntry(dict):
+    # container for parsed log data
+    def __init__(self, *args, **kwargs):
+        super(LogEntry, self).__init__(*args, **kwargs)
+        # would be nice if Python allowed less verbose syntax
+        # for these
+        self.revision = self.get("revision")
+        self.author   = self.get("author")
+        self.date     = self.get("date", None)
+        self.message  = self.get("message", "")
+        self.changed_paths = self.get("changed_paths", [])
+        # changed_paths contains a list of dicts
+        #    'path': path,
+        #    'action': action,  # 'A', 'M' or 'D'
+        #    'copyfrom_path': copyfrom-path,
+        #    'copyfrom_revision': int(rev),
+    
+    def __setattr__(self, name, value):
+        # both attribute and dictionary access should work
+        dict.__setattr__(self, name, value)
+        dict.__setitem__(self, name, value)
+    
+    def __setitem__(self, name, value):
+        # both attribute and dictionary access should work
+        dict.__setitem__(self, name, value)
+        dict.__setattr__(self, name, value)
+
 def strip_forbidden_xml_chars(xml_string):
     """
     Given an XML string, strips forbidden characters as per the XML spec.
 def parse_svn_log_xml(xml_string):
     """
     Parse the XML output from an "svn log" command and extract useful information
-    as a list of dicts (one per log changeset).
+    as a list of LogEntry objects (one per log changeset).
+
+    :return: list of LogEntry objects
     """
     l = []
     xml_string = strip_forbidden_xml_chars(xml_string)
     tree = ET.fromstring(xml_string)
     for entry in tree.findall('logentry'):
-        d = {}
+        d = LogEntry()
         d['revision'] = int(entry.get('revision'))
         # Some revisions don't have authors, most notably the first revision
         # in a repository.