comparison mercurial/localrepo.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 d2899a856f9f
children 344751cd8cb8
comparison
equal deleted inserted replaced
8208:32a2a1e244f1 8209:a1a5a57efe90
355 try: 355 try:
356 r = self.changelog.rev(n) 356 r = self.changelog.rev(n)
357 except: 357 except:
358 r = -2 # sort to the beginning of the list if unknown 358 r = -2 # sort to the beginning of the list if unknown
359 l.append((r, t, n)) 359 l.append((r, t, n))
360 return [(t, n) for r, t, n in util.sort(l)] 360 return [(t, n) for r, t, n in sorted(l)]
361 361
362 def nodetags(self, node): 362 def nodetags(self, node):
363 '''return the tags associated with a node''' 363 '''return the tags associated with a node'''
364 if not self.nodetagscache: 364 if not self.nodetagscache:
365 self.nodetagscache = {} 365 self.nodetagscache = {}
859 def _commitctx(self, wctx, force=False, force_editor=False, empty_ok=False, 859 def _commitctx(self, wctx, force=False, force_editor=False, empty_ok=False,
860 use_dirstate=True, update_dirstate=True): 860 use_dirstate=True, update_dirstate=True):
861 tr = None 861 tr = None
862 valid = 0 # don't save the dirstate if this isn't set 862 valid = 0 # don't save the dirstate if this isn't set
863 try: 863 try:
864 commit = util.sort(wctx.modified() + wctx.added()) 864 commit = sorted(wctx.modified() + wctx.added())
865 remove = wctx.removed() 865 remove = wctx.removed()
866 extra = wctx.extra().copy() 866 extra = wctx.extra().copy()
867 branchname = extra['branch'] 867 branchname = extra['branch']
868 user = wctx.user() 868 user = wctx.user()
869 text = wctx.description() 869 text = wctx.description()
917 raise 917 raise
918 else: 918 else:
919 remove.append(f) 919 remove.append(f)
920 920
921 updated, added = [], [] 921 updated, added = [], []
922 for f in util.sort(changed): 922 for f in sorted(changed):
923 if f in m1 or f in m2: 923 if f in m1 or f in m2:
924 updated.append(f) 924 updated.append(f)
925 else: 925 else:
926 added.append(f) 926 added.append(f)
927 927
928 # update manifest 928 # update manifest
929 m1.update(new) 929 m1.update(new)
930 removed = [f for f in util.sort(remove) if f in m1 or f in m2] 930 removed = [f for f in sorted(remove) if f in m1 or f in m2]
931 removed1 = [] 931 removed1 = []
932 932
933 for f in removed: 933 for f in removed:
934 if f in m1: 934 if f in m1:
935 del m1[f] 935 del m1[f]
1218 return True 1218 return True
1219 extras = self.changelog.read(head)[5] 1219 extras = self.changelog.read(head)[5]
1220 return ('close' not in extras) 1220 return ('close' not in extras)
1221 # sort the output in rev descending order 1221 # sort the output in rev descending order
1222 heads = [(-self.changelog.rev(h), h) for h in heads if display(h)] 1222 heads = [(-self.changelog.rev(h), h) for h in heads if display(h)]
1223 return [n for (r, n) in util.sort(heads)] 1223 return [n for (r, n) in sorted(heads)]
1224 1224
1225 def branchheads(self, branch=None, start=None, closed=True): 1225 def branchheads(self, branch=None, start=None, closed=True):
1226 if branch is None: 1226 if branch is None:
1227 branch = self[None].branch() 1227 branch = self[None].branch()
1228 branches = self._branchheads() 1228 branches = self._branchheads()
1877 if isinstance(fname, int): 1877 if isinstance(fname, int):
1878 continue 1878 continue
1879 msng_filenode_set.setdefault(fname, {}) 1879 msng_filenode_set.setdefault(fname, {})
1880 changedfiles[fname] = 1 1880 changedfiles[fname] = 1
1881 # Go through all our files in order sorted by name. 1881 # Go through all our files in order sorted by name.
1882 for fname in util.sort(changedfiles): 1882 for fname in sorted(changedfiles):
1883 filerevlog = self.file(fname) 1883 filerevlog = self.file(fname)
1884 if not len(filerevlog): 1884 if not len(filerevlog):
1885 raise util.Abort(_("empty or missing revlog for %s") % fname) 1885 raise util.Abort(_("empty or missing revlog for %s") % fname)
1886 # Toss out the filenodes that the recipient isn't really 1886 # Toss out the filenodes that the recipient isn't really
1887 # missing. 1887 # missing.
1967 mnfst = self.manifest 1967 mnfst = self.manifest
1968 nodeiter = gennodelst(mnfst) 1968 nodeiter = gennodelst(mnfst)
1969 for chnk in mnfst.group(nodeiter, lookuprevlink_func(mnfst)): 1969 for chnk in mnfst.group(nodeiter, lookuprevlink_func(mnfst)):
1970 yield chnk 1970 yield chnk
1971 1971
1972 for fname in util.sort(changedfiles): 1972 for fname in sorted(changedfiles):
1973 filerevlog = self.file(fname) 1973 filerevlog = self.file(fname)
1974 if not len(filerevlog): 1974 if not len(filerevlog):
1975 raise util.Abort(_("empty or missing revlog for %s") % fname) 1975 raise util.Abort(_("empty or missing revlog for %s") % fname)
1976 nodeiter = gennodelst(filerevlog) 1976 nodeiter = gennodelst(filerevlog)
1977 nodeiter = list(nodeiter) 1977 nodeiter = list(nodeiter)