mercurial/changelog.py
changeset 34398 e51c8ffa1ffa
parent 34296 3c9691728237
child 34441 50474f0b3f1b
equal deleted inserted replaced
34397:765eb17a7eb8 34398:e51c8ffa1ffa
     5 # This software may be used and distributed according to the terms of the
     5 # This software may be used and distributed according to the terms of the
     6 # GNU General Public License version 2 or any later version.
     6 # GNU General Public License version 2 or any later version.
     7 
     7 
     8 from __future__ import absolute_import
     8 from __future__ import absolute_import
     9 
     9 
    10 import collections
       
    11 
       
    12 from .i18n import _
    10 from .i18n import _
    13 from .node import (
    11 from .node import (
    14     bin,
    12     bin,
    15     hex,
    13     hex,
    16     nullid,
    14     nullid,
       
    15 )
       
    16 from .thirdparty import (
       
    17     attr,
    17 )
    18 )
    18 
    19 
    19 from . import (
    20 from . import (
    20     encoding,
    21     encoding,
    21     error,
    22     error,
   140         if name != target:
   141         if name != target:
   141             return opener(name, mode)
   142             return opener(name, mode)
   142         return appender(opener, name, mode, buf)
   143         return appender(opener, name, mode, buf)
   143     return _delay
   144     return _delay
   144 
   145 
   145 _changelogrevision = collections.namedtuple(u'changelogrevision',
   146 @attr.s
   146                                             (u'manifest', u'user', u'date',
   147 class _changelogrevision(object):
   147                                              u'files', u'description',
   148     # Extensions might modify _defaultextra, so let the constructor below pass
   148                                              u'extra'))
   149     # it in
       
   150     extra = attr.ib()
       
   151     manifest = attr.ib(default=nullid)
       
   152     user = attr.ib(default='')
       
   153     date = attr.ib(default=(0, 0))
       
   154     files = attr.ib(default=[])
       
   155     description = attr.ib(default='')
   149 
   156 
   150 class changelogrevision(object):
   157 class changelogrevision(object):
   151     """Holds results of a parsed changelog revision.
   158     """Holds results of a parsed changelog revision.
   152 
   159 
   153     Changelog revisions consist of multiple pieces of data, including
   160     Changelog revisions consist of multiple pieces of data, including
   160         u'_text',
   167         u'_text',
   161     )
   168     )
   162 
   169 
   163     def __new__(cls, text):
   170     def __new__(cls, text):
   164         if not text:
   171         if not text:
   165             return _changelogrevision(
   172             return _changelogrevision(extra=_defaultextra)
   166                 manifest=nullid,
       
   167                 user='',
       
   168                 date=(0, 0),
       
   169                 files=[],
       
   170                 description='',
       
   171                 extra=_defaultextra,
       
   172             )
       
   173 
   173 
   174         self = super(changelogrevision, cls).__new__(cls)
   174         self = super(changelogrevision, cls).__new__(cls)
   175         # We could return here and implement the following as an __init__.
   175         # We could return here and implement the following as an __init__.
   176         # But doing it here is equivalent and saves an extra function call.
   176         # But doing it here is equivalent and saves an extra function call.
   177 
   177