Mercurial > public > mercurial-scm > hg
comparison mercurial/exchange.py @ 35264:a1e70c1dbec0
bookmark: use the 'bookmarks' bundle2 part to push bookmark update (issue5165)
We use the new binary parts we introduced earlier to exchange bookmark. The
payload is a bit more compact since we use binary and the length of bookmarks
is no longer constrained to 255.
.. fix:: Issue 5165
Bookmark, whose name is longer than 255, can again be exchanged again
between 4.4+ client and servers.
author | Boris Feld <boris.feld@octobus.net> |
---|---|
date | Tue, 17 Oct 2017 12:38:13 +0200 |
parents | 3fd5f05a5b87 |
children | cb4dcd7fabe7 |
comparison
equal
deleted
inserted
replaced
35263:ae79d878702b | 35264:a1e70c1dbec0 |
---|---|
895 def _pushb2bookmarks(pushop, bundler): | 895 def _pushb2bookmarks(pushop, bundler): |
896 """handle bookmark push through bundle2""" | 896 """handle bookmark push through bundle2""" |
897 if 'bookmarks' in pushop.stepsdone: | 897 if 'bookmarks' in pushop.stepsdone: |
898 return | 898 return |
899 b2caps = bundle2.bundle2caps(pushop.remote) | 899 b2caps = bundle2.bundle2caps(pushop.remote) |
900 if 'pushkey' in b2caps: | 900 |
901 legacy = pushop.repo.ui.configlist('devel', 'legacy.exchange') | |
902 legacybooks = 'bookmarks' in legacy | |
903 | |
904 if not legacybooks and 'bookmarks' in b2caps: | |
905 return _pushb2bookmarkspart(pushop, bundler) | |
906 elif 'pushkey' in b2caps: | |
901 return _pushb2bookmarkspushkey(pushop, bundler) | 907 return _pushb2bookmarkspushkey(pushop, bundler) |
908 | |
909 def _bmaction(old, new): | |
910 """small utility for bookmark pushing""" | |
911 if not old: | |
912 return 'export' | |
913 elif not new: | |
914 return 'delete' | |
915 return 'update' | |
916 | |
917 def _pushb2bookmarkspart(pushop, bundler): | |
918 pushop.stepsdone.add('bookmarks') | |
919 if not pushop.outbookmarks: | |
920 return | |
921 | |
922 allactions = [] | |
923 data = [] | |
924 for book, old, new in pushop.outbookmarks: | |
925 new = bin(new) | |
926 data.append((book, new)) | |
927 allactions.append((book, _bmaction(old, new))) | |
928 checkdata = bookmod.binaryencode(data) | |
929 bundler.newpart('bookmarks', data=checkdata) | |
930 | |
931 def handlereply(op): | |
932 ui = pushop.ui | |
933 # if success | |
934 for book, action in allactions: | |
935 ui.status(bookmsgmap[action][0] % book) | |
936 | |
937 return handlereply | |
902 | 938 |
903 def _pushb2bookmarkspushkey(pushop, bundler): | 939 def _pushb2bookmarkspushkey(pushop, bundler): |
904 pushop.stepsdone.add('bookmarks') | 940 pushop.stepsdone.add('bookmarks') |
905 part2book = [] | 941 part2book = [] |
906 enc = pushkey.encode | 942 enc = pushkey.encode |