##// END OF EJS Templates
exchange: use rich class for sorting clone bundle entries...
Gregory Szorc -
r30685:95325386 default
parent child Browse files
Show More
@@ -1902,18 +1902,22 b' def filterclonebundleentries(repo, entri'
1902
1902
1903 return newentries
1903 return newentries
1904
1904
1905 def sortclonebundleentries(ui, entries):
1905 class clonebundleentry(object):
1906 prefers = ui.configlist('ui', 'clonebundleprefers', default=[])
1906 """Represents an item in a clone bundles manifest.
1907 if not prefers:
1907
1908 return list(entries)
1908 This rich class is needed to support sorting since sorted() in Python 3
1909 doesn't support ``cmp`` and our comparison is complex enough that ``key=``
1910 won't work.
1911 """
1909
1912
1910 prefers = [p.split('=', 1) for p in prefers]
1913 def __init__(self, value, prefers):
1914 self.value = value
1915 self.prefers = prefers
1911
1916
1912 # Our sort function.
1917 def _cmp(self, other):
1913 def compareentry(a, b):
1918 for prefkey, prefvalue in self.prefers:
1914 for prefkey, prefvalue in prefers:
1919 avalue = self.value.get(prefkey)
1915 avalue = a.get(prefkey)
1920 bvalue = other.value.get(prefkey)
1916 bvalue = b.get(prefkey)
1917
1921
1918 # Special case for b missing attribute and a matches exactly.
1922 # Special case for b missing attribute and a matches exactly.
1919 if avalue is not None and bvalue is None and avalue == prefvalue:
1923 if avalue is not None and bvalue is None and avalue == prefvalue:
@@ -1944,7 +1948,33 b' def sortclonebundleentries(ui, entries):'
1944 # back to index order.
1948 # back to index order.
1945 return 0
1949 return 0
1946
1950
1947 return sorted(entries, cmp=compareentry)
1951 def __lt__(self, other):
1952 return self._cmp(other) < 0
1953
1954 def __gt__(self, other):
1955 return self._cmp(other) > 0
1956
1957 def __eq__(self, other):
1958 return self._cmp(other) == 0
1959
1960 def __le__(self, other):
1961 return self._cmp(other) <= 0
1962
1963 def __ge__(self, other):
1964 return self._cmp(other) >= 0
1965
1966 def __ne__(self, other):
1967 return self._cmp(other) != 0
1968
1969 def sortclonebundleentries(ui, entries):
1970 prefers = ui.configlist('ui', 'clonebundleprefers', default=[])
1971 if not prefers:
1972 return list(entries)
1973
1974 prefers = [p.split('=', 1) for p in prefers]
1975
1976 items = sorted(clonebundleentry(v, prefers) for v in entries)
1977 return [i.value for i in items]
1948
1978
1949 def trypullbundlefromurl(ui, repo, url):
1979 def trypullbundlefromurl(ui, repo, url):
1950 """Attempt to apply a bundle from a URL."""
1980 """Attempt to apply a bundle from a URL."""
General Comments 0
You need to be logged in to leave comments. Login now