Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/localrepo.py @ 9032:1fa80c5428b8
compat: use 'key' argument instead of 'cmp' when sorting a list
author | Alejandro Santos <alejolp@alejolp.com> |
---|---|
date | Sun, 05 Jul 2009 11:02:00 +0200 |
parents | 7b19cda0fa10 |
children | 93fe89afc611 |
comparison
equal
deleted
inserted
replaced
9031:3b76321aa0de | 9032:1fa80c5428b8 |
---|---|
1707 def identity(x): | 1707 def identity(x): |
1708 return x | 1708 return x |
1709 | 1709 |
1710 # A function generating function. Sets up an environment for the | 1710 # A function generating function. Sets up an environment for the |
1711 # inner function. | 1711 # inner function. |
1712 def cmp_by_rev_func(revlog): | 1712 def revkey(revlog): |
1713 # Compare two nodes by their revision number in the environment's | 1713 # Key to sort a node by it's revision number in the environment's |
1714 # revision history. Since the revision number both represents the | 1714 # revision history. Since the revision number both represents the |
1715 # most efficient order to read the nodes in, and represents a | 1715 # most efficient order to read the nodes in, and represents a |
1716 # topological sorting of the nodes, this function is often useful. | 1716 # topological sorting of the nodes, this function is often useful. |
1717 def cmp_by_rev(a, b): | 1717 def revlog_sort_key(x): |
1718 return cmp(revlog.rev(a), revlog.rev(b)) | 1718 return revlog.rev(x) |
1719 return cmp_by_rev | 1719 return revlog_sort_key |
1720 | 1720 |
1721 # If we determine that a particular file or manifest node must be a | 1721 # If we determine that a particular file or manifest node must be a |
1722 # node that the recipient of the changegroup will already have, we can | 1722 # node that the recipient of the changegroup will already have, we can |
1723 # also assume the recipient will have all the parents. This function | 1723 # also assume the recipient will have all the parents. This function |
1724 # prunes them from the set of missing nodes. | 1724 # prunes them from the set of missing nodes. |
1725 def prune_parents(revlog, hasset, msngset): | 1725 def prune_parents(revlog, hasset, msngset): |
1726 haslst = list(hasset) | 1726 haslst = list(hasset) |
1727 haslst.sort(cmp_by_rev_func(revlog)) | 1727 haslst.sort(key=revkey(revlog)) |
1728 for node in haslst: | 1728 for node in haslst: |
1729 parentlst = [p for p in revlog.parents(node) if p != nullid] | 1729 parentlst = [p for p in revlog.parents(node) if p != nullid] |
1730 while parentlst: | 1730 while parentlst: |
1731 n = parentlst.pop() | 1731 n = parentlst.pop() |
1732 if n not in hasset: | 1732 if n not in hasset: |
1872 # calling our functions back. | 1872 # calling our functions back. |
1873 prune_manifests() | 1873 prune_manifests() |
1874 add_extra_nodes(1, msng_mnfst_set) | 1874 add_extra_nodes(1, msng_mnfst_set) |
1875 msng_mnfst_lst = msng_mnfst_set.keys() | 1875 msng_mnfst_lst = msng_mnfst_set.keys() |
1876 # Sort the manifestnodes by revision number. | 1876 # Sort the manifestnodes by revision number. |
1877 msng_mnfst_lst.sort(cmp_by_rev_func(mnfst)) | 1877 msng_mnfst_lst.sort(key=revkey(mnfst)) |
1878 # Create a generator for the manifestnodes that calls our lookup | 1878 # Create a generator for the manifestnodes that calls our lookup |
1879 # and data collection functions back. | 1879 # and data collection functions back. |
1880 group = mnfst.group(msng_mnfst_lst, lookup_manifest_link, | 1880 group = mnfst.group(msng_mnfst_lst, lookup_manifest_link, |
1881 filenode_collector(changedfiles)) | 1881 filenode_collector(changedfiles)) |
1882 for chnk in group: | 1882 for chnk in group: |
1910 # otherwise don't bother. | 1910 # otherwise don't bother. |
1911 if len(msng_filenode_lst) > 0: | 1911 if len(msng_filenode_lst) > 0: |
1912 yield changegroup.chunkheader(len(fname)) | 1912 yield changegroup.chunkheader(len(fname)) |
1913 yield fname | 1913 yield fname |
1914 # Sort the filenodes by their revision # | 1914 # Sort the filenodes by their revision # |
1915 msng_filenode_lst.sort(cmp_by_rev_func(filerevlog)) | 1915 msng_filenode_lst.sort(key=revkey(filerevlog)) |
1916 # Create a group generator and only pass in a changenode | 1916 # Create a group generator and only pass in a changenode |
1917 # lookup function as we need to collect no information | 1917 # lookup function as we need to collect no information |
1918 # from filenodes. | 1918 # from filenodes. |
1919 group = filerevlog.group(msng_filenode_lst, | 1919 group = filerevlog.group(msng_filenode_lst, |
1920 lookup_filenode_link_func(fname)) | 1920 lookup_filenode_link_func(fname)) |