]> arthur.barton.de Git - bup.git/blobdiff - lib/bup/git.py
git.py: flush idx_map before close so FILE* operations will see changes.
[bup.git] / lib / bup / git.py
index 5cb282922c392169dffc6bb9083ae441be606256..00975a713d8849f9d110d0271b657c535cd3b3d0 100644 (file)
@@ -8,7 +8,6 @@ from bup import _helpers, path, midx, bloom, xstat
 
 max_pack_size = 1000*1000*1000  # larger packs will slow down pruning
 max_pack_objects = 200*1000  # cache memory usage is about 83 bytes per object
-SEEK_END=2  # os.SEEK_END is not defined in python 2.4
 
 verbose = 0
 ignore_midx = 0
@@ -127,7 +126,7 @@ def calc_hash(type, content):
     return sum.digest()
 
 
-def _shalist_sort_key(ent):
+def shalist_item_sort_key(ent):
     (mode, name, id) = ent
     assert(mode+0 == mode)
     if stat.S_ISDIR(mode):
@@ -138,7 +137,7 @@ def _shalist_sort_key(ent):
 
 def tree_encode(shalist):
     """Generate a git tree object from (mode,name,hash) tuples."""
-    shalist = sorted(shalist, key = _shalist_sort_key)
+    shalist = sorted(shalist, key = shalist_item_sort_key)
     l = []
     for (mode,name,bin) in shalist:
         assert(mode)
@@ -155,13 +154,13 @@ def tree_decode(buf):
     """Generate a list of (mode,name,hash) from the git tree object in buf."""
     ofs = 0
     while ofs < len(buf):
-        z = buf[ofs:].find('\0')
-        assert(z > 0)
-        spl = buf[ofs:ofs+z].split(' ', 1)
+        z = buf.find('\0', ofs)
+        assert(z > ofs)
+        spl = buf[ofs:z].split(' ', 1)
         assert(len(spl) == 2)
         mode,name = spl
-        sha = buf[ofs+z+1:ofs+z+1+20]
-        ofs += z+1+20
+        sha = buf[z+1:z+1+20]
+        ofs = z+1+20
         yield (int(mode, 8), name, sha)
 
 
@@ -662,9 +661,13 @@ class PackWriter:
         idx_f.truncate(ofs64_ofs)
         idx_f.seek(0)
         idx_map = mmap_readwrite(idx_f, close=False)
-        idx_f.seek(0, SEEK_END)
+        idx_f.seek(0, os.SEEK_END)
         count = _helpers.write_idx(idx_f, idx_map, idx, self.count)
         assert(count == self.count)
+        # Sync, since it doesn't look like POSIX guarantees that a
+        # matching FILE* (i.e. idx_f) will see the parallel changes if
+        # we don't.
+        idx_map.flush()
         idx_map.close()
         idx_f.write(packbin)
 
@@ -830,6 +833,10 @@ def init_repo(path=None):
     p = subprocess.Popen(['git', 'config', 'pack.indexVersion', '2'],
                          stdout=sys.stderr, preexec_fn = _gitenv)
     _git_wait('git config', p)
+    # Enable the reflog
+    p = subprocess.Popen(['git', 'config', 'core.logAllRefUpdates', 'true'],
+                         stdout=sys.stderr, preexec_fn = _gitenv)
+    _git_wait('git config', p)
 
 
 def check_repo_or_die(path=None):
@@ -959,7 +966,8 @@ class CatPipe:
         if not self.p or self.p.poll() != None:
             self._restart()
         assert(self.p)
-        assert(self.p.poll() == None)
+        poll_result = self.p.poll()
+        assert(poll_result == None)
         if self.inprogress:
             log('_fast_get: opening %r while %r is open\n'
                 % (id, self.inprogress))
@@ -985,7 +993,8 @@ class CatPipe:
             yield type
             for blob in it:
                 yield blob
-            assert(self.p.stdout.readline() == '\n')
+            readline_result = self.p.stdout.readline()
+            assert(readline_result == '\n')
             self.inprogress = None
         except Exception, e:
             it.abort()