Browse Source

Remove GitBackendRepo, use plain Repo's instead.

Jelmer Vernooij 15 years ago
parent
commit
94529d6b27

+ 1 - 1
bin/dul-daemon

@@ -27,6 +27,6 @@ if __name__ == "__main__":
     else:
         gitdir = "."
 
-    backend = DictBackend({"/": GitBackendRepo(Repo(gitdir))})
+    backend = DictBackend({"/": Repo(gitdir)})
     server = TCPGitServer(backend, 'localhost')
     server.serve_forever()

+ 1 - 1
bin/dul-web

@@ -30,7 +30,7 @@ if __name__ == "__main__":
     else:
         gitdir = os.getcwd()
 
-	backend = DictBackend({"/": GitBackendRepo(Repo(gitdir))})
+	backend = DictBackend({"/": Repo(gitdir)})
     app = HTTPGitApplication(backend)
     # TODO: allow serving on other ports via command-line flag
     server = make_server('', 8000, app)

+ 5 - 10
dulwich/server.py

@@ -64,9 +64,13 @@ class Backend(object):
 class BackendRepo(object):
     """Repository abstraction used by the Git server.
     
-    Eventually this should become just a subset of Repo.
+    Please note that the methods required here are a 
+    subset of those provided by dulwich.repo.Repo.
     """
 
+    object_store = None
+    refs = None
+
     def get_refs(self):
         """
         Get all the refs in the repository
@@ -98,15 +102,6 @@ class BackendRepo(object):
         raise NotImplementedError
 
 
-class GitBackendRepo(BackendRepo):
-
-    def __init__(self, repo):
-        self.repo = repo
-        self.refs = self.repo.refs
-        self.object_store = self.repo.object_store
-        self.fetch_objects = self.repo.fetch_objects
-        self.get_refs = self.repo.get_refs
-
 class DictBackend(Backend):
     """Trivial backend that looks up Git repositories in a dictionary."""
 

+ 1 - 1
dulwich/tests/compat/test_server.py

@@ -66,7 +66,7 @@ class GitServerTestCase(ServerTests, CompatTestCase):
 
     def _start_server(self, repo):
         dul_server = TCPGitServer(
-            server.DictBackend({"/": server.GitBackendRepo(repo)}),
+            server.DictBackend({"/": repo}),
             'localhost', 0)
         threading.Thread(target=dul_server.serve).start()
         self._server = dul_server

+ 1 - 4
dulwich/tests/compat/test_web.py

@@ -27,9 +27,6 @@ On *nix, you can kill the tests with Ctrl-Z, "kill %".
 import threading
 from wsgiref import simple_server
 
-from dulwich.server import (
-    GitBackendRepo,
-    )
 from dulwich.web import (
     HTTPGitApplication,
     )
@@ -68,7 +65,7 @@ class WebTests(ServerTests):
     protocol = 'http'
 
     def _start_server(self, repo):
-        app = self._make_app(GitBackendRepo(repo))
+        app = self._make_app(repo)
         dul_server = simple_server.make_server('localhost', 0, app,
                                                server_class=WSGIServer)
         threading.Thread(target=dul_server.serve_forever).start()

+ 10 - 14
dulwich/tests/test_web.py

@@ -23,7 +23,6 @@ import re
 from unittest import TestCase
 
 from dulwich.objects import (
-    Tag,
     Blob,
     )
 from dulwich.web import (
@@ -110,26 +109,23 @@ class DumbHandlersTestCase(WebTestCase):
 
         tag1 = TestTag('aaa', Blob, '222')
 
-        class TestRepo(object):
-            def __init__(self, objects, peeled):
-                self._objects = dict((o.sha(), o) for o in objects)
-                self._peeled = peeled
-
-            def get_peeled(self, sha):
-                return self._peeled[sha]
-
-            def __getitem__(self, sha):
-                return self._objects[sha]
-
         class TestBackend(object):
+
             def __init__(self):
                 objects = [blob1, blob2, blob3, tag1]
-                self.repo = TestRepo(objects, {
+                self._objects = dict((o.sha(), o) for o in objects)
+                self._peeled = {
                     'HEAD': '000',
                     'refs/heads/master': blob1.sha(),
                     'refs/tags/tag-tag': blob2.sha(),
                     'refs/tags/blob-tag': blob3.sha(),
-                    })
+                    }
+
+            def __getitem__(self, sha):
+                return self._objects[sha]
+
+            def get_peeled(self, sha):
+                return self._peeled[sha]
 
             def get_refs(self):
                 return {

+ 5 - 5
dulwich/web.py

@@ -73,7 +73,7 @@ def send_file(req, f, content_type):
 
 def get_text_file(req, backend, mat):
     req.nocache()
-    return send_file(req, backend.repo.get_named_file(mat.group()),
+    return send_file(req, backend.get_named_file(mat.group()),
                      'text/plain')
 
 
@@ -94,13 +94,13 @@ def get_loose_object(req, backend, mat):
 
 def get_pack_file(req, backend, mat):
     req.cache_forever()
-    return send_file(req, backend.repo.get_named_file(mat.group()),
+    return send_file(req, backend.get_named_file(mat.group()),
                      'application/x-git-packed-objects')
 
 
 def get_idx_file(req, backend, mat):
     req.cache_forever()
-    return send_file(req, backend.repo.get_named_file(mat.group()),
+    return send_file(req, backend.get_named_file(mat.group()),
                      'application/x-git-packed-objects-toc')
 
 
@@ -138,11 +138,11 @@ def get_info_refs(req, backend, mat, services=None):
             if name == 'HEAD':
                 continue
             sha = refs[name]
-            o = backend.repo[sha]
+            o = backend[sha]
             if not o:
                 continue
             yield '%s\t%s\n' % (sha, name)
-            peeled_sha = backend.repo.get_peeled(name)
+            peeled_sha = backend.get_peeled(name)
             if peeled_sha != sha:
                 yield '%s\t%s^{}\n' % (peeled_sha, name)