comparison mercurial/bookmarks.py @ 48243:76c071bba40d

bookmarks: add support for `mirror` mode to `incoming` This is more consistent. Differential Revision: https://phab.mercurial-scm.org/D11676
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 15 Oct 2021 04:25:58 +0200
parents 4d2ab365699e
children b56858d85a7b
comparison
equal deleted inserted replaced
48242:4d2ab365699e 48243:76c071bba40d
789 changes.append((b, node)) 789 changes.append((b, node))
790 writer(msg) 790 writer(msg)
791 repo._bookmarks.applychanges(repo, tr, changes) 791 repo._bookmarks.applychanges(repo, tr, changes)
792 792
793 793
794 def incoming(ui, repo, peer): 794 def incoming(ui, repo, peer, mode=None):
795 """Show bookmarks incoming from other to repo""" 795 """Show bookmarks incoming from other to repo"""
796 ui.status(_(b"searching for changed bookmarks\n")) 796 ui.status(_(b"searching for changed bookmarks\n"))
797 797
798 with peer.commandexecutor() as e: 798 with peer.commandexecutor() as e:
799 remotemarks = unhexlifybookmarks( 799 remotemarks = unhexlifybookmarks(
803 b'namespace': b'bookmarks', 803 b'namespace': b'bookmarks',
804 }, 804 },
805 ).result() 805 ).result()
806 ) 806 )
807 807
808 r = comparebookmarks(repo, remotemarks, repo._bookmarks)
809 addsrc, adddst, advsrc, advdst, diverge, differ, invalid, same = r
810
811 incomings = [] 808 incomings = []
812 if ui.debugflag: 809 if ui.debugflag:
813 getid = lambda id: id 810 getid = lambda id: id
814 else: 811 else:
815 getid = lambda id: id[:12] 812 getid = lambda id: id[:12]
821 else: 818 else:
822 819
823 def add(b, id, st): 820 def add(b, id, st):
824 incomings.append(b" %-25s %s\n" % (b, getid(id))) 821 incomings.append(b" %-25s %s\n" % (b, getid(id)))
825 822
826 for b, scid, dcid in addsrc: 823 if mode == b'mirror':
827 # i18n: "added" refers to a bookmark 824 localmarks = repo._bookmarks
828 add(b, hex(scid), _(b'added')) 825 allmarks = set(remotemarks.keys()) | set(localmarks.keys())
829 for b, scid, dcid in advsrc: 826 for b in sorted(allmarks):
830 # i18n: "advanced" refers to a bookmark 827 loc = localmarks.get(b)
831 add(b, hex(scid), _(b'advanced')) 828 rem = remotemarks.get(b)
832 for b, scid, dcid in diverge: 829 if loc == rem:
833 # i18n: "diverged" refers to a bookmark 830 continue
834 add(b, hex(scid), _(b'diverged')) 831 elif loc is None:
835 for b, scid, dcid in differ: 832 add(b, hex(rem), _(b'added'))
836 # i18n: "changed" refers to a bookmark 833 elif rem is None:
837 add(b, hex(scid), _(b'changed')) 834 add(b, hex(repo.nullid), _(b'removed'))
835 else:
836 add(b, hex(rem), _(b'changed'))
837 else:
838 r = comparebookmarks(repo, remotemarks, repo._bookmarks)
839 addsrc, adddst, advsrc, advdst, diverge, differ, invalid, same = r
840
841 for b, scid, dcid in addsrc:
842 # i18n: "added" refers to a bookmark
843 add(b, hex(scid), _(b'added'))
844 for b, scid, dcid in advsrc:
845 # i18n: "advanced" refers to a bookmark
846 add(b, hex(scid), _(b'advanced'))
847 for b, scid, dcid in diverge:
848 # i18n: "diverged" refers to a bookmark
849 add(b, hex(scid), _(b'diverged'))
850 for b, scid, dcid in differ:
851 # i18n: "changed" refers to a bookmark
852 add(b, hex(scid), _(b'changed'))
838 853
839 if not incomings: 854 if not incomings:
840 ui.status(_(b"no changed bookmarks found\n")) 855 ui.status(_(b"no changed bookmarks found\n"))
841 return 1 856 return 1
842 857