Details
Details
- Reviewers
- None
- Group Reviewers
hg-reviewers - Commits
- rHGe0bf41b83cef: exchange: avoid unnecessary conversion of bookmark nodes to hex (API)
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
| hg-reviewers |
| Lint Skipped |
| Unit Tests Skipped |
| Path | Packages | |||
|---|---|---|---|---|
| M | mercurial/exchange.py (23 lines) |
| Commit | Parents | Author | Summary | Date |
|---|---|---|---|---|
| 4a75f99fdf26 | 14d06a7b028c | Valentin Gatien-Baron | Sep 8 2019, 8:10 PM |
| Status | Author | Revision | |
|---|---|---|---|
| Closed | valentin.gatienbaron | ||
| Closed | valentin.gatienbaron | ||
| Closed | valentin.gatienbaron |
| # summary of the remote phase situation | # summary of the remote phase situation | ||||
| self.remotephases = None | self.remotephases = None | ||||
| # phases changes that must be pushed along side the changesets | # phases changes that must be pushed along side the changesets | ||||
| self.outdatedphases = None | self.outdatedphases = None | ||||
| # phases changes that must be pushed if changeset push fails | # phases changes that must be pushed if changeset push fails | ||||
| self.fallbackoutdatedphases = None | self.fallbackoutdatedphases = None | ||||
| # outgoing obsmarkers | # outgoing obsmarkers | ||||
| self.outobsmarkers = set() | self.outobsmarkers = set() | ||||
| # outgoing bookmarks | # outgoing bookmarks, list of (bm, oldnode | '', newnode | '') | ||||
| self.outbookmarks = [] | self.outbookmarks = [] | ||||
| # transaction manager | # transaction manager | ||||
| self.trmanager = None | self.trmanager = None | ||||
| # map { pushkey partid -> callback handling failure} | # map { pushkey partid -> callback handling failure} | ||||
| # used to handle exception from mandatory pushkey part failure | # used to handle exception from mandatory pushkey part failure | ||||
| self.pkfailcb = {} | self.pkfailcb = {} | ||||
| # an iterable of pushvars or None | # an iterable of pushvars or None | ||||
| self.pushvars = pushvars | self.pushvars = pushvars | ||||
| remotebookmark = listkeys(remote, 'bookmarks') | remotebookmark = listkeys(remote, 'bookmarks') | ||||
| explicit = {repo._bookmarks.expandname(bookmark) | explicit = {repo._bookmarks.expandname(bookmark) | ||||
| for bookmark in pushop.bookmarks} | for bookmark in pushop.bookmarks} | ||||
| remotebookmark = bookmod.unhexlifybookmarks(remotebookmark) | remotebookmark = bookmod.unhexlifybookmarks(remotebookmark) | ||||
| comp = bookmod.comparebookmarks(repo, repo._bookmarks, remotebookmark) | comp = bookmod.comparebookmarks(repo, repo._bookmarks, remotebookmark) | ||||
| def safehex(x): | |||||
| if x is None: | |||||
| return x | |||||
| return hex(x) | |||||
| def hexifycompbookmarks(bookmarks): | |||||
| return [(b, safehex(scid), safehex(dcid)) | |||||
| for (b, scid, dcid) in bookmarks] | |||||
| comp = [hexifycompbookmarks(marks) for marks in comp] | |||||
| return _processcompared(pushop, ancestors, explicit, remotebookmark, comp) | return _processcompared(pushop, ancestors, explicit, remotebookmark, comp) | ||||
| def _processcompared(pushop, pushed, explicit, remotebms, comp): | def _processcompared(pushop, pushed, explicit, remotebms, comp): | ||||
| """take decision on bookmarks to push to the remote repo | """take decision on bookmarks to push to the remote repo | ||||
| Exists to help extensions alter this behavior. | Exists to help extensions alter this behavior. | ||||
| """ | """ | ||||
| addsrc, adddst, advsrc, advdst, diverge, differ, invalid, same = comp | addsrc, adddst, advsrc, advdst, diverge, differ, invalid, same = comp | ||||
| if not _pushing(pushop) or pushop.force: | if not _pushing(pushop) or pushop.force: | ||||
| return | return | ||||
| b2caps = bundle2.bundle2caps(pushop.remote) | b2caps = bundle2.bundle2caps(pushop.remote) | ||||
| hasbookmarkcheck = 'bookmarks' in b2caps | hasbookmarkcheck = 'bookmarks' in b2caps | ||||
| if not (pushop.outbookmarks and hasbookmarkcheck): | if not (pushop.outbookmarks and hasbookmarkcheck): | ||||
| return | return | ||||
| data = [] | data = [] | ||||
| for book, old, new in pushop.outbookmarks: | for book, old, new in pushop.outbookmarks: | ||||
| old = bin(old) | |||||
| data.append((book, old)) | data.append((book, old)) | ||||
| checkdata = bookmod.binaryencode(data) | checkdata = bookmod.binaryencode(data) | ||||
| bundler.newpart('check:bookmarks', data=checkdata) | bundler.newpart('check:bookmarks', data=checkdata) | ||||
| @b2partsgenerator('check-phases') | @b2partsgenerator('check-phases') | ||||
| def _pushb2checkphases(pushop, bundler): | def _pushb2checkphases(pushop, bundler): | ||||
| """insert phase move checking""" | """insert phase move checking""" | ||||
| if not _pushing(pushop) or pushop.force: | if not _pushing(pushop) or pushop.force: | ||||
| pushop.stepsdone.add('bookmarks') | pushop.stepsdone.add('bookmarks') | ||||
| if not pushop.outbookmarks: | if not pushop.outbookmarks: | ||||
| return | return | ||||
| allactions = [] | allactions = [] | ||||
| data = [] | data = [] | ||||
| for book, old, new in pushop.outbookmarks: | for book, old, new in pushop.outbookmarks: | ||||
| _abortonsecretctx(pushop, new, book) | _abortonsecretctx(pushop, new, book) | ||||
| new = bin(new) | |||||
| data.append((book, new)) | data.append((book, new)) | ||||
| allactions.append((book, _bmaction(old, new))) | allactions.append((book, _bmaction(old, new))) | ||||
| checkdata = bookmod.binaryencode(data) | checkdata = bookmod.binaryencode(data) | ||||
| bundler.newpart('bookmarks', data=checkdata) | bundler.newpart('bookmarks', data=checkdata) | ||||
| def handlereply(op): | def handlereply(op): | ||||
| ui = pushop.ui | ui = pushop.ui | ||||
| # if success | # if success | ||||
| # we should not be called for part we did not generated | # we should not be called for part we did not generated | ||||
| assert False | assert False | ||||
| for book, old, new in pushop.outbookmarks: | for book, old, new in pushop.outbookmarks: | ||||
| _abortonsecretctx(pushop, new, book) | _abortonsecretctx(pushop, new, book) | ||||
| part = bundler.newpart('pushkey') | part = bundler.newpart('pushkey') | ||||
| part.addparam('namespace', enc('bookmarks')) | part.addparam('namespace', enc('bookmarks')) | ||||
| part.addparam('key', enc(book)) | part.addparam('key', enc(book)) | ||||
| part.addparam('old', enc(old)) | part.addparam('old', enc(hex(old))) | ||||
| part.addparam('new', enc(new)) | part.addparam('new', enc(hex(new))) | ||||
| action = 'update' | action = 'update' | ||||
| if not old: | if not old: | ||||
| action = 'export' | action = 'export' | ||||
| elif not new: | elif not new: | ||||
| action = 'delete' | action = 'delete' | ||||
| part2book.append((part.id, book, action)) | part2book.append((part.id, book, action)) | ||||
| pushop.pkfailcb[part.id] = handlefailure | pushop.pkfailcb[part.id] = handlefailure | ||||
| action = 'export' | action = 'export' | ||||
| elif not new: | elif not new: | ||||
| action = 'delete' | action = 'delete' | ||||
| with remote.commandexecutor() as e: | with remote.commandexecutor() as e: | ||||
| r = e.callcommand('pushkey', { | r = e.callcommand('pushkey', { | ||||
| 'namespace': 'bookmarks', | 'namespace': 'bookmarks', | ||||
| 'key': b, | 'key': b, | ||||
| 'old': old, | 'old': hex(old), | ||||
| 'new': new, | 'new': hex(new), | ||||
| }).result() | }).result() | ||||
| if r: | if r: | ||||
| ui.status(bookmsgmap[action][0] % b) | ui.status(bookmsgmap[action][0] % b) | ||||
| else: | else: | ||||
| ui.warn(bookmsgmap[action][1] % b) | ui.warn(bookmsgmap[action][1] % b) | ||||
| # discovery can have set the value form invalid entry | # discovery can have set the value form invalid entry | ||||
| if pushop.bkresult is not None: | if pushop.bkresult is not None: | ||||