comparison mercurial/scmutil.py @ 43654:c5548b0b6847

scmutil: convert status data object from a tuple to an attrs (API) We've been pushing towards the property names for a while, and the subclassing of the tuple confuses pytype. Rather than bend over backwards to try and annotate the tuple subclass, let's just use attrs here. Differential Revision: https://phab.mercurial-scm.org/D7406
author Augie Fackler <augie@google.com>
date Thu, 14 Nov 2019 13:38:17 -0500
parents 0b7733719d21
children 5b90a050082b
comparison
equal deleted inserted replaced
43653:6186c2a53ea5 43654:c5548b0b6847
25 short, 25 short,
26 wdirid, 26 wdirid,
27 wdirrev, 27 wdirrev,
28 ) 28 )
29 from .pycompat import getattr 29 from .pycompat import getattr
30 30 from .thirdparty import attr
31 from . import ( 31 from . import (
32 copies as copiesmod, 32 copies as copiesmod,
33 encoding, 33 encoding,
34 error, 34 error,
35 match as matchmod, 35 match as matchmod,
60 parsers = policy.importmod('parsers') 60 parsers = policy.importmod('parsers')
61 61
62 termsize = scmplatform.termsize 62 termsize = scmplatform.termsize
63 63
64 64
65 class status(tuple): 65 @attr.s(slots=True, repr=False)
66 '''Named tuple with a list of files per status. The 'deleted', 'unknown' 66 class status(object):
67 and 'ignored' properties are only relevant to the working copy. 67 '''Struct with a list of files per status.
68
69 The 'deleted', 'unknown' and 'ignored' properties are only
70 relevant to the working copy.
68 ''' 71 '''
69 72
70 __slots__ = () 73 modified = attr.ib(default=list)
71 74 added = attr.ib(default=list)
72 def __new__( 75 removed = attr.ib(default=list)
73 cls, modified, added, removed, deleted, unknown, ignored, clean 76 deleted = attr.ib(default=list)
74 ): 77 unknown = attr.ib(default=list)
75 return tuple.__new__( 78 ignored = attr.ib(default=list)
76 cls, (modified, added, removed, deleted, unknown, ignored, clean) 79 clean = attr.ib(default=list)
77 ) 80
78 81 def __iter__(self):
79 @property 82 yield self.modified
80 def modified(self): 83 yield self.added
81 '''files that have been modified''' 84 yield self.removed
82 return self[0] 85 yield self.deleted
83 86 yield self.unknown
84 @property 87 yield self.ignored
85 def added(self): 88 yield self.clean
86 '''files that have been added''' 89
87 return self[1] 90 def __repr__(self):
88
89 @property
90 def removed(self):
91 '''files that have been removed'''
92 return self[2]
93
94 @property
95 def deleted(self):
96 '''files that are in the dirstate, but have been deleted from the
97 working copy (aka "missing")
98 '''
99 return self[3]
100
101 @property
102 def unknown(self):
103 '''files not in the dirstate that are not ignored'''
104 return self[4]
105
106 @property
107 def ignored(self):
108 '''files not in the dirstate that are ignored (by _dirignore())'''
109 return self[5]
110
111 @property
112 def clean(self):
113 '''files that have not been modified'''
114 return self[6]
115
116 def __repr__(self, *args, **kwargs):
117 return ( 91 return (
118 r'<status modified=%s, added=%s, removed=%s, deleted=%s, ' 92 r'<status modified=%s, added=%s, removed=%s, deleted=%s, '
119 r'unknown=%s, ignored=%s, clean=%s>' 93 r'unknown=%s, ignored=%s, clean=%s>'
120 ) % tuple(pycompat.sysstr(stringutil.pprint(v)) for v in self) 94 ) % tuple(pycompat.sysstr(stringutil.pprint(v)) for v in self)
121 95