diff --git a/svn/common.py b/svn/common.py index a53e2f2..a80b5b0 100644 --- a/svn/common.py +++ b/svn/common.py @@ -242,10 +242,6 @@ def log_default(self, timestamp_from_dt=None, timestamp_to_dt=None, do_combine=True) root = xml.etree.ElementTree.fromstring(result) - named_fields = ['date', 'msg', 'revision', 'author', 'changelist'] - c = collections.namedtuple( - 'LogEntry', - named_fields) # Merge history can create nested log entries, so use iter instead of findall for e in root.iter('logentry'): @@ -266,13 +262,16 @@ def log_default(self, timestamp_from_dt=None, timestamp_to_dt=None, if changelist is True: cl = [] for ch in e.findall('paths/path'): - cl.append((ch.attrib['action'], ch.text)) + # namedtuple fields cannot have hyphens, so replace with underscores + attribs = svn.constants.ChangelistEntryDefaults.copy() + attribs.update({key.replace('-', '_'): val for key, val in ch.attrib.items()}) + cl.append(svn.constants.ChangelistEntry(path=ch.text, **attribs)) log_entry['changelist'] = cl else: log_entry['changelist'] = None - yield c(**log_entry) + yield svn.constants.LogEntry(**log_entry) def export(self, to_path, revision=None, force=False): cmd = [] diff --git a/svn/constants.py b/svn/constants.py index 7bfee62..48be1e6 100644 --- a/svn/constants.py +++ b/svn/constants.py @@ -1,3 +1,5 @@ +import collections + # Kinds K_DIR = 'dir' @@ -43,3 +45,13 @@ 'replaced': ST_REPLACED, 'unversioned': ST_UNVERSIONED, } + +fields = ['date', 'msg', 'revision', 'author', 'changelist'] +LogEntry = collections.namedtuple('LogEntry', fields) + +# code in https://svn.apache.org/repos/asf/subversion/trunk/subversion/svn/log-cmd.c +# uses hyphens for the attribute names, but namedtuple field names cannot have hyphens +fields = ['action', 'path', 'copyfrom_path', 'copyfrom_rev', 'kind', 'text_mods', 'prop_mods'] +ChangelistEntry = collections.namedtuple('ChangelistEntry', fields) +# NOTE: Python 2's namedtuple doesn't allow for defaults, so need a defaults dict +ChangelistEntryDefaults = {x: None for x in fields[2:]}