Patchwork D11676: bookmarks: add support for `mirror` mode to `incoming`

login
register
mail settings
Submitter phabricator
Date Oct. 15, 2021, 8:19 a.m.
Message ID <differential-rev-PHID-DREV-362iedxbovitbijy45ko-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/49999/
State Superseded
Headers show

Comments

phabricator - Oct. 15, 2021, 8:19 a.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This is more consistent.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D11676

AFFECTED FILES
  mercurial/bookmarks.py
  mercurial/commands.py
  tests/test-bookmarks-pushpull.t

CHANGE DETAILS




To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/tests/test-bookmarks-pushpull.t b/tests/test-bookmarks-pushpull.t
--- a/tests/test-bookmarks-pushpull.t
+++ b/tests/test-bookmarks-pushpull.t
@@ -503,6 +503,20 @@ 
    * 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=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
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -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()
 
diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -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
@@ -816,25 +813,47 @@ 
     if ui.verbose:
 
         def add(b, id, st):
-            incomings.append(b"   %-25s %s %s\n" % (b, getid(id), st))
+            pattern = b"   %-25s %s %s\n"
+            data = (b, getid(id), st)
+            incomings.append(pattern % data)
 
     else:
 
         def add(b, id, st):
-            incomings.append(b"   %-25s %s\n" % (b, getid(id)))
+            pattern = b"   %-25s %s\n"
+            data = (b, getid(id))
+            incomings.append(pattern % data)
 
-    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) | set(repo._bookmarks)
+        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"))