bookmarks: add support for `mirror` mode to `incoming`
authorPierre-Yves David <pierre-yves.david@octobus.net>
Fri, 15 Oct 2021 04:25:58 +0200
changeset 48243 76c071bba40d
parent 48242 4d2ab365699e
child 48244 b56858d85a7b
bookmarks: add support for `mirror` mode to `incoming` This is more consistent. Differential Revision: https://phab.mercurial-scm.org/D11676
mercurial/bookmarks.py
mercurial/commands.py
tests/test-bookmarks-pushpull.t
--- a/mercurial/bookmarks.py	Fri Oct 15 03:49:05 2021 +0200
+++ b/mercurial/bookmarks.py	Fri Oct 15 04:25:58 2021 +0200
@@ -791,7 +791,7 @@
         repo._bookmarks.applychanges(repo, tr, changes)
 
 
-def incoming(ui, repo, peer):
+def incoming(ui, repo, peer, mode=None):
     """Show bookmarks incoming from other to repo"""
     ui.status(_(b"searching for changed bookmarks\n"))
 
@@ -805,9 +805,6 @@
             ).result()
         )
 
-    r = comparebookmarks(repo, remotemarks, repo._bookmarks)
-    addsrc, adddst, advsrc, advdst, diverge, differ, invalid, same = r
-
     incomings = []
     if ui.debugflag:
         getid = lambda id: id
@@ -823,18 +820,36 @@
         def add(b, id, st):
             incomings.append(b"   %-25s %s\n" % (b, getid(id)))
 
-    for b, scid, dcid in addsrc:
-        # i18n: "added" refers to a bookmark
-        add(b, hex(scid), _(b'added'))
-    for b, scid, dcid in advsrc:
-        # i18n: "advanced" refers to a bookmark
-        add(b, hex(scid), _(b'advanced'))
-    for b, scid, dcid in diverge:
-        # i18n: "diverged" refers to a bookmark
-        add(b, hex(scid), _(b'diverged'))
-    for b, scid, dcid in differ:
-        # i18n: "changed" refers to a bookmark
-        add(b, hex(scid), _(b'changed'))
+    if mode == b'mirror':
+        localmarks = repo._bookmarks
+        allmarks = set(remotemarks.keys()) | set(localmarks.keys())
+        for b in sorted(allmarks):
+            loc = localmarks.get(b)
+            rem = remotemarks.get(b)
+            if loc == rem:
+                continue
+            elif loc is None:
+                add(b, hex(rem), _(b'added'))
+            elif rem is None:
+                add(b, hex(repo.nullid), _(b'removed'))
+            else:
+                add(b, hex(rem), _(b'changed'))
+    else:
+        r = comparebookmarks(repo, remotemarks, repo._bookmarks)
+        addsrc, adddst, advsrc, advdst, diverge, differ, invalid, same = r
+
+        for b, scid, dcid in addsrc:
+            # i18n: "added" refers to a bookmark
+            add(b, hex(scid), _(b'added'))
+        for b, scid, dcid in advsrc:
+            # i18n: "advanced" refers to a bookmark
+            add(b, hex(scid), _(b'advanced'))
+        for b, scid, dcid in diverge:
+            # i18n: "diverged" refers to a bookmark
+            add(b, hex(scid), _(b'diverged'))
+        for b, scid, dcid in differ:
+            # i18n: "changed" refers to a bookmark
+            add(b, hex(scid), _(b'changed'))
 
     if not incomings:
         ui.status(_(b"no changed bookmarks found\n"))
--- a/mercurial/commands.py	Fri Oct 15 03:49:05 2021 +0200
+++ b/mercurial/commands.py	Fri Oct 15 04:25:58 2021 +0200
@@ -4360,7 +4360,9 @@
                 ui.status(
                     _(b'comparing with %s\n') % urlutil.hidepassword(source)
                 )
-                return bookmarks.incoming(ui, repo, other)
+                return bookmarks.incoming(
+                    ui, repo, other, mode=path.bookmarks_mode
+                )
             finally:
                 other.close()
 
--- a/tests/test-bookmarks-pushpull.t	Fri Oct 15 03:49:05 2021 +0200
+++ b/tests/test-bookmarks-pushpull.t	Fri Oct 15 04:25:58 2021 +0200
@@ -503,6 +503,26 @@
    * foobar                    1:9b140be10808
   $ cp .hg/bookmarks .hg/bookmarks.bak
   $ hg book -d X
+  $ hg incoming --bookmark  -v ../a
+  comparing with ../a
+  searching for changed bookmarks
+     @                         0d2164f0ce0d diverged
+     X                         0d2164f0ce0d added
+  $ hg incoming --bookmark  -v ../a --config 'paths.*:bookmarks.mode=babar'
+  (paths.*:bookmarks.mode has unknown value: "babar")
+  comparing with ../a
+  searching for changed bookmarks
+     @                         0d2164f0ce0d diverged
+     X                         0d2164f0ce0d added
+  $ hg incoming --bookmark  -v ../a --config 'paths.*:bookmarks.mode=mirror'
+  comparing with ../a
+  searching for changed bookmarks
+     @                         0d2164f0ce0d changed
+     @foo                      000000000000 removed
+     X                         0d2164f0ce0d added
+     X@foo                     000000000000 removed
+     foo                       000000000000 removed
+     foobar                    000000000000 removed
   $ hg pull ../a --config 'paths.*:bookmarks.mode=mirror'
   pulling from ../a
   searching for changes