[PATCH 4 of 4] largefiles: makes verify batching stat calls to remote

liscju piotr.listkiewicz at gmail.com
Mon May 2 16:19:12 EDT 2016


# HG changeset patch
# User liscju <piotr.listkiewicz at gmail.com>
# Date 1462210631 -7200
#      Mon May 02 19:37:11 2016 +0200
# Branch stable
# Node ID 5ca4f289ae02c580e19eafe7bf6168bda92664eb
# Parent  889c3537ab941231ebc6881af6c1be6f0321294b
largefiles: makes verify batching stat calls to remote

Instead of sending stat calls for each file separately, it send
one batch call with stat invocations for all files.

diff -r 889c3537ab94 -r 5ca4f289ae02 hgext/largefiles/remotestore.py
--- a/hgext/largefiles/remotestore.py	Mon May 02 18:52:49 2016 +0200
+++ b/hgext/largefiles/remotestore.py	Mon May 02 19:37:11 2016 +0200
@@ -67,28 +67,31 @@ class remotestore(basestore.basestore):
 
     def _verify(self, revs, contents, verified):
         failed = False
+        # filestocheck is list of (cset, filename, expectedhash)
+        filestocheck = []
         for rev in revs:
             cctx = self.repo[rev]
             cset = "%d:%s" % (cctx.rev(), node.short(cctx.node()))
 
             for standin in cctx:
-                if self._verifyfile(cctx, cset, contents, standin, verified):
-                    failed = True
+                filename = lfutil.splitstandin(standin)
+                if filename:
+                    fctx = cctx[standin]
+                    key = (filename, fctx.filenode())
+                    expectedhash = fctx.data()[0:40]
+                    verified.add(key)
+                    filestocheck.append((cset, filename, expectedhash))
+
+        expectedhashes = [expecthash for _, _, expecthash in filestocheck]
+        statresults = self._stat(expectedhashes)
+        for cset, filename, expectedhash in filestocheck:
+            stat = statresults[expectedhash]
+            if self._verifyfile(cset, filename, stat):
+                failed = True
+
         return failed
 
-    def _verifyfile(self, cctx, cset, contents, standin, verified):
-        filename = lfutil.splitstandin(standin)
-        if not filename:
-            return False
-        fctx = cctx[standin]
-        key = (filename, fctx.filenode())
-        if key in verified:
-            return False
-
-        verified.add(key)
-
-        expecthash = fctx.data()[0:40]
-        stat = self._stat([expecthash])[expecthash]
+    def _verifyfile(self, cset, filename, stat):
         if not stat:
             return False
         elif stat == 1:
diff -r 889c3537ab94 -r 5ca4f289ae02 tests/test-largefiles-wireproto.t
--- a/tests/test-largefiles-wireproto.t	Mon May 02 18:52:49 2016 +0200
+++ b/tests/test-largefiles-wireproto.t	Mon May 02 19:37:11 2016 +0200
@@ -306,4 +306,46 @@ largefiles pulled on update - no server 
 used all HGPORTs, kill all daemons
   $ killdaemons.py
 
+largefiles should batch verify remote calls
+
+  $ hg init batchverifymain
+  $ cd batchverifymain
+  $ echo "aaa" >> a
+  $ hg add --large a
+  $ hg commit -m "a"
+  Invoking status precommit hook
+  A a
+  $ echo "bbb" >> b
+  $ hg add --large b
+  $ hg commit -m "b"
+  Invoking status precommit hook
+  A b
+  $ cd ..
+  $ hg serve -R batchverifymain -d -p $HGPORT --pid-file hg.pid \
+  > -A access.log
+  $ cat hg.pid >> $DAEMON_PIDS
+  $ hg clone http://localhost:$HGPORT batchverifyclone
+  requesting all changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 2 changesets with 2 changes to 2 files
+  updating to branch default
+  getting changed largefiles
+  2 largefiles updated, 0 removed
+  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg -R batchverifyclone verify --large
+  checking changesets
+  checking manifests
+  crosschecking files in changesets and manifests
+  checking files
+  2 files, 2 changesets, 2 total revisions
+  searching 1 changesets for largefiles
+  verified existence of 2 revisions of 2 largefiles
+  $ tail -1 access.log
+  127.0.0.1 - - [*] "GET /?cmd=batch HTTP/1.1" 200 - x-hgarg-1:cmds=statlfile+sha%3D972a1a11f19934401291cc99117ec614933374ce%3Bstatlfile+sha%3Dc801c9cfe94400963fcb683246217d5db77f9a9a (glob)
+  $ rm access.log
+
+  $ killdaemons.py
+
 #endif


More information about the Mercurial-devel mailing list