##// END OF EJS Templates
exchange: support sorting URLs by client-side preferences...
Gregory Szorc -
r26648:c347d532 default
parent child Browse files
Show More
@@ -1622,7 +1622,7 b' def _maybeapplyclonebundle(pullop):'
1622 'operator)\n'))
1622 'operator)\n'))
1623 return
1623 return
1624
1624
1625 # TODO sort entries by user preferences.
1625 entries = sortclonebundleentries(repo.ui, entries)
1626
1626
1627 url = entries[0]['URL']
1627 url = entries[0]['URL']
1628 repo.ui.status(_('applying clone bundle from %s\n') % url)
1628 repo.ui.status(_('applying clone bundle from %s\n') % url)
@@ -1700,6 +1700,51 b' def filterclonebundleentries(repo, entri'
1700
1700
1701 return newentries
1701 return newentries
1702
1702
1703 def sortclonebundleentries(ui, entries):
1704 # experimental config: experimental.clonebundleprefers
1705 prefers = ui.configlist('experimental', 'clonebundleprefers', default=[])
1706 if not prefers:
1707 return list(entries)
1708
1709 prefers = [p.split('=', 1) for p in prefers]
1710
1711 # Our sort function.
1712 def compareentry(a, b):
1713 for prefkey, prefvalue in prefers:
1714 avalue = a.get(prefkey)
1715 bvalue = b.get(prefkey)
1716
1717 # Special case for b missing attribute and a matches exactly.
1718 if avalue is not None and bvalue is None and avalue == prefvalue:
1719 return -1
1720
1721 # Special case for a missing attribute and b matches exactly.
1722 if bvalue is not None and avalue is None and bvalue == prefvalue:
1723 return 1
1724
1725 # We can't compare unless attribute present on both.
1726 if avalue is None or bvalue is None:
1727 continue
1728
1729 # Same values should fall back to next attribute.
1730 if avalue == bvalue:
1731 continue
1732
1733 # Exact matches come first.
1734 if avalue == prefvalue:
1735 return -1
1736 if bvalue == prefvalue:
1737 return 1
1738
1739 # Fall back to next attribute.
1740 continue
1741
1742 # If we got here we couldn't sort by attributes and prefers. Fall
1743 # back to index order.
1744 return 0
1745
1746 return sorted(entries, cmp=compareentry)
1747
1703 def trypullbundlefromurl(ui, repo, url):
1748 def trypullbundlefromurl(ui, repo, url):
1704 """Attempt to apply a bundle from a URL."""
1749 """Attempt to apply a bundle from a URL."""
1705 lock = repo.lock()
1750 lock = repo.lock()
@@ -261,3 +261,97 b' Python <2.7.9 will filter SNI URLs'
261 searching for changes
261 searching for changes
262 no changes found
262 no changes found
263 #endif
263 #endif
264
265 Set up manifest for testing preferences
266 (Remember, the TYPE does not have to match reality - the URL is
267 important)
268
269 $ cp full.hg gz-a.hg
270 $ cp full.hg gz-b.hg
271 $ cp full.hg bz2-a.hg
272 $ cp full.hg bz2-b.hg
273 $ cat > server/.hg/clonebundles.manifest << EOF
274 > http://localhost:$HGPORT1/gz-a.hg BUNDLESPEC=gzip-v2 extra=a
275 > http://localhost:$HGPORT1/bz2-a.hg BUNDLESPEC=bzip2-v2 extra=a
276 > http://localhost:$HGPORT1/gz-b.hg BUNDLESPEC=gzip-v2 extra=b
277 > http://localhost:$HGPORT1/bz2-b.hg BUNDLESPEC=bzip2-v2 extra=b
278 > EOF
279
280 Preferring an undefined attribute will take first entry
281
282 $ hg --config experimental.clonebundleprefers=foo=bar clone -U http://localhost:$HGPORT prefer-foo
283 applying clone bundle from http://localhost:$HGPORT1/gz-a.hg
284 adding changesets
285 adding manifests
286 adding file changes
287 added 2 changesets with 2 changes to 2 files
288 finished applying clone bundle
289 searching for changes
290 no changes found
291
292 Preferring bz2 type will download first entry of that type
293
294 $ hg --config experimental.clonebundleprefers=COMPRESSION=bzip2 clone -U http://localhost:$HGPORT prefer-bz
295 applying clone bundle from http://localhost:$HGPORT1/bz2-a.hg
296 adding changesets
297 adding manifests
298 adding file changes
299 added 2 changesets with 2 changes to 2 files
300 finished applying clone bundle
301 searching for changes
302 no changes found
303
304 Preferring multiple values of an option works
305
306 $ hg --config experimental.clonebundleprefers=COMPRESSION=unknown,COMPRESSION=bzip2 clone -U http://localhost:$HGPORT prefer-multiple-bz
307 applying clone bundle from http://localhost:$HGPORT1/bz2-a.hg
308 adding changesets
309 adding manifests
310 adding file changes
311 added 2 changesets with 2 changes to 2 files
312 finished applying clone bundle
313 searching for changes
314 no changes found
315
316 Sorting multiple values should get us back to original first entry
317
318 $ hg --config experimental.clonebundleprefers=BUNDLESPEC=unknown,BUNDLESPEC=gzip-v2,BUNDLESPEC=bzip2-v2 clone -U http://localhost:$HGPORT prefer-multiple-gz
319 applying clone bundle from http://localhost:$HGPORT1/gz-a.hg
320 adding changesets
321 adding manifests
322 adding file changes
323 added 2 changesets with 2 changes to 2 files
324 finished applying clone bundle
325 searching for changes
326 no changes found
327
328 Preferring multiple attributes has correct order
329
330 $ hg --config experimental.clonebundleprefers=extra=b,BUNDLESPEC=bzip2-v2 clone -U http://localhost:$HGPORT prefer-separate-attributes
331 applying clone bundle from http://localhost:$HGPORT1/bz2-b.hg
332 adding changesets
333 adding manifests
334 adding file changes
335 added 2 changesets with 2 changes to 2 files
336 finished applying clone bundle
337 searching for changes
338 no changes found
339
340 Test where attribute is missing from some entries
341
342 $ cat > server/.hg/clonebundles.manifest << EOF
343 > http://localhost:$HGPORT1/gz-a.hg BUNDLESPEC=gzip-v2
344 > http://localhost:$HGPORT1/bz2-a.hg BUNDLESPEC=bzip2-v2
345 > http://localhost:$HGPORT1/gz-b.hg BUNDLESPEC=gzip-v2 extra=b
346 > http://localhost:$HGPORT1/bz2-b.hg BUNDLESPEC=bzip2-v2 extra=b
347 > EOF
348
349 $ hg --config experimental.clonebundleprefers=extra=b clone -U http://localhost:$HGPORT prefer-partially-defined-attribute
350 applying clone bundle from http://localhost:$HGPORT1/gz-b.hg
351 adding changesets
352 adding manifests
353 adding file changes
354 added 2 changesets with 2 changes to 2 files
355 finished applying clone bundle
356 searching for changes
357 no changes found
General Comments 0
You need to be logged in to leave comments. Login now