comparison mercurial/exchange.py @ 42924:e0bf41b83cef

exchange: avoid unnecessary conversion of bookmark nodes to hex (API) Differential Revision: https://phab.mercurial-scm.org/D6830
author Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
date Sun, 08 Sep 2019 20:10:32 -0400
parents 08fce968d00b
children 9fd7710d9ae2
comparison
equal deleted inserted replaced
42923:a7abc6081bc5 42924:e0bf41b83cef
10 import collections 10 import collections
11 import hashlib 11 import hashlib
12 12
13 from .i18n import _ 13 from .i18n import _
14 from .node import ( 14 from .node import (
15 bin,
16 hex, 15 hex,
17 nullid, 16 nullid,
18 nullrev, 17 nullrev,
19 ) 18 )
20 from .thirdparty import ( 19 from .thirdparty import (
439 self.outdatedphases = None 438 self.outdatedphases = None
440 # phases changes that must be pushed if changeset push fails 439 # phases changes that must be pushed if changeset push fails
441 self.fallbackoutdatedphases = None 440 self.fallbackoutdatedphases = None
442 # outgoing obsmarkers 441 # outgoing obsmarkers
443 self.outobsmarkers = set() 442 self.outobsmarkers = set()
444 # outgoing bookmarks 443 # outgoing bookmarks, list of (bm, oldnode | '', newnode | '')
445 self.outbookmarks = [] 444 self.outbookmarks = []
446 # transaction manager 445 # transaction manager
447 self.trmanager = None 446 self.trmanager = None
448 # map { pushkey partid -> callback handling failure} 447 # map { pushkey partid -> callback handling failure}
449 # used to handle exception from mandatory pushkey part failure 448 # used to handle exception from mandatory pushkey part failure
714 explicit = {repo._bookmarks.expandname(bookmark) 713 explicit = {repo._bookmarks.expandname(bookmark)
715 for bookmark in pushop.bookmarks} 714 for bookmark in pushop.bookmarks}
716 715
717 remotebookmark = bookmod.unhexlifybookmarks(remotebookmark) 716 remotebookmark = bookmod.unhexlifybookmarks(remotebookmark)
718 comp = bookmod.comparebookmarks(repo, repo._bookmarks, remotebookmark) 717 comp = bookmod.comparebookmarks(repo, repo._bookmarks, remotebookmark)
719
720 def safehex(x):
721 if x is None:
722 return x
723 return hex(x)
724
725 def hexifycompbookmarks(bookmarks):
726 return [(b, safehex(scid), safehex(dcid))
727 for (b, scid, dcid) in bookmarks]
728
729 comp = [hexifycompbookmarks(marks) for marks in comp]
730 return _processcompared(pushop, ancestors, explicit, remotebookmark, comp) 718 return _processcompared(pushop, ancestors, explicit, remotebookmark, comp)
731 719
732 def _processcompared(pushop, pushed, explicit, remotebms, comp): 720 def _processcompared(pushop, pushed, explicit, remotebms, comp):
733 """take decision on bookmarks to push to the remote repo 721 """take decision on bookmarks to push to the remote repo
734 722
875 hasbookmarkcheck = 'bookmarks' in b2caps 863 hasbookmarkcheck = 'bookmarks' in b2caps
876 if not (pushop.outbookmarks and hasbookmarkcheck): 864 if not (pushop.outbookmarks and hasbookmarkcheck):
877 return 865 return
878 data = [] 866 data = []
879 for book, old, new in pushop.outbookmarks: 867 for book, old, new in pushop.outbookmarks:
880 old = bin(old)
881 data.append((book, old)) 868 data.append((book, old))
882 checkdata = bookmod.binaryencode(data) 869 checkdata = bookmod.binaryencode(data)
883 bundler.newpart('check:bookmarks', data=checkdata) 870 bundler.newpart('check:bookmarks', data=checkdata)
884 871
885 @b2partsgenerator('check-phases') 872 @b2partsgenerator('check-phases')
1049 1036
1050 allactions = [] 1037 allactions = []
1051 data = [] 1038 data = []
1052 for book, old, new in pushop.outbookmarks: 1039 for book, old, new in pushop.outbookmarks:
1053 _abortonsecretctx(pushop, new, book) 1040 _abortonsecretctx(pushop, new, book)
1054 new = bin(new)
1055 data.append((book, new)) 1041 data.append((book, new))
1056 allactions.append((book, _bmaction(old, new))) 1042 allactions.append((book, _bmaction(old, new)))
1057 checkdata = bookmod.binaryencode(data) 1043 checkdata = bookmod.binaryencode(data)
1058 bundler.newpart('bookmarks', data=checkdata) 1044 bundler.newpart('bookmarks', data=checkdata)
1059 1045
1081 for book, old, new in pushop.outbookmarks: 1067 for book, old, new in pushop.outbookmarks:
1082 _abortonsecretctx(pushop, new, book) 1068 _abortonsecretctx(pushop, new, book)
1083 part = bundler.newpart('pushkey') 1069 part = bundler.newpart('pushkey')
1084 part.addparam('namespace', enc('bookmarks')) 1070 part.addparam('namespace', enc('bookmarks'))
1085 part.addparam('key', enc(book)) 1071 part.addparam('key', enc(book))
1086 part.addparam('old', enc(old)) 1072 part.addparam('old', enc(hex(old)))
1087 part.addparam('new', enc(new)) 1073 part.addparam('new', enc(hex(new)))
1088 action = 'update' 1074 action = 'update'
1089 if not old: 1075 if not old:
1090 action = 'export' 1076 action = 'export'
1091 elif not new: 1077 elif not new:
1092 action = 'delete' 1078 action = 'delete'
1337 1323
1338 with remote.commandexecutor() as e: 1324 with remote.commandexecutor() as e:
1339 r = e.callcommand('pushkey', { 1325 r = e.callcommand('pushkey', {
1340 'namespace': 'bookmarks', 1326 'namespace': 'bookmarks',
1341 'key': b, 1327 'key': b,
1342 'old': old, 1328 'old': hex(old),
1343 'new': new, 1329 'new': hex(new),
1344 }).result() 1330 }).result()
1345 1331
1346 if r: 1332 if r:
1347 ui.status(bookmsgmap[action][0] % b) 1333 ui.status(bookmsgmap[action][0] % b)
1348 else: 1334 else: