Patchwork D868: changelog: use attrs instead of namedtuple

login
register
mail settings
Submitter phabricator
Date Oct. 1, 2017, 11:34 a.m.
Message ID <604b39c9fb5ce6cfdbc2fd738a2da42e@localhost.localdomain>
Download mbox | patch
Permalink /patch/24321/
State Not Applicable
Headers show

Comments

phabricator - Oct. 1, 2017, 11:34 a.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGe51c8ffa1ffa: changelog: use attrs instead of namedtuple (authored by sid0, committed by ).

CHANGED PRIOR TO COMMIT
  https://phab.mercurial-scm.org/D868?vs=2232&id=2252#toc

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D868?vs=2232&id=2252

REVISION DETAIL
  https://phab.mercurial-scm.org/D868

AFFECTED FILES
  mercurial/changelog.py

CHANGE DETAILS




To: sid0, #hg-reviewers, durin42
Cc: mercurial-devel

Patch

diff --git a/mercurial/changelog.py b/mercurial/changelog.py
--- a/mercurial/changelog.py
+++ b/mercurial/changelog.py
@@ -7,14 +7,15 @@ 
 
 from __future__ import absolute_import
 
-import collections
-
 from .i18n import _
 from .node import (
     bin,
     hex,
     nullid,
 )
+from .thirdparty import (
+    attr,
+)
 
 from . import (
     encoding,
@@ -142,10 +143,16 @@ 
         return appender(opener, name, mode, buf)
     return _delay
 
-_changelogrevision = collections.namedtuple(u'changelogrevision',
-                                            (u'manifest', u'user', u'date',
-                                             u'files', u'description',
-                                             u'extra'))
+@attr.s
+class _changelogrevision(object):
+    # Extensions might modify _defaultextra, so let the constructor below pass
+    # it in
+    extra = attr.ib()
+    manifest = attr.ib(default=nullid)
+    user = attr.ib(default='')
+    date = attr.ib(default=(0, 0))
+    files = attr.ib(default=[])
+    description = attr.ib(default='')
 
 class changelogrevision(object):
     """Holds results of a parsed changelog revision.
@@ -162,14 +169,7 @@ 
 
     def __new__(cls, text):
         if not text:
-            return _changelogrevision(
-                manifest=nullid,
-                user='',
-                date=(0, 0),
-                files=[],
-                description='',
-                extra=_defaultextra,
-            )
+            return _changelogrevision(extra=_defaultextra)
 
         self = super(changelogrevision, cls).__new__(cls)
         # We could return here and implement the following as an __init__.