[PATCH 1 of 4 bfiles] Refactored store.verify method to reduce duplication (when implementing sshstore.verify)

david.douard at logilab.fr david.douard at logilab.fr
Tue Dec 1 13:05:10 CST 2009


# HG changeset patch
# User David Douard <david.douard at logilab.fr>
# Date 1259691358 -3600
# Node ID 1fc6ddc898b5ef990440a66dfc92d940c7897a1f
# Parent  b0d5cc24ba317f4989c817d8ad72aef528a99e9f
Refactored store.verify method to reduce duplication (when implementing sshstore.verify)

diff --git a/bfiles.py b/bfiles.py
--- a/bfiles.py
+++ b/bfiles.py
@@ -861,7 +861,31 @@
         '''Verify the existence (and, optionally, contents) of every big
         file revision referenced by every changeset in revs.
         Return 0 if all is well, non-zero on any errors.'''
-        raise NotImplementedError('abstract method')
+        write = self.ui.write
+        failed = False
+
+        write(_('searching %d changesets for big files\n') % len(revs))
+        verified = set()                # set of (filename, filenode) tuples
+
+        for rev in revs:
+            cctx = self.repo[rev]
+            cset = "%d:%s" % (cctx.rev(), node.short(cctx.node()))
+
+            for standin in cctx:
+                failed = (self._verifyfile(cctx, cset, contents,
+                                           standin, verified)
+                          or failed)
+
+        num_revs = len(verified)
+        num_bfiles = len(set([fname for (fname, fnode) in verified]))
+        if contents:
+            write(_('verified contents of %d revisions of %d big files\n')
+                  % (num_revs, num_bfiles))
+        else:
+            write(_('verified existence of %d revisions of %d big files\n')
+                  % (num_revs, num_bfiles))
+
+        return int(failed)
 
     def _getfile(self, tmpfile, filename, hash):
         '''Fetch one revision of one file from the store and write it
@@ -871,6 +895,11 @@
         exist in the store).'''
         raise NotImplementedError('abstract method')
 
+    def _verifyfile(self, cctx, cset, contents, standin, verified):
+        '''Perform the actual verification of a file in the store.
+        '''
+        raise NotImplementedError('abstract method')
+
 class localstore(basestore):
     '''Not necessarily a local store, just one using a regular filesystem
     path.  Could be on the same machine or could be a network mount.'''
@@ -886,36 +915,6 @@
         util.makedirs(destdir)
         shutil.copy(source, dest)
 
-    def verify(self, revs, contents=False):
-        write = self.ui.write
-        failed = False
-
-        write(_('searching %d changesets for big files\n') % len(revs))
-        verified = set()                # set of (filename, filenode) tuples
-
-        for rev in revs:
-            cctx = self.repo[rev]
-            cset = "%d:%s" % (cctx.rev(), node.short(cctx.node()))
-
-            for standin in cctx:
-                failed = (self._verify_file(cctx,
-                                            cset,
-                                            contents,
-                                            standin,
-                                            verified)
-                          or failed)
-
-        num_revs = len(verified)
-        num_bfiles = len(set([fname for (fname, fnode) in verified]))
-        if contents:
-            write(_('verified contents of %d revisions of %d big files\n')
-                  % (num_revs, num_bfiles))
-        else:
-            write(_('verified existence of %d revisions of %d big files\n')
-                  % (num_revs, num_bfiles))
-
-        return int(failed)
-
     def _getfile(self, tmpfile, filename, hash):
         path = os.path.join(self.url, filename, hash)
         try:
@@ -925,7 +924,7 @@
             raise StoreError(filename, hash, path, err.strerror)
         return _copy_and_hash(_blockstream(infile), tmpfile)
 
-    def _verify_file(self, cctx, cset, contents, standin, verified):
+    def _verifyfile(self, cctx, cset, contents, standin, verified):
         filename = _split_standin(standin)
         if not filename:
             return False
@@ -1010,6 +1009,9 @@
             # remote may send "unsynced changes"
             self.abort(error.RepoError(_("put failed: %s") % r))
 
+    def verify(self, revs, contents=False):
+        raise NotImplementedError('abstract method')
+
     def _getfile(self, tmpfile, filename, hash):
         storefile = os.path.join(self.path, filename, hash)
         hasher = hashlib.sha1()
@@ -1133,6 +1135,9 @@
     def put(self, source, filename, hash):
         raise NotImplementedError('sorry, HTTP PUT not implemented yet')
 
+    def verify(self, cctx, cset, contents, standin, verified):
+        raise NotImplementedError('abstract method')
+
     def _getfile(self, tmpfile, filename, hash):
         (baseurl, authinfo) = url_.getauthinfo(self.url)
         url = urlparse.urljoin(baseurl,
@@ -1257,7 +1262,6 @@
         finally:
             fd.close()
 
-
 # -- hg commands declarations ------------------------------------------------
 
 commands.norepo += " bfserve"


More information about the Mercurial-devel mailing list