]> arthur.barton.de Git - bup.git/commitdiff
midx4: Fix name offsets when generated from idx
authorBrandon Low <lostlogic@lostlogicx.com>
Tue, 8 Feb 2011 18:43:22 +0000 (10:43 -0800)
committerAvery Pennarun <apenwarr@gmail.com>
Tue, 8 Feb 2011 22:32:41 +0000 (14:32 -0800)
This was a nasty bug, glad it got found before release.  Only effected
the server's ability to suggest .idxs so far, but would have effected
any attempt to have bup retrieve objects directly too.

Signed-off-by: Brandon Low <lostlogic@lostlogicx.com>
lib/bup/_helpers.c
lib/bup/git.py
lib/bup/t/tgit.py

index 938b7a3ad50ffbec02cc8193608779d62dde7854..0af94113bd87d0116576f165b93e533b702c067e 100644 (file)
@@ -330,7 +330,10 @@ static PyObject *merge_into(PyObject *self, PyObject *args)
            return NULL;
        idxs[i]->cur = (struct sha *)&idxs[i]->map[sha_ofs];
        idxs[i]->end = &idxs[i]->cur[len];
-       idxs[i]->cur_name = (uint32_t *)&idxs[i]->map[name_map_ofs];
+       if (name_map_ofs)
+           idxs[i]->cur_name = (uint32_t *)&idxs[i]->map[name_map_ofs];
+       else
+           idxs[i]->cur_name = NULL;
     }
     table_ptr = (uint32_t *)&fmap[12];
     sha_ptr = (struct sha *)&table_ptr[1<<bits];
index 153971143e65b8970fdc450a90b4627001b81947..8a6808e03b59a5070babe73dbee51b3b49e66ee9 100644 (file)
@@ -250,7 +250,7 @@ class PackIdx:
     def exists(self, hash, want_source=False):
         """Return nonempty if the object exists in this index."""
         if hash and (self._idx_from_hash(hash) != None):
-            return want_source and self.name or True
+            return want_source and os.path.basename(self.name) or True
         return None
 
     def __len__(self):
index f5e0237c064cceb8c58987ba87da15fcff818143..656303784a68a8f215461156fcd5d5e8b87c2422 100644 (file)
@@ -89,6 +89,50 @@ def testpacks():
     WVPASS(r.exists(hashes[6]))
     WVFAIL(r.exists('\0'*20))
 
+
+@wvtest
+def test_pack_name_lookup():
+    os.environ['BUP_MAIN_EXE'] = bupmain = '../../../bup'
+    os.environ['BUP_DIR'] = bupdir = 'pybuptest.tmp'
+    subprocess.call(['rm','-rf', bupdir])
+    git.init_repo(bupdir)
+    git.verbose = 1
+
+    idxnames = []
+
+    w = git.PackWriter()
+    hashes = []
+    for i in range(2):
+        hashes.append(w.new_blob(str(i)))
+    log('\n')
+    idxnames.append(w.close() + '.idx')
+
+    w = git.PackWriter()
+    for i in range(2,4):
+        hashes.append(w.new_blob(str(i)))
+    log('\n')
+    idxnames.append(w.close() + '.idx')
+
+    idxnames = [os.path.basename(ix) for ix in idxnames]
+
+    def verify(r):
+       for i in range(2):
+           WVPASSEQ(r.exists(hashes[i], want_source=True), idxnames[0])
+       for i in range(2,4):
+           WVPASSEQ(r.exists(hashes[i], want_source=True), idxnames[1])
+
+    r = git.PackIdxList('pybuptest.tmp/objects/pack')
+    WVPASSEQ(len(r.packs), 2)
+    verify(r)
+    del r
+
+    subprocess.call([bupmain, 'midx', '-f'])
+
+    r = git.PackIdxList('pybuptest.tmp/objects/pack')
+    WVPASSEQ(len(r.packs), 1)
+    verify(r)
+
+
 @wvtest
 def test_long_index():
     w = git.PackWriter()