[PATCH] protocol: Add the stream-preferred capability

Ben benoit.allard at gmx.de
Tue Apr 3 17:03:15 CDT 2012


# HG changeset patch
# User Benoit Allard <benoit at aeteurope.nl>
# Date 1333490447 -7200
# Node ID 35c2b849d7d00ea90e04a348127ff586bfa3aca6
# Parent  f350021ee32ed22b8bd7d3211a8899df0e3d6552
protocol: Add the stream-preferred capability

This makes the client use the uncompressed protocol.

diff -r f350021ee32e -r 35c2b849d7d0 mercurial/help/config.txt
--- a/mercurial/help/config.txt	Tue Apr 03 11:35:04 2012 -0500
+++ b/mercurial/help/config.txt	Wed Apr 04 00:00:47 2012 +0200
@@ -979,6 +979,10 @@
     the write lock while determining what data to transfer.
     Default is True.
 
+``preferuncompressed``
+    When set, clients will try to use the uncompressed streaming
+    protocol. Default is False.
+
 ``validate``
     Whether to validate the completeness of pushed changesets by
     checking that all new file revisions specified in manifests are
diff -r f350021ee32e -r 35c2b849d7d0 mercurial/localrepo.py
--- a/mercurial/localrepo.py	Tue Apr 03 11:35:04 2012 -0500
+++ b/mercurial/localrepo.py	Wed Apr 04 00:00:47 2012 +0200
@@ -2290,6 +2290,10 @@
         # and format flags on "stream" capability, and use
         # uncompressed only if compatible.
 
+        if not stream:
+            # if the server explicitely prefer to stream (for fast LANs)
+            stream = remote.capable('stream-preferred')
+
         if stream and not heads:
             # 'stream' means remote revlog format is revlogv1 only
             if remote.capable('stream'):
diff -r f350021ee32e -r 35c2b849d7d0 mercurial/wireproto.py
--- a/mercurial/wireproto.py	Tue Apr 03 11:35:04 2012 -0500
+++ b/mercurial/wireproto.py	Wed Apr 04 00:00:47 2012 +0200
@@ -415,6 +415,8 @@
     caps = ('lookup changegroupsubset branchmap pushkey known getbundle '
             'unbundlehash batch').split()
     if _allowstream(repo.ui):
+        if repo.ui.configbool('server', 'preferuncompressed', False):
+            caps.append('stream-preferred')
         requiredformats = repo.requirements & repo.supportedformats
         # if our local revlogs are just revlogv1, add 'stream' cap
         if not requiredformats - set(('revlogv1',)):
diff -r f350021ee32e -r 35c2b849d7d0 tests/test-hgweb-commands.t
--- a/tests/test-hgweb-commands.t	Tue Apr 03 11:35:04 2012 -0500
+++ b/tests/test-hgweb-commands.t	Wed Apr 04 00:00:47 2012 +0200
@@ -1198,10 +1198,10 @@
   	top: -1px;
   }
 
-Stop and restart with HGENCODING=cp932
+Stop and restart with HGENCODING=cp932 and preferuncompressed
 
   $ "$TESTDIR/killdaemons.py"
-  $ HGENCODING=cp932 hg serve --config server.uncompressed=False -n test \
+  $ HGENCODING=cp932 hg serve --config server.preferuncompressed=True -n test \
   >     -p $HGPORT -d --pid-file=hg.pid -E errors.log
   $ cat hg.pid >> $DAEMON_PIDS
 
@@ -1216,6 +1216,15 @@
   >     | grep '^var data ='
   var data = [["548001d11f45", [0, 1], [[0, 0, 1, -1, ""]], "\u80fd", "test", "1970-01-01", ["unstable", true], ["tip"], ["something"]], ["ba87b23d29ca", [0, 1], [[0, 0, 1, 3, "FF0000"]], "branch", "test", "1970-01-01", ["unstable", false], [], []], ["1d22e65f027e", [0, 1], [[0, 0, 1, 3, ""]], "branch", "test", "1970-01-01", ["stable", true], [], []], ["a4f92ed23982", [0, 1], [[0, 0, 1, 3, ""]], "Added tag 1.0 for changeset 2ef0ac749a14", "test", "1970-01-01", ["default", true], [], []], ["2ef0ac749a14", [0, 1], [], "base", "test", "1970-01-01", ["default", false], ["1.0"], ["anotherthing"]]];
 
+capabilities
+
+  $ "$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT '?cmd=capabilities'; echo
+  200 Script output follows
+  
+  lookup changegroupsubset branchmap pushkey known getbundle unbundlehash batch stream-preferred stream unbundle=HG10GZ,HG10BZ,HG10UN httpheader=1024
+
+heads
+
 ERRORS ENCOUNTERED
 
   $ cat errors.log
diff -r f350021ee32e -r 35c2b849d7d0 tests/test-http.t
--- a/tests/test-http.t	Tue Apr 03 11:35:04 2012 -0500
+++ b/tests/test-http.t	Wed Apr 04 00:00:47 2012 +0200
@@ -112,6 +112,7 @@
   [255]
 
 test http authentication
++ use the same server to test server side streaming preference
 
   $ cd test
   $ cat << EOT > userpass.py
@@ -127,7 +128,8 @@
   > def extsetup():
   >     common.permhooks.insert(0, perform_authentication)
   > EOT
-  $ hg --config extensions.x=userpass.py serve -p $HGPORT2 -d --pid-file=pid
+  $ hg --config extensions.x=userpass.py serve -p $HGPORT2 -d --pid-file=pid \
+  >    --config server.preferuncompressed=True
   $ cat pid >> $DAEMON_PIDS
 
   $ hg id http://localhost:$HGPORT2/  
@@ -149,8 +151,13 @@
   5fed3813f7f5
   $ hg id http://user@localhost:$HGPORT2/ 
   5fed3813f7f5
-  $ hg id http://user:pass@localhost:$HGPORT2/
-  5fed3813f7f5
+  $ hg clone http://user:pass@localhost:$HGPORT2/ dest 2>&1
+  streaming all changes
+  7 files to transfer, 916 bytes of data
+  transferred * bytes in * seconds (*/sec) (glob)
+  updating to branch default
+  5 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
   $ hg id http://user2@localhost:$HGPORT2/ 
   abort: http authorization required
   [255]


More information about the Mercurial-devel mailing list