# HG changeset patch # User Siddharth Agarwal # Date 1494525005 25200 # Node ID d0d9a4fca59bcb0c0d5a53e7b3d2db2068844d1f # Parent 076f1ff43f0f4cf86523df225eb181d869d8eb0f clone: add a server-side option to disable full getbundles (pull-based clones) For large enough repositories, pull-based clones take too long, and an attempt to use them indicates some sort of configuration or other issue or maybe an outdated Mercurial. Add a config option to disable them. diff -r 076f1ff43f0f -r d0d9a4fca59b mercurial/help/config.txt --- a/mercurial/help/config.txt Mon May 08 20:01:06 2017 -0700 +++ b/mercurial/help/config.txt Thu May 11 10:50:05 2017 -0700 @@ -1660,6 +1660,12 @@ 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 -r 076f1ff43f0f -r d0d9a4fca59b mercurial/wireproto.py --- a/mercurial/wireproto.py Mon May 08 20:01:06 2017 -0700 +++ b/mercurial/wireproto.py Thu May 11 10:50:05 2017 -0700 @@ -16,6 +16,7 @@ from .node import ( bin, hex, + nullid, ) from . import ( @@ -841,6 +842,17 @@ 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 -r 076f1ff43f0f -r d0d9a4fca59b tests/test-http-bundle1.t --- a/tests/test-http-bundle1.t Mon May 08 20:01:06 2017 -0700 +++ b/tests/test-http-bundle1.t Thu May 11 10:50:05 2017 -0700 @@ -365,3 +365,41 @@ 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 -r 076f1ff43f0f -r d0d9a4fca59b tests/test-http.t --- a/tests/test-http.t Mon May 08 20:01:06 2017 -0700 +++ b/tests/test-http.t Thu May 11 10:50:05 2017 -0700 @@ -354,6 +354,44 @@ [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