]> arthur.barton.de Git - bup.git/commitdiff
hashsplit: use shorter offset-filenames inside trees.
authorAvery Pennarun <apenwarr@gmail.com>
Sun, 20 Feb 2011 02:48:06 +0000 (18:48 -0800)
committerAvery Pennarun <apenwarr@gmail.com>
Sun, 20 Feb 2011 05:38:28 +0000 (21:38 -0800)
We previously zero-padded all the filenames (which are hexified versions of
the file offsets) to 16 characters, which corresponds to a maximum file size
that fits into a 64-bit integer.  I realized that there's no reason to
use a fixed padding length; just pad all the entries in a particular tree to
the length of the longest entry (to ensure that sorting
alphabetically is still equivalent to sorting numerically).

This saves a small amount of space in each tree, which is probably
irrelevant given that gzip compression can quite easily compress extra
zeroes.  But it also makes browsing the tree in git look a little prettier.

This is backwards compatible with old versions of vfs.py, since vfs.py has
always just treated the numbers as an ordered set of numbers, and doesn't
care how much zero padding they have.

Signed-off-by: Avery Pennarun <apenwarr@gmail.com>
lib/bup/hashsplit.py

index 2b2163b99899ce03a491fecab72a164b9c249f67..914c2bb5a8e04b532a78e3b860ac2b23216288dc 100644 (file)
@@ -119,11 +119,14 @@ def split_to_blobs(makeblob, files, keep_boundaries, progress):
 
 def _make_shalist(l):
     ofs = 0
+    l = list(l)
+    total = sum(size for mode,sha,size, in l)
+    vlen = len('%x' % total)
     shalist = []
     for (mode, sha, size) in l:
-        shalist.append((mode, '%016x' % ofs, sha))
+        shalist.append((mode, '%0*x' % (vlen,ofs), sha))
         ofs += size
-    total = ofs
+    assert(ofs == total)
     return (shalist, total)