comparison mercurial/context.py @ 21592:16f62b4203b1

committablectx: simplify caching the status Previously, workingctx had custom variables for the unknown, ignored, and clean list of files of status. These then got moved to committablectx and, after the refactoring of localrepo.status, are no longer needed. We, therefore, simplify the whole mess. As a bonus, we are able to remove the need for having 'assert'.
author Sean Farley <sean.michael.farley@gmail.com>
date Thu, 24 Apr 2014 17:31:20 -0500
parents e5deefcaa12b
children b2d6bc6f9c3e
comparison
equal deleted inserted replaced
21591:660ef8ca8c3c 21592:16f62b4203b1
890 if date: 890 if date:
891 self._date = util.parsedate(date) 891 self._date = util.parsedate(date)
892 if user: 892 if user:
893 self._user = user 893 self._user = user
894 if changes: 894 if changes:
895 self._status = list(changes[:4]) 895 self._status = changes
896 self._unknown = changes[4]
897 self._ignored = changes[5]
898 self._clean = changes[6]
899 else:
900 self._unknown = None
901 self._ignored = None
902 self._clean = None
903 896
904 self._extra = {} 897 self._extra = {}
905 if extra: 898 if extra:
906 self._extra = extra.copy() 899 self._extra = extra.copy()
907 if 'branch' not in self._extra: 900 if 'branch' not in self._extra:
972 else: 965 else:
973 getman = lambda f: man 966 getman = lambda f: man
974 967
975 copied = self._repo.dirstate.copies() 968 copied = self._repo.dirstate.copies()
976 ff = self._flagfunc 969 ff = self._flagfunc
977 modified, added, removed, deleted = self._status 970 modified, added, removed, deleted = self._status[:4]
978 for i, l in (("a", added), ("m", modified)): 971 for i, l in (("a", added), ("m", modified)):
979 for f in l: 972 for f in l:
980 orig = copied.get(f, f) 973 orig = copied.get(f, f)
981 man[f] = getman(orig).get(orig, nullid) + i 974 man[f] = getman(orig).get(orig, nullid) + i
982 try: 975 try:
990 983
991 return man 984 return man
992 985
993 @propertycache 986 @propertycache
994 def _status(self): 987 def _status(self):
995 return self._repo.status()[:4] 988 return self._repo.status()
996 989
997 @propertycache 990 @propertycache
998 def _user(self): 991 def _user(self):
999 return self._repo.ui.username() 992 return self._repo.ui.username()
1000 993
1021 def removed(self): 1014 def removed(self):
1022 return self._status[2] 1015 return self._status[2]
1023 def deleted(self): 1016 def deleted(self):
1024 return self._status[3] 1017 return self._status[3]
1025 def unknown(self): 1018 def unknown(self):
1026 assert self._unknown is not None # must call status first 1019 return self._status[4]
1027 return self._unknown
1028 def ignored(self): 1020 def ignored(self):
1029 assert self._ignored is not None # must call status first 1021 return self._status[5]
1030 return self._ignored
1031 def clean(self): 1022 def clean(self):
1032 assert self._clean is not None # must call status first 1023 return self._status[6]
1033 return self._clean
1034 def branch(self): 1024 def branch(self):
1035 return encoding.tolocal(self._extra['branch']) 1025 return encoding.tolocal(self._extra['branch'])
1036 def closesbranch(self): 1026 def closesbranch(self):
1037 return 'close' in self._extra 1027 return 'close' in self._extra
1038 def extra(self): 1028 def extra(self):
1393 _status property will implicitly read the status using its default 1383 _status property will implicitly read the status using its default
1394 arguments.""" 1384 arguments."""
1395 listignored, listclean, listunknown = ignored, clean, unknown 1385 listignored, listclean, listunknown = ignored, clean, unknown
1396 s = self._dirstatestatus(match=match, ignored=listignored, 1386 s = self._dirstatestatus(match=match, ignored=listignored,
1397 clean=listclean, unknown=listunknown) 1387 clean=listclean, unknown=listunknown)
1398 modified, added, removed, deleted, unknown, ignored, clean = s 1388
1399 1389 s[0] = self._filtersuspectsymlink(s[0])
1400 modified = self._filtersuspectsymlink(modified) 1390 self._status = s
1401 1391 return s
1402 self._unknown = self._ignored = self._clean = None
1403 if listunknown:
1404 self._unknown = unknown
1405 if listignored:
1406 self._ignored = ignored
1407 if listclean:
1408 self._clean = clean
1409 self._status = modified, added, removed, deleted
1410
1411 return modified, added, removed, deleted, unknown, ignored, clean
1412 1392
1413 1393
1414 class committablefilectx(basefilectx): 1394 class committablefilectx(basefilectx):
1415 """A committablefilectx provides common functionality for a file context 1395 """A committablefilectx provides common functionality for a file context
1416 that wants the ability to commit, e.g. workingfilectx or memfilectx.""" 1396 that wants the ability to commit, e.g. workingfilectx or memfilectx."""