Patchwork D11675: bookmarks: move the `mirror` option to the `paths` section

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

Comments

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

REVISION SUMMARY
  A new `bookmarks` section with a `mirror` option have been added. That option
  has never been released yet.
  
  This new options is limited since it affect all paths without distinction. In
  case where a repository is interacting with multiple peers, being able to
  control behavior on a path basis can be quite valuable.
  
  In addition, having more variant of behavior would be interesting, especially a
  mode where no bookmark exchanged is tried at all. Such new mode (implemented
  later) make a lot of sense for configuration on a path-basis.
  
  Configuration of the default behavior is still possible through the usage of
  generic path configuration. The "old" config, becomes:
  
    [bookmarks]
    mirror=True
  
  becomes:
  
    [path]
    *:bookmarks.mode=mirror

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/bookmarks.py
  mercurial/configitems.py
  mercurial/exchange.py
  mercurial/helptext/config.txt
  mercurial/utils/urlutil.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,7 +503,7 @@ 
    * foobar                    1:9b140be10808
   $ cp .hg/bookmarks .hg/bookmarks.bak
   $ hg book -d X
-  $ hg pull ../a --config bookmarks.mirror=true
+  $ hg pull ../a --config 'paths.*:bookmarks.mode=mirror'
   pulling from ../a
   searching for changes
   no changes found
diff --git a/mercurial/utils/urlutil.py b/mercurial/utils/urlutil.py
--- a/mercurial/utils/urlutil.py
+++ b/mercurial/utils/urlutil.py
@@ -766,6 +766,23 @@ 
     return value
 
 
+KNOW_BOOKMARKS_MODE = {
+    b'default',
+    b'mirror',
+}
+
+
+@pathsuboption(b'bookmarks.mode', b'bookmarks_mode')
+def bookmarks_mode_option(ui, path, value):
+    if value not in KNOW_BOOKMARKS_MODE:
+        msg = _(b'(paths.%s:bookmarks.mode as unknown value %s)\n')
+        msg %= (path.name, value)
+        ui.warn(msg)
+    if value == b'default':
+        value = None
+    return value
+
+
 @pathsuboption(b'multi-urls', b'multi_urls')
 def multiurls_pathoption(ui, path, value):
     res = stringutil.parsebool(value)
diff --git a/mercurial/helptext/config.txt b/mercurial/helptext/config.txt
--- a/mercurial/helptext/config.txt
+++ b/mercurial/helptext/config.txt
@@ -418,16 +418,6 @@ 
 If no suitable authentication entry is found, the user is prompted
 for credentials as usual if required by the remote.
 
-``bookmarks``
--------------
-
-Controls some aspect of bookmarks.
-
-``mirror``
-    When pulling, instead of merging local bookmarks and remote bookmarks,
-    replace local bookmarks by remote bookmarks. This is useful to replicate
-    a repository, or as an optimization. (default: False)
-
 ``cmdserver``
 -------------
 
@@ -1758,6 +1748,15 @@ 
    Revsets specifying bookmarks will not result in the bookmark being
    pushed.
 
+``bookmarks.mode``
+  How bookmark will be dealt during the exchange. It support the following value
+
+  - ``default``: the default behavior, local and remote bookmarks are "merged"
+    on push/pull.
+
+  - ``mirror``: when pulling, replace local bookmarks by remote bookmarks. This
+    is useful to replicate a repository, or as an optimization.
+
 The following special named paths exist:
 
 ``default``
diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -2028,6 +2028,9 @@ 
     pullop.stepsdone.add(b'bookmarks')
     repo = pullop.repo
     remotebookmarks = pullop.remotebookmarks
+    bookmarks_mode = None
+    if pullop.remote_path is not None:
+        bookmarks_mode = pullop.remote_path.bookmarks_mode
     bookmod.updatefromremote(
         repo.ui,
         repo,
@@ -2035,6 +2038,7 @@ 
         pullop.remote.url(),
         pullop.gettransaction,
         explicit=pullop.explicitbookmarks,
+        mode=bookmarks_mode,
     )
 
 
diff --git a/mercurial/configitems.py b/mercurial/configitems.py
--- a/mercurial/configitems.py
+++ b/mercurial/configitems.py
@@ -207,11 +207,6 @@ 
     b'pushing',
     default=list,
 )
-coreconfigitem(
-    b'bookmarks',
-    b'mirror',
-    default=False,
-)
 # bundle.mainreporoot: internal hack for bundlerepo
 coreconfigitem(
     b'bundle',
diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -772,9 +772,11 @@ 
     return changed
 
 
-def updatefromremote(ui, repo, remotemarks, path, trfunc, explicit=()):
+def updatefromremote(
+    ui, repo, remotemarks, path, trfunc, explicit=(), mode=None
+):
     ui.debug(b"checking for updated bookmarks\n")
-    if ui.configbool(b'bookmarks', b'mirror'):
+    if mode == b'mirror':
         changed = mirroring_remote(ui, repo, remotemarks)
     else:
         changed = merging_from_remote(ui, repo, remotemarks, path, explicit)