diff --git a/hgext/churn.py b/hgext/churn.py --- a/hgext/churn.py +++ b/hgext/churn.py @@ -143,8 +143,8 @@ def churn(ui, repo, *pats, **opts): if not rate: return - sortfn = ((not opts.get('sort')) and (lambda a, b: cmp(b[1], a[1])) or None) - rate.sort(sortfn) + sortkey = ((not opts.get('sort')) and (lambda x: -x[1]) or None) + rate.sort(key=sortkey) maxcount = float(max([v for k, v in rate])) maxname = max([len(k) for k, v in rate]) diff --git a/hgext/convert/cvsps.py b/hgext/convert/cvsps.py --- a/hgext/convert/cvsps.py +++ b/hgext/convert/cvsps.py @@ -12,13 +12,6 @@ import cPickle as pickle from mercurial import util from mercurial.i18n import _ -def listsort(list, key): - "helper to sort by key in Python 2.3" - try: - list.sort(key=key) - except TypeError: - list.sort(lambda l, r: cmp(key(l), key(r))) - class logentry(object): '''Class logentry has the following attributes: .author - author name as CVS knows it @@ -419,7 +412,7 @@ def createlog(ui, directory=None, root=" if len(log) % 100 == 0: ui.status(util.ellipsis('%d %s' % (len(log), e.file), 80)+'\n') - listsort(log, key=lambda x:(x.rcs, x.revision)) + log.sort(key=lambda x: (x.rcs, x.revision)) # find parent revisions of individual files versions = {} @@ -435,7 +428,7 @@ def createlog(ui, directory=None, root=" if cache: if log: # join up the old and new logs - listsort(log, key=lambda x:x.date) + log.sort(key=lambda x: x.date) if oldlog and oldlog[-1].date >= log[0].date: raise logerror('Log cache overlaps with new log entries,' @@ -484,7 +477,7 @@ def createchangeset(ui, log, fuzz=60, me # Merge changesets - listsort(log, key=lambda x:(x.comment, x.author, x.branch, x.date)) + log.sort(key=lambda x: (x.comment, x.author, x.branch, x.date)) changesets = [] files = set() diff --git a/hgext/mq.py b/hgext/mq.py --- a/hgext/mq.py +++ b/hgext/mq.py @@ -1541,7 +1541,7 @@ class queue(object): raise util.Abort(_('option "-r" not valid when importing ' 'files')) rev = cmdutil.revrange(repo, rev) - rev.sort(lambda x, y: cmp(y, x)) + rev.sort(reverse=True) if (len(files) > 1 or len(rev) > 1) and patchname: raise util.Abort(_('option "-n" not valid when importing multiple ' 'patches')) @@ -2334,7 +2334,7 @@ def select(ui, repo, *args, **opts): if ui.verbose: guards['NONE'] = noguards guards = guards.items() - guards.sort(lambda a, b: cmp(a[0][1:], b[0][1:])) + guards.sort(key=lambda x: x[0][1:]) if guards: ui.note(_('guards in series file:\n')) for guard, count in guards: diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -1709,14 +1709,14 @@ class localrepository(repo.repository): # A function generating function. Sets up an environment for the # inner function. - def cmp_by_rev_func(revlog): - # Compare two nodes by their revision number in the environment's + def revkey(revlog): + # Key to sort a node by it's revision number in the environment's # revision history. Since the revision number both represents the # most efficient order to read the nodes in, and represents a # topological sorting of the nodes, this function is often useful. - def cmp_by_rev(a, b): - return cmp(revlog.rev(a), revlog.rev(b)) - return cmp_by_rev + def revlog_sort_key(x): + return revlog.rev(x) + return revlog_sort_key # If we determine that a particular file or manifest node must be a # node that the recipient of the changegroup will already have, we can @@ -1724,7 +1724,7 @@ class localrepository(repo.repository): # prunes them from the set of missing nodes. def prune_parents(revlog, hasset, msngset): haslst = list(hasset) - haslst.sort(cmp_by_rev_func(revlog)) + haslst.sort(key=revkey(revlog)) for node in haslst: parentlst = [p for p in revlog.parents(node) if p != nullid] while parentlst: @@ -1874,7 +1874,7 @@ class localrepository(repo.repository): add_extra_nodes(1, msng_mnfst_set) msng_mnfst_lst = msng_mnfst_set.keys() # Sort the manifestnodes by revision number. - msng_mnfst_lst.sort(cmp_by_rev_func(mnfst)) + msng_mnfst_lst.sort(key=revkey(mnfst)) # Create a generator for the manifestnodes that calls our lookup # and data collection functions back. group = mnfst.group(msng_mnfst_lst, lookup_manifest_link, @@ -1912,7 +1912,7 @@ class localrepository(repo.repository): yield changegroup.chunkheader(len(fname)) yield fname # Sort the filenodes by their revision # - msng_filenode_lst.sort(cmp_by_rev_func(filerevlog)) + msng_filenode_lst.sort(key=revkey(filerevlog)) # Create a group generator and only pass in a changenode # lookup function as we need to collect no information # from filenodes. diff --git a/mercurial/lsprof.py b/mercurial/lsprof.py --- a/mercurial/lsprof.py +++ b/mercurial/lsprof.py @@ -26,12 +26,10 @@ class Stats(object): """XXX docstring""" if crit not in profiler_entry.__dict__: raise ValueError("Can't sort by %s" % crit) - self.data.sort(lambda b, a: cmp(getattr(a, crit), - getattr(b, crit))) + self.data.sort(key=lambda x: getattr(x, crit), reverse=True) for e in self.data: if e.calls: - e.calls.sort(lambda b, a: cmp(getattr(a, crit), - getattr(b, crit))) + e.calls.sort(key=lambda x: getattr(x, crit), reverse=True) def pprint(self, top=None, file=None, limit=None, climit=None): """XXX docstring""" diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -325,10 +325,6 @@ class patchfile(object): # looks through the hash and finds candidate lines. The # result is a list of line numbers sorted based on distance # from linenum - def sorter(a, b): - vala = abs(a - linenum) - valb = abs(b - linenum) - return cmp(vala, valb) try: cand = self.hash[l] @@ -337,7 +333,7 @@ class patchfile(object): if len(cand) > 1: # resort our list of potentials forward then back. - cand.sort(sorter) + cand.sort(key=lambda x: abs(x - linenum)) return cand def hashlines(self):