Skip to content

Commit

Permalink
Remove GitBackendRepo, use plain Repo's instead.
Browse files Browse the repository at this point in the history
  • Loading branch information
jelmer committed Apr 3, 2010
1 parent d2fdaa0 commit 94529d6
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 36 deletions.
2 changes: 1 addition & 1 deletion bin/dul-daemon
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 1 addition & 1 deletion bin/dul-web
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 5 additions & 10 deletions dulwich/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,13 @@ def open_repository(self, path):
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
Expand Down Expand Up @@ -98,15 +102,6 @@ def fetch_objects(self, determine_wants, graph_walker, progress,
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."""

Expand Down
2 changes: 1 addition & 1 deletion dulwich/tests/compat/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def tearDown(self):

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
Expand Down
5 changes: 1 addition & 4 deletions dulwich/tests/compat/test_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
import threading
from wsgiref import simple_server

from dulwich.server import (
GitBackendRepo,
)
from dulwich.web import (
HTTPGitApplication,
)
Expand Down Expand Up @@ -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()
Expand Down
24 changes: 10 additions & 14 deletions dulwich/tests/test_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from unittest import TestCase

from dulwich.objects import (
Tag,
Blob,
)
from dulwich.web import (
Expand Down Expand Up @@ -110,26 +109,23 @@ def __init__(self, sha):

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 {
Expand Down
10 changes: 5 additions & 5 deletions dulwich/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')


Expand All @@ -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')


Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 94529d6

Please sign in to comment.