store: change handling of decoding errors
authorMatt Mackall <mpm@selenic.com>
Wed, 13 Aug 2008 20:18:43 -0500
changeset 6900 def492d1b592
parent 6899 56a7a54e074f
child 6901 43a817f3a649
store: change handling of decoding errors
mercurial/localrepo.py
mercurial/store.py
mercurial/verify.py
--- a/mercurial/localrepo.py	Wed Aug 13 20:18:43 2008 -0500
+++ b/mercurial/localrepo.py	Wed Aug 13 20:18:43 2008 -0500
@@ -2066,7 +2066,7 @@
             total_bytes = 0
             # get consistent snapshot of repo, lock during scan
             lock = self.lock()
-            for name, size in self.store.walk():
+            for name, ename, size in self.store.walk():
                 entries.append((name, size))
                 total_bytes += size
             return entries, total_bytes
--- a/mercurial/store.py	Wed Aug 13 20:18:43 2008 -0500
+++ b/mercurial/store.py	Wed Aug 13 20:18:43 2008 -0500
@@ -5,7 +5,6 @@
 # This software may be used and distributed according to the terms
 # of the GNU General Public License, incorporated herein by reference.
 
-from i18n import _
 import os, stat, osutil, util
 
 def _buildencodefun():
@@ -59,7 +58,7 @@
         return os.path.join(self.path, f)
 
     def _walk(self, relpath, recurse):
-        '''yields (filename, size)'''
+        '''yields (unencoded, encoded, size)'''
         path = os.path.join(self.path, relpath)
         striplen = len(self.path) + len(os.sep)
         prefix = path[striplen:]
@@ -71,16 +70,17 @@
                 for f, kind, st in osutil.listdir(p, stat=True):
                     fp = os.path.join(p, f)
                     if kind == stat.S_IFREG and f[-2:] in ('.d', '.i'):
-                        l.append((util.pconvert(fp[striplen:]), st.st_size))
+                        n = util.pconvert(fp[striplen:])
+                        l.append((n, n, st.st_size))
                     elif kind == stat.S_IFDIR and recurse:
                         visit.append(fp)
         return util.sort(l)
 
-    def datafiles(self, reporterror=None):
+    def datafiles(self):
         return self._walk('data', True)
 
     def walk(self):
-        '''yields (direncoded filename, size)'''
+        '''yields (unencoded, encoded, size)'''
         # yield data files first
         for x in self.datafiles():
             yield x
@@ -99,14 +99,13 @@
         op.createmode = self.createmode
         self.opener = lambda f, *args, **kw: op(self.encodefn(f), *args, **kw)
 
-    def datafiles(self, reporterror=None):
-        for f, size in self._walk('data', True):
+    def datafiles(self):
+        for a, b, size in self._walk('data', True):
             try:
-                yield decodefilename(f), size
+                a = decodefilename(a)
             except KeyError:
-                if not reporterror:
-                    raise
-                reporterror(_("cannot decode filename '%s'") % f)
+                a = None
+            yield a, b, size
 
     def join(self, f):
         return os.path.join(self.path, self.encodefn(f))
--- a/mercurial/verify.py	Wed Aug 13 20:18:43 2008 -0500
+++ b/mercurial/verify.py	Wed Aug 13 20:18:43 2008 -0500
@@ -159,16 +159,18 @@
 
     ui.status(_("checking files\n"))
 
-    storefiles = {} 
-    for f, size in repo.store.datafiles(lambda m: err(None, m)):
-        if size > 0:
+    storefiles = {}
+    for f, f2, size in repo.store.datafiles():
+        if not f:
+            err(None, _("cannot decode filename '%s'") % f2)
+        elif size > 0:
             storefiles[f] = True
 
     files = util.sort(util.unique(filenodes.keys() + filelinkrevs.keys()))
     for f in files:
         fl = repo.file(f)
 
-        for ff in fl.files():    
+        for ff in fl.files():
             try:
                 del storefiles[ff]
             except KeyError: