瀏覽代碼

dul-daemon can accept incoming packs (store them in the repository, and index them).

John Carr 16 年之前
父節點
當前提交
cc20a122f7
共有 2 個文件被更改,包括 30 次插入7 次删除
  1. 29 6
      bin/dul-daemon
  2. 1 1
      dulwich/server.py

+ 29 - 6
bin/dul-daemon

@@ -17,30 +17,53 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 # MA  02110-1301, USA.
 
-import sys
+import sys, tempfile
 from dulwich.server import Backend, TCPGitServer
 from dulwich.repo import Repo
+from dulwich.pack import PackData, Pack
 
 class GitBackend(Backend):
 
-    def __init__(self, gitdir):
+    def __init__(self, gitdir=None):
         self.gitdir = gitdir
-        self.repository = Repo(gitdir)
+
+        if not self.gitdir:
+            self.gitdir = tempfile.mkdtemp()
+            Repo.create(self.gitdir)
+
+        self.repo = Repo(gitdir)
 
     def get_refs(self):
-	return [tuple(refsha) for refsha in self.repository.heads().items()]
+	return [('HEAD', self.repo.head())] +  
+           [tuple(refsha) for refsha in self.repo.heads().items()]
 
     def has_revision(self, sha):
         return False
 
     def apply_pack(self, refs, read):
-        read()
+        # store the incoming pack in the repository
+        fd, name = tempfile.mkstemp(suffix='pack', prefix='', dir=self.repo.packdir())
+        fd.write(read())
+        fd.close()
+
+        # strip '.pack' off our filename
+        basename = name[:-5]
+
+        # generate an index for it
+        pd = PackData(name)
+        pd.create_index_v2(basename+".idx")
+
+        # FIXME: Update heads
 
     def generate_pack(self, want, have, write, progress):
         pass
 
 
 if __name__ == "__main__":
-    backend = GitBackend(sys.argv[1])
+    gitdir = None
+    if len(sys.argv) > 1:
+        gitdir = sys.argv[1]
+
+    backend = GitBackend(gitdir)
     server = TCPGitServer(backend, ('localhost', 9418))
     server.serve_forever()

+ 1 - 1
dulwich/server.py

@@ -125,7 +125,7 @@ class UploadPackHandler(Handler):
         # Keep reading the list of demands until we hit another "0000" 
         want_revs = []
         while want and want[:4] == 'want':
-            want_rev = want[5:]
+            want_rev = want[5:40]
             # FIXME: This check probably isnt needed?
             if self.backend.has_revision(want_rev):
                want_revs.append(want_rev)