Skip to content
Snippets Groups Projects
Commit bf548f18 authored by Raphaël Gomès's avatar Raphaël Gomès
Browse files

config: add option to never exchange bookmarks

Some repositories (particularly Octobus's `mercurial-devel` instance) do not
want to exchange bookmarks, ever. This change applies to all exchange mechanisms
relevant to Heptapod but was initially motivated by the new hg pull mirrors.
parent 280a173b
No related branches found
No related tags found
1 merge request!44config: add option to never exchange bookmarks
Pipeline #14854 passed with warnings
Pipeline: hgitaly

#14855

    ......@@ -9,6 +9,7 @@
    needed for Heptapod server operations.
    """
    import json
    from mercurial.i18n import _
    from mercurial import (
    cmdutil,
    ......@@ -17,6 +18,7 @@
    error,
    exthelper,
    extensions,
    exchange,
    pycompat,
    registrar,
    scmutil,
    ......@@ -51,6 +53,8 @@
    configitem(b'heptapod', b'repositories-root')
    configitem(b'heptapod', b'gitlab-shell')
    configitem(b'heptapod', b'mirror-path')
    # Strips all bookmarks exchange by lying about peer capabilities
    configitem(b'heptapod', b'exchange-ignore-bookmarks', False)
    # The following items affect other config items recognized by the core
    # or by extensions. The default value should be inert, i.e., would not
    ......@@ -241,6 +245,18 @@
    b"This may be reenabled in a subsequent version.")
    def bookmarks_op_override(orig, op, *args, **kwargs):
    '''Wrap command to never pull/push bookmarks'''
    ui = op.repo.ui
    ignore_bookmarks = ui.configbool(b"heptapod", b"exchange-ignore-bookmarks")
    if not ignore_bookmarks:
    return orig(op, *args, **kwargs)
    # Not sure how important this is, but it's done in the original function
    # for the pushop in case of early return
    op.stepsdone.add(b'bookmarks')
    extensions.wrapfunction(subrepo.hgsubrepo, b'get', forbid_subrepo_get)
    extensions.wrapfunction(subrepo.gitsubrepo, b'get', forbid_subrepo_get)
    extensions.wrapfunction(subrepo.svnsubrepo, b'get', forbid_subrepo_get)
    ......@@ -244,3 +260,19 @@
    extensions.wrapfunction(subrepo.hgsubrepo, b'get', forbid_subrepo_get)
    extensions.wrapfunction(subrepo.gitsubrepo, b'get', forbid_subrepo_get)
    extensions.wrapfunction(subrepo.svnsubrepo, b'get', forbid_subrepo_get)
    def extsetup(ui):
    """Tweaks after all extensions went though their `uisetup`
    hgext3rd.heptapod is meant to be terminal, the only (debatable)
    exception being HGitaly, which could well adopt the whole of `heptapod`
    and `hgext3rd.heptapod` in the future.
    """
    extensions.wrapfunction(exchange, b'_pullbookmarks', bookmarks_op_override)
    extensions.wrapfunction(exchange, b'_pushbookmark', bookmarks_op_override)
    extensions.wrapfunction(
    exchange,
    b'_pushb2bookmarkspart',
    bookmarks_op_override
    )
    # Copyright 2020 Raphaël Gomès <raphael.gomes@octobus.net>
    #
    # This software may be used and distributed according to the terms of the
    # GNU General Public License version 2 or any later version.
    #
    # SPDX-License-Identifier: GPL-2.0-or-later
    import pytest
    from heptapod.testhelpers import RepoWrapper
    from mercurial_testhelpers import as_bytes
    from .utils import common_config
    def make_repo(path, heptapod_config_overrides=None):
    heptapod_config_overrides = heptapod_config_overrides or {}
    config = common_config()
    config.setdefault('heptapod', {}).update(heptapod_config_overrides)
    config['phases'] = dict(publish=False)
    wrapper = RepoWrapper.init(path, config=config)
    ctx = wrapper.commit_file('foo', content='foo0', message="default0")
    wrapper.command('bookmark', b'book1', rev=ctx.hex())
    wrapper.set_phase('public', ['.'])
    return wrapper
    def get_revs_with_bookmark(wrapper):
    return wrapper.repo.revs(b'bookmark()')
    @pytest.mark.parametrize("ignore_bookmarks", [True, False])
    def test_pull_bookmarks(tmpdir, ignore_bookmarks):
    """Case where the pulled has a bookmark."""
    source_path = tmpdir.join('source')
    dest_path = tmpdir.join('dest')
    source = make_repo(source_path)
    dest = RepoWrapper.init(dest_path)
    assert len(get_revs_with_bookmark(dest)) == 0
    assert len(get_revs_with_bookmark(source)) == 1
    dest.repo.ui.setconfig(
    b'heptapod',
    b'exchange-ignore-bookmarks',
    ignore_bookmarks,
    )
    dest.command('pull', as_bytes(source_path))
    if ignore_bookmarks:
    assert len(get_revs_with_bookmark(dest)) == 0
    else:
    assert list(get_revs_with_bookmark(dest)) == [0]
    @pytest.mark.parametrize("ignore_bookmarks", [True, False])
    def test_push_bookmarks(tmpdir, ignore_bookmarks):
    """Case where the pusher has a bookmark."""
    source_path = tmpdir.join('source')
    dest_path = tmpdir.join('dest')
    overrides = {
    'exchange-ignore-bookmarks': ignore_bookmarks,
    }
    source = make_repo(source_path, heptapod_config_overrides=overrides)
    dest = RepoWrapper.init(dest_path)
    assert len(get_revs_with_bookmark(dest)) == 0
    assert len(get_revs_with_bookmark(source)) == 1
    source.command('push', dest=as_bytes(dest_path), bookmark=[b'book1'])
    dest = RepoWrapper.load(dest_path)
    if ignore_bookmarks:
    assert len(get_revs_with_bookmark(dest)) == 0
    else:
    assert list(get_revs_with_bookmark(dest)) == [0]
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment