comparison mercurial/context.py @ 8209:a1a5a57efe90

replace util.sort with sorted built-in This is marginally faster for small and moderately-sized lists
author Matt Mackall <mpm@selenic.com>
date Sun, 26 Apr 2009 16:50:44 -0500
parents dd8d5be57d65
children 46293a0c7e9f
comparison
equal deleted inserted replaced
8208:32a2a1e244f1 8209:a1a5a57efe90
77 77
78 def __getitem__(self, key): 78 def __getitem__(self, key):
79 return self.filectx(key) 79 return self.filectx(key)
80 80
81 def __iter__(self): 81 def __iter__(self):
82 for f in util.sort(self._manifest): 82 for f in sorted(self._manifest):
83 yield f 83 yield f
84 84
85 def changeset(self): return self._changeset 85 def changeset(self): return self._changeset
86 def manifest(self): return self._manifest 86 def manifest(self): return self._manifest
87 87
164 if ffn == fn or fn.startswith("%s/" % ffn): 164 if ffn == fn or fn.startswith("%s/" % ffn):
165 del fdict[ffn] 165 del fdict[ffn]
166 break 166 break
167 if match(fn): 167 if match(fn):
168 yield fn 168 yield fn
169 for fn in util.sort(fdict): 169 for fn in sorted(fdict):
170 if match.bad(fn, 'No such file in rev ' + str(self)) and match(fn): 170 if match.bad(fn, 'No such file in rev ' + str(self)) and match(fn):
171 yield fn 171 yield fn
172 172
173 class filectx(object): 173 class filectx(object):
174 """A filecontext object makes access to data related to a particular 174 """A filecontext object makes access to data related to a particular
410 for f in files: 410 for f in files:
411 fn = [(n.rev(), n) for n in needed if n._path == f] 411 fn = [(n.rev(), n) for n in needed if n._path == f]
412 visit.extend(fn) 412 visit.extend(fn)
413 413
414 hist = {} 414 hist = {}
415 for r, f in util.sort(visit): 415 for r, f in sorted(visit):
416 curr = decorate(f.data(), f) 416 curr = decorate(f.data(), f)
417 for p in parents(f): 417 for p in parents(f):
418 if p != nullid: 418 if p != nullid:
419 curr = pair(hist[p], curr) 419 curr = pair(hist[p], curr)
420 # trim the history of unneeded revs 420 # trim the history of unneeded revs
555 555
556 def user(self): return self._user or self._repo.ui.username() 556 def user(self): return self._user or self._repo.ui.username()
557 def date(self): return self._date 557 def date(self): return self._date
558 def description(self): return self._text 558 def description(self): return self._text
559 def files(self): 559 def files(self):
560 return util.sort(self._status[0] + self._status[1] + self._status[2]) 560 return sorted(self._status[0] + self._status[1] + self._status[2])
561 561
562 def modified(self): return self._status[0] 562 def modified(self): return self._status[0]
563 def added(self): return self._status[1] 563 def added(self): return self._status[1]
564 def removed(self): return self._status[2] 564 def removed(self): return self._status[2]
565 def deleted(self): return self._status[3] 565 def deleted(self): return self._status[3]
604 def ancestor(self, c2): 604 def ancestor(self, c2):
605 """return the ancestor context of self and c2""" 605 """return the ancestor context of self and c2"""
606 return self._parents[0].ancestor(c2) # punt on two parents for now 606 return self._parents[0].ancestor(c2) # punt on two parents for now
607 607
608 def walk(self, match): 608 def walk(self, match):
609 return util.sort(self._repo.dirstate.walk(match, True, False).keys()) 609 return sorted(self._repo.dirstate.walk(match, True, False))
610 610
611 class workingfilectx(filectx): 611 class workingfilectx(filectx):
612 """A workingfilectx object makes access to data related to a particular 612 """A workingfilectx object makes access to data related to a particular
613 file in the working directory convenient.""" 613 file in the working directory convenient."""
614 def __init__(self, repo, path, filelog=None, workingctx=None): 614 def __init__(self, repo, path, filelog=None, workingctx=None):
725 self._date = date and util.parsedate(date) or util.makedate() 725 self._date = date and util.parsedate(date) or util.makedate()
726 self._user = user 726 self._user = user
727 parents = [(p or nullid) for p in parents] 727 parents = [(p or nullid) for p in parents]
728 p1, p2 = parents 728 p1, p2 = parents
729 self._parents = [changectx(self._repo, p) for p in (p1, p2)] 729 self._parents = [changectx(self._repo, p) for p in (p1, p2)]
730 files = util.sort(set(files)) 730 files = sorted(set(files))
731 self._status = [files, [], [], [], []] 731 self._status = [files, [], [], [], []]
732 self._filectxfn = filectxfn 732 self._filectxfn = filectxfn
733 733
734 self._extra = extra and extra.copy() or {} 734 self._extra = extra and extra.copy() or {}
735 if 'branch' not in self._extra: 735 if 'branch' not in self._extra: