[PATCH STABLE v2] store: remove zero size files from fncache

Adrian Buehlmann adrian at cadifra.com
Wed Mar 3 14:33:51 CST 2010


# HG changeset patch
# User Adrian Buehlmann <adrian at cadifra.com>
# Date 1267641462 -3600
# Branch stable
# Node ID 1ff171d92a179e864872f909faed7a9483e1c827
# Parent  d5bd1beff794461611bb37999a79bd110c88d008
store: remove zero size files from fncache

'hg strip' truncates files in the store to zero if those files were added in a
stripped changeset.

These zero-size files should be treated the same as nonexistent fncache entries,
i.e. not be yielded by store.fncachestore.datafiles and removed from the fncache
file.

Generally, datafiles does not return zero-size files anymore for all store kinds.

diff --git a/mercurial/store.py b/mercurial/store.py
--- a/mercurial/store.py
+++ b/mercurial/store.py
@@ -197,7 +197,9 @@ class basicstore(object):
         return sorted(l)
 
     def datafiles(self):
-        return self._walk('data', True)
+        for a, b, size in self._walk('data', True):
+            if size != 0:
+                yield a, b, size
 
     def walk(self):
         '''yields (unencoded, encoded, size)'''
@@ -222,11 +224,12 @@ class encodedstore(basicstore):
 
     def datafiles(self):
         for a, b, size in self._walk('data', True):
-            try:
-                a = decodefilename(a)
-            except KeyError:
-                a = None
-            yield a, b, size
+            if size != 0:
+                try:
+                    a = decodefilename(a)
+                except KeyError:
+                    a = None
+                yield a, b, size
 
     def join(self, f):
         return self.pathjoiner(self.path, encodefilename(f))
@@ -309,8 +312,12 @@ class fncachestore(basicstore):
             ef = hybridencode(f)
             try:
                 st = os.stat(pjoin(spath, ef))
-                yield f, ef, st.st_size
-                existing.append(f)
+                if st.st_size != 0:
+                    yield f, ef, st.st_size
+                    existing.append(f)
+                else:
+                    # stripped by mq, remove entry from fncache
+                    rewrite = True
             except OSError:
                 # nonexistent entry
                 rewrite = True
diff --git a/mercurial/verify.py b/mercurial/verify.py
--- a/mercurial/verify.py
+++ b/mercurial/verify.py
@@ -197,7 +197,7 @@ def _verify(repo):
     for f, f2, size in repo.store.datafiles():
         if not f:
             err(None, _("cannot decode filename '%s'") % f2)
-        elif size > 0:
+        else:
             storefiles.add(f)
 
     files = sorted(set(filenodes) | set(filelinkrevs))
diff --git a/tests/test-mq-strip b/tests/test-mq-strip
--- a/tests/test-mq-strip
+++ b/tests/test-mq-strip
@@ -51,3 +51,30 @@ hg parents
 hg strip 4 2>&1 | sed 's/\(saving bundle to \).*/\1/'
 echo % after strip of merge parent
 hg parents
+
+echo
+echo % "testing: removal of stripped files from fncache file by hg verify"
+hg init a
+cd a
+echo foo > bar.txt
+hg add
+hg ci -m0
+echo bla > another.txt
+hg add
+hg ci -m1
+echo
+echo % "cat .hg/store/fncache"
+cat .hg/store/fncache
+echo
+echo % "hg strip --nobackup 1"
+hg strip --nobackup 1
+echo
+echo % "cat .hg/store/fncache"
+cat .hg/store/fncache
+echo
+echo % "hg verify"
+hg verify
+echo
+echo % "cat .hg/store/fncache"
+cat .hg/store/fncache
+
diff --git a/tests/test-mq-strip.out b/tests/test-mq-strip.out
--- a/tests/test-mq-strip.out
+++ b/tests/test-mq-strip.out
@@ -171,3 +171,28 @@ user:        test
 date:        Thu Jan 01 00:00:00 1970 +0000
 summary:     b
 
+
+% testing: removal of stripped files from fncache file by hg verify
+adding bar.txt
+adding another.txt
+
+% cat .hg/store/fncache
+data/bar.txt.i
+data/another.txt.i
+
+% hg strip --nobackup 1
+0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+
+% cat .hg/store/fncache
+data/bar.txt.i
+data/another.txt.i
+
+% hg verify
+checking changesets
+checking manifests
+crosschecking files in changesets and manifests
+checking files
+1 files, 1 changesets, 1 total revisions
+
+% cat .hg/store/fncache
+data/bar.txt.i


More information about the Mercurial-devel mailing list