Mercurial > hg
comparison mercurial/bookmarks.py @ 45942:89a2afe31e82
formating: upgrade to black 20.8b1
This required a couple of small tweaks to un-confuse black, but now it
works. Big formatting changes come from:
* Dramatically improved collection-splitting logic upstream
* Black having a strong (correct IMO) opinion that """ is better than '''
Differential Revision: https://phab.mercurial-scm.org/D9430
author | Augie Fackler <raf@durin42.com> |
---|---|
date | Fri, 27 Nov 2020 17:03:29 -0500 |
parents | 9acbe30953e8 |
children | 6266d19556ad |
comparison
equal
deleted
inserted
replaced
45941:346af7687c6f | 45942:89a2afe31e82 |
---|---|
187 def names(self, node): | 187 def names(self, node): |
188 """Return a sorted list of bookmarks pointing to the specified node""" | 188 """Return a sorted list of bookmarks pointing to the specified node""" |
189 return self._nodemap.get(node, []) | 189 return self._nodemap.get(node, []) |
190 | 190 |
191 def applychanges(self, repo, tr, changes): | 191 def applychanges(self, repo, tr, changes): |
192 """Apply a list of changes to bookmarks | 192 """Apply a list of changes to bookmarks""" |
193 """ | |
194 bmchanges = tr.changes.get(b'bookmarks') | 193 bmchanges = tr.changes.get(b'bookmarks') |
195 for name, node in changes: | 194 for name, node in changes: |
196 old = self._refmap.get(name) | 195 old = self._refmap.get(name) |
197 if node is None: | 196 if node is None: |
198 self._del(name) | 197 self._del(name) |
420 heads.append(n) | 419 heads.append(n) |
421 return heads | 420 return heads |
422 | 421 |
423 | 422 |
424 def calculateupdate(ui, repo): | 423 def calculateupdate(ui, repo): |
425 '''Return a tuple (activemark, movemarkfrom) indicating the active bookmark | 424 """Return a tuple (activemark, movemarkfrom) indicating the active bookmark |
426 and where to move the active bookmark from, if needed.''' | 425 and where to move the active bookmark from, if needed.""" |
427 checkout, movemarkfrom = None, None | 426 checkout, movemarkfrom = None, None |
428 activemark = repo._activebookmark | 427 activemark = repo._activebookmark |
429 if isactivewdirparent(repo): | 428 if isactivewdirparent(repo): |
430 movemarkfrom = repo[b'.'].node() | 429 movemarkfrom = repo[b'.'].node() |
431 elif activemark: | 430 elif activemark: |
507 marks.applychanges(repo, tr, changes) | 506 marks.applychanges(repo, tr, changes) |
508 return True | 507 return True |
509 | 508 |
510 | 509 |
511 def comparebookmarks(repo, srcmarks, dstmarks, targets=None): | 510 def comparebookmarks(repo, srcmarks, dstmarks, targets=None): |
512 '''Compare bookmarks between srcmarks and dstmarks | 511 """Compare bookmarks between srcmarks and dstmarks |
513 | 512 |
514 This returns tuple "(addsrc, adddst, advsrc, advdst, diverge, | 513 This returns tuple "(addsrc, adddst, advsrc, advdst, diverge, |
515 differ, invalid)", each are list of bookmarks below: | 514 differ, invalid)", each are list of bookmarks below: |
516 | 515 |
517 :addsrc: added on src side (removed on dst side, perhaps) | 516 :addsrc: added on src side (removed on dst side, perhaps) |
530 Changeset IDs of tuples in "addsrc", "adddst", "differ" or | 529 Changeset IDs of tuples in "addsrc", "adddst", "differ" or |
531 "invalid" list may be unknown for repo. | 530 "invalid" list may be unknown for repo. |
532 | 531 |
533 If "targets" is specified, only bookmarks listed in it are | 532 If "targets" is specified, only bookmarks listed in it are |
534 examined. | 533 examined. |
535 ''' | 534 """ |
536 | 535 |
537 if targets: | 536 if targets: |
538 bset = set(targets) | 537 bset = set(targets) |
539 else: | 538 else: |
540 srcmarkset = set(srcmarks) | 539 srcmarkset = set(srcmarks) |
583 | 582 |
584 return results | 583 return results |
585 | 584 |
586 | 585 |
587 def _diverge(ui, b, path, localmarks, remotenode): | 586 def _diverge(ui, b, path, localmarks, remotenode): |
588 '''Return appropriate diverged bookmark for specified ``path`` | 587 """Return appropriate diverged bookmark for specified ``path`` |
589 | 588 |
590 This returns None, if it is failed to assign any divergent | 589 This returns None, if it is failed to assign any divergent |
591 bookmark name. | 590 bookmark name. |
592 | 591 |
593 This reuses already existing one with "@number" suffix, if it | 592 This reuses already existing one with "@number" suffix, if it |
594 refers ``remotenode``. | 593 refers ``remotenode``. |
595 ''' | 594 """ |
596 if b == b'@': | 595 if b == b'@': |
597 b = b'' | 596 b = b'' |
598 # try to use an @pathalias suffix | 597 # try to use an @pathalias suffix |
599 # if an @pathalias already exists, we overwrite (update) it | 598 # if an @pathalias already exists, we overwrite (update) it |
600 if path.startswith(b"file:"): | 599 if path.startswith(b"file:"): |
760 writer(msg) | 759 writer(msg) |
761 localmarks.applychanges(repo, tr, changes) | 760 localmarks.applychanges(repo, tr, changes) |
762 | 761 |
763 | 762 |
764 def incoming(ui, repo, peer): | 763 def incoming(ui, repo, peer): |
765 '''Show bookmarks incoming from other to repo | 764 """Show bookmarks incoming from other to repo""" |
766 ''' | |
767 ui.status(_(b"searching for changed bookmarks\n")) | 765 ui.status(_(b"searching for changed bookmarks\n")) |
768 | 766 |
769 with peer.commandexecutor() as e: | 767 with peer.commandexecutor() as e: |
770 remotemarks = unhexlifybookmarks( | 768 remotemarks = unhexlifybookmarks( |
771 e.callcommand(b'listkeys', {b'namespace': b'bookmarks',}).result() | 769 e.callcommand( |
770 b'listkeys', | |
771 { | |
772 b'namespace': b'bookmarks', | |
773 }, | |
774 ).result() | |
772 ) | 775 ) |
773 | 776 |
774 r = comparebookmarks(repo, remotemarks, repo._bookmarks) | 777 r = comparebookmarks(repo, remotemarks, repo._bookmarks) |
775 addsrc, adddst, advsrc, advdst, diverge, differ, invalid, same = r | 778 addsrc, adddst, advsrc, advdst, diverge, differ, invalid, same = r |
776 | 779 |
811 | 814 |
812 return 0 | 815 return 0 |
813 | 816 |
814 | 817 |
815 def outgoing(ui, repo, other): | 818 def outgoing(ui, repo, other): |
816 '''Show bookmarks outgoing from repo to other | 819 """Show bookmarks outgoing from repo to other""" |
817 ''' | |
818 ui.status(_(b"searching for changed bookmarks\n")) | 820 ui.status(_(b"searching for changed bookmarks\n")) |
819 | 821 |
820 remotemarks = unhexlifybookmarks(other.listkeys(b'bookmarks')) | 822 remotemarks = unhexlifybookmarks(other.listkeys(b'bookmarks')) |
821 r = comparebookmarks(repo, repo._bookmarks, remotemarks) | 823 r = comparebookmarks(repo, repo._bookmarks, remotemarks) |
822 addsrc, adddst, advsrc, advdst, diverge, differ, invalid, same = r | 824 addsrc, adddst, advsrc, advdst, diverge, differ, invalid, same = r |
861 | 863 |
862 return 0 | 864 return 0 |
863 | 865 |
864 | 866 |
865 def summary(repo, peer): | 867 def summary(repo, peer): |
866 '''Compare bookmarks between repo and other for "hg summary" output | 868 """Compare bookmarks between repo and other for "hg summary" output |
867 | 869 |
868 This returns "(# of incoming, # of outgoing)" tuple. | 870 This returns "(# of incoming, # of outgoing)" tuple. |
869 ''' | 871 """ |
870 with peer.commandexecutor() as e: | 872 with peer.commandexecutor() as e: |
871 remotemarks = unhexlifybookmarks( | 873 remotemarks = unhexlifybookmarks( |
872 e.callcommand(b'listkeys', {b'namespace': b'bookmarks',}).result() | 874 e.callcommand( |
875 b'listkeys', | |
876 { | |
877 b'namespace': b'bookmarks', | |
878 }, | |
879 ).result() | |
873 ) | 880 ) |
874 | 881 |
875 r = comparebookmarks(repo, remotemarks, repo._bookmarks) | 882 r = comparebookmarks(repo, remotemarks, repo._bookmarks) |
876 addsrc, adddst, advsrc, advdst, diverge, differ, invalid, same = r | 883 addsrc, adddst, advsrc, advdst, diverge, differ, invalid, same = r |
877 return (len(addsrc), len(adddst)) | 884 return (len(addsrc), len(adddst)) |