diff --git a/mercurial/help/config.txt b/mercurial/help/config.txt --- a/mercurial/help/config.txt +++ b/mercurial/help/config.txt @@ -1660,6 +1660,12 @@ Controls generic server settings. When set, clients will try to use the uncompressed streaming protocol. (default: False) +``disablefullbundle`` + When set, servers will refuse attempts to do pull-based clones. + If this option is set, ``preferuncompressed`` and/or clone bundles + are highly recommended. Partial clones will still be allowed. + (default: False) + ``validate`` Whether to validate the completeness of pushed changesets by checking that all new file revisions specified in manifests are diff --git a/mercurial/wireproto.py b/mercurial/wireproto.py --- a/mercurial/wireproto.py +++ b/mercurial/wireproto.py @@ -16,6 +16,7 @@ from .i18n import _ from .node import ( bin, hex, + nullid, ) from . import ( @@ -841,6 +842,17 @@ def getbundle(repo, proto, others): hint=bundle2requiredhint) try: + if repo.ui.configbool('server', 'disablefullbundle', False): + # Check to see if this is a full clone. + clheads = set(repo.changelog.heads()) + heads = set(opts.get('heads', set())) + common = set(opts.get('common', set())) + common.discard(nullid) + if not common and clheads == heads: + raise error.Abort( + _('server has pull-based clones disabled'), + hint=_('remove --pull if specified or upgrade Mercurial')) + chunks = exchange.getbundlechunks(repo, 'serve', **opts) except error.Abort as exc: # cleanly forward Abort error to the client diff --git a/tests/test-http-bundle1.t b/tests/test-http-bundle1.t --- a/tests/test-http-bundle1.t +++ b/tests/test-http-bundle1.t @@ -365,3 +365,41 @@ Check error reporting while pulling/clon this is an exercise [255] $ cat error.log + +disable pull-based clones + + $ hg -R test serve -p $HGPORT1 -d --pid-file=hg4.pid -E error.log --config server.disablefullbundle=True + $ cat hg4.pid >> $DAEMON_PIDS + $ hg clone http://localhost:$HGPORT1/ disable-pull-clone + requesting all changes + abort: remote error: + server has pull-based clones disabled + [255] + +... but keep stream clones working + + $ hg clone --uncompressed --noupdate http://localhost:$HGPORT1/ test-stream-clone + streaming all changes + * files to transfer, * of data (glob) + transferred * in * seconds (* KB/sec) (glob) + searching for changes + no changes found + +... and also keep partial clones and pulls working + $ hg clone http://localhost:$HGPORT1 --rev 0 test-partial-clone + adding changesets + adding manifests + adding file changes + added 1 changesets with 4 changes to 4 files + updating to branch default + 4 files updated, 0 files merged, 0 files removed, 0 files unresolved + $ hg pull -R test-partial-clone + pulling from http://localhost:$HGPORT1/ + searching for changes + adding changesets + adding manifests + adding file changes + added 2 changesets with 3 changes to 3 files + (run 'hg update' to get a working copy) + + $ cat error.log diff --git a/tests/test-http.t b/tests/test-http.t --- a/tests/test-http.t +++ b/tests/test-http.t @@ -354,6 +354,44 @@ check abort error reporting while pullin [255] $ cat error.log +disable pull-based clones + + $ hg -R test serve -p $HGPORT1 -d --pid-file=hg4.pid -E error.log --config server.disablefullbundle=True + $ cat hg4.pid >> $DAEMON_PIDS + $ hg clone http://localhost:$HGPORT1/ disable-pull-clone + requesting all changes + remote: abort: server has pull-based clones disabled + abort: pull failed on remote + (remove --pull if specified or upgrade Mercurial) + [255] + +... but keep stream clones working + + $ hg clone --uncompressed --noupdate http://localhost:$HGPORT1/ test-stream-clone + streaming all changes + * files to transfer, * of data (glob) + transferred * in * seconds (*/sec) (glob) + searching for changes + no changes found + $ cat error.log + +... and also keep partial clones and pulls working + $ hg clone http://localhost:$HGPORT1 --rev 0 test-partial-clone + adding changesets + adding manifests + adding file changes + added 1 changesets with 4 changes to 4 files + updating to branch default + 4 files updated, 0 files merged, 0 files removed, 0 files unresolved + $ hg pull -R test-partial-clone + pulling from http://localhost:$HGPORT1/ + searching for changes + adding changesets + adding manifests + adding file changes + added 2 changesets with 3 changes to 3 files + (run 'hg update' to get a working copy) + corrupt cookies file should yield a warning $ cat > $TESTTMP/cookies.txt << EOF