# HG changeset patch # User Martin von Zweigbergk # Date 1412976756 25200 # Node ID cb4449921a1d0120428dee395b124376903ccbc4 # Parent 3b8e6c095239b1a4c6641302519a3d0c7f54057a status: create class for status lists Callers of various status() methods (on dirstate, context, repo) get a tuple of 7 elements, where each element is a list of files. This results in lots of uses of indexes where names would be much more readable. For example, "status.ignored" seems clearer than "status[4]" [1]. So, let's introduce a simple named tuple containing the 7 status fields: modified, added, removed, deleted, unknown, ignored, clean. This patch introduces the class and updates the status methods to return instances of it. Later patches will update the callers. [1] Did you even notice that it should have been "status[5]"? (tweaked by mpm to introduce the class in scmutil and only change one user) diff -r 3b8e6c095239 -r cb4449921a1d mercurial/dirstate.py --- a/mercurial/dirstate.py Fri Oct 03 21:21:20 2014 -0700 +++ b/mercurial/dirstate.py Fri Oct 10 14:32:36 2014 -0700 @@ -908,8 +908,8 @@ elif state == 'r': radd(fn) - return (lookup, (modified, added, removed, deleted, unknown, ignored, - clean)) + return (lookup, scmutil.status(modified, added, removed, deleted, + unknown, ignored, clean)) def matches(self, match): ''' diff -r 3b8e6c095239 -r cb4449921a1d mercurial/scmutil.py --- a/mercurial/scmutil.py Fri Oct 03 21:21:20 2014 -0700 +++ b/mercurial/scmutil.py Fri Oct 10 14:32:36 2014 -0700 @@ -20,6 +20,50 @@ systemrcpath = scmplatform.systemrcpath userrcpath = scmplatform.userrcpath +class status(tuple): + '''Named tuple with a list of files per status. The 'deleted', 'unknown' + and 'ignored' properties are only relevant to the working copy. + ''' + + __slots__ = () + + def __new__(cls, modified, added, removed, deleted, unknown, ignored, + clean): + return tuple.__new__(cls, (modified, added, removed, deleted, unknown, + ignored, clean)) + + @property + def modified(self): + return self[0] + + @property + def added(self): + return self[1] + + @property + def removed(self): + return self[2] + + @property + def deleted(self): + return self[3] + + @property + def unknown(self): + return self[4] + + @property + def ignored(self): + return self[5] + + @property + def clean(self): + return self[6] + + def __repr__(self, *args, **kwargs): + return (('') % self) + def itersubrepos(ctx1, ctx2): """find subrepos in ctx1 or ctx2""" # Create a (subpath, ctx) mapping where we prefer subpaths from