]> arthur.barton.de Git - bup.git/commitdiff
bup-server: revert to non-midx indexes when suggesting a pack.
authorAvery Pennarun <apenwarr@gmail.com>
Fri, 5 Feb 2010 00:26:17 +0000 (19:26 -0500)
committerAvery Pennarun <apenwarr@gmail.com>
Fri, 5 Feb 2010 00:28:11 +0000 (19:28 -0500)
Currently midx files can't tell you *which* index contains a particular
hash, just that *one* of them does.  So bup-server was barfing when it
expected MultiPackIndex.exists() to return a pack name, and was getting a
.midx file instead.

We could have loosened the assertion and allowed the server to suggest a
.midx file... but those can be huge, and it defeats the purpose of only
suggesting the minimal set of packs so that lightweight clients aren't
overwhelmed.

cmd-server.py
git.py

index 5ca8f36532dc617635eecb8cb51cf9ef12df339c..7cc78a3fb89e4c32988087aa3513818047eef2b5 100755 (executable)
@@ -75,6 +75,20 @@ def receive_objects(conn, junk):
         (type, content) = git._decode_packobj(buf)
         sha = git.calc_hash(type, content)
         oldpack = w.exists(sha)
+        if oldpack and (oldpack == True or oldpack.endswith('.midx')):
+            # FIXME: we shouldn't really have to know about midx files
+            # at this layer.  But exists() on a midx doesn't return the
+            # packname (since it doesn't know)... probably we should just
+            # fix that deficiency of midx files eventually, although it'll
+            # make the files bigger.  This method is certainly not very
+            # efficient.
+            w.objcache.refresh(skip_midx = True, forget_packs = True)
+            oldpack = w.objcache.exists(sha)
+            log('new suggestion: %r\n' % oldpack)
+            assert(oldpack)
+            assert(oldpack != True)
+            assert(not oldpack.endswith('.midx'))
+            w.objcache.refresh(skip_midx = False)
         if oldpack:
             assert(oldpack.endswith('.idx'))
             (dir,name) = os.path.split(oldpack)
diff --git a/git.py b/git.py
index 23c0d46fd6679b8f2227a00e80855048ea5801f7..71ca32d2de75e4091e59d1f47cb4c4306655e355 100644 (file)
--- a/git.py
+++ b/git.py
@@ -230,11 +230,13 @@ class MultiPackIndex:
                 return p.name
         return None
 
-    def refresh(self):
-        global ignore_midx
+    def refresh(self, skip_midx = False, forget_packs = False):
+        if forget_packs:
+            self.packs = []
+        skip_midx = skip_midx or ignore_midx
         d = dict([(p.name, 1) for p in self.packs])
         if os.path.exists(self.dir):
-            if not ignore_midx:
+            if not skip_midx:
                 midxl = []
                 for f in os.listdir(self.dir):
                     full = os.path.join(self.dir, f)