]> arthur.barton.de Git - bup.git/commitdiff
Dumb server doesn't need objcache
authorBrandon Low <lostlogic@lostlogicx.com>
Sat, 8 Jan 2011 19:55:59 +0000 (11:55 -0800)
committerAvery Pennarun <apenwarr@gmail.com>
Mon, 10 Jan 2011 02:00:25 +0000 (18:00 -0800)
And it's a waste of memory on a low power box.

Signed-off-by: Brandon Low <lostlogic@lostlogicx.com>
cmd/server-cmd.py
lib/bup/client.py
lib/bup/git.py

index 42ec1d4ef4a59242928ce9a5d55f5b249b288369..8ce0e4ee91c6ffb5de02d17ad17d55876459b82d 100755 (executable)
@@ -56,7 +56,10 @@ def receive_objects_v2(conn, junk):
         w = suspended_w
         suspended_w = None
     else:
-        w = git.PackWriter()
+        if dumb_server_mode:
+            w = git.PackWriter(objcache_maker=None)
+        else:
+            w = git.PackWriter()
     while 1:
         ns = conn.read(4)
         if not ns:
@@ -88,39 +91,37 @@ def receive_objects_v2(conn, junk):
             w.abort()
             raise Exception('object read: expected %d bytes, got %d\n'
                             % (n, len(buf)))
-        if dumb_server_mode:
-            oldpack = None
-        else:
+        if not dumb_server_mode:
             oldpack = w.exists(shar)
-        # FIXME: we only suggest a single index per cycle, because the client
-        # is currently too dumb to download more than one per cycle anyway.
-        # Actually we should fix the client, but this is a minor optimization
-        # on the server side.
-        if not suggested and \
-          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.
-            oldpack = w.objcache.packname_containing(shar)
-            debug2('new suggestion: %r\n' % oldpack)
-            assert(oldpack)
-            assert(oldpack != True)
-            assert(not oldpack.endswith('.midx'))
-            w.objcache.refresh()
-        if not suggested and oldpack:
-            assert(oldpack.endswith('.idx'))
-            (dir,name) = os.path.split(oldpack)
-            if not (name in suggested):
-                debug1("bup server: suggesting index %s\n" % name)
-                conn.write('index %s\n' % name)
-                suggested[name] = 1
-        else:
-            nw, crc = w._raw_write([buf], sha=shar)
-            _check(w, crcr, crc, 'object read: expected crc %d, got %d\n')
-            _check(w, n, nw, 'object read: expected %d bytes, got %d\n')
+            # FIXME: we only suggest a single index per cycle, because the client
+            # is currently too dumb to download more than one per cycle anyway.
+            # Actually we should fix the client, but this is a minor optimization
+            # on the server side.
+            if not suggested and \
+              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.
+                oldpack = w.objcache.packname_containing(shar)
+                debug2('new suggestion: %r\n' % oldpack)
+                assert(oldpack)
+                assert(oldpack != True)
+                assert(not oldpack.endswith('.midx'))
+                w.objcache.refresh()
+            if not suggested and oldpack:
+                assert(oldpack.endswith('.idx'))
+                (dir,name) = os.path.split(oldpack)
+                if not (name in suggested):
+                    debug1("bup server: suggesting index %s\n" % name)
+                    conn.write('index %s\n' % name)
+                    suggested[name] = 1
+                continue
+        nw, crc = w._raw_write([buf], sha=shar)
+        _check(w, crcr, crc, 'object read: expected crc %d, got %d\n')
+        _check(w, n, nw, 'object read: expected %d bytes, got %d\n')
     # NOTREACHED
     
 
index f75fab6064cba76761d15c1b03c5620e42355b90..a3eb3a29a12cf5d62b6d37492bb3a568300473f4 100644 (file)
@@ -193,10 +193,6 @@ class Client:
         git.auto_midx(self.cachedir)
 
     def _make_objcache(self):
-        ob = self._busy
-        self._busy = None
-        #self.sync_indexes()
-        self._busy = ob
         return git.PackIdxList(self.cachedir)
 
     def _suggest_pack(self, indexname):
@@ -273,7 +269,6 @@ class PackWriter_Remote(git.PackWriter):
 
     def _open(self):
         if not self._packopen:
-            self._make_objcache()
             if self.onopen:
                 self.onopen()
             self._packopen = True
index 518adc5631b4ce8ebe97d44862fdf49c40a46b60..064bcdfd90218a9d73584a02654fff3813fb5829 100644 (file)
@@ -520,9 +520,12 @@ def idxmerge(idxlist, final_progress=True):
         log('Reading indexes: %.2f%% (%d/%d), done.\n' % (100, total, total))
 
 
+def _make_objcache():
+    return PackIdxList(repo('objects/pack'))
+
 class PackWriter:
     """Writes Git objects insid a pack file."""
-    def __init__(self, objcache_maker=None):
+    def __init__(self, objcache_maker=_make_objcache):
         self.count = 0
         self.outbytes = 0
         self.filename = None
@@ -534,16 +537,8 @@ class PackWriter:
     def __del__(self):
         self.close()
 
-    def _make_objcache(self):
-        if self.objcache == None:
-            if self.objcache_maker:
-                self.objcache = self.objcache_maker()
-            else:
-                self.objcache = PackIdxList(repo('objects/pack'))
-
     def _open(self):
         if not self.file:
-            self._make_objcache()
             (fd,name) = tempfile.mkstemp(suffix='.pack', dir=repo('objects'))
             self.file = os.fdopen(fd, 'w+b')
             assert(name.endswith('.pack'))
@@ -593,14 +588,21 @@ class PackWriter:
         """Write an object in this pack file."""
         return self._write(calc_hash(type, content), type, content)
 
+    def _require_objcache(self):
+        if self.objcache is None and self.objcache_maker:
+            self.objcache = self.objcache_maker()
+        if self.objcache is None:
+            raise GitError(
+                    "PackWriter not opened or can't check exists w/o objcache")
+
     def exists(self, id):
         """Return non-empty if an object is found in the object cache."""
-        if not self.objcache:
-            self._make_objcache()
+        self._require_objcache()
         return self.objcache.exists(id)
 
     def maybe_write(self, type, content):
         """Write an object to the pack file if not present and return its id."""
+        self._require_objcache()
         sha = calc_hash(type, content)
         if not self.exists(sha):
             self._write(sha, type, content)