#!/usr/bin/python # dul-daemon - Simple git-daemon a like # Copyright (C) 2008 John Carr # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; version 2 # of the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. import os, 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=None): self.gitdir = gitdir if not self.gitdir: self.gitdir = tempfile.mkdtemp() Repo.create(self.gitdir) self.repo = Repo(self.gitdir) def get_refs(self): refs = [] if self.repo.head(): refs.append(('HEAD', self.repo.head())) for refsha in self.repo.heads().items(): refs.append(refsha) return refs def has_revision(self, sha): return False def apply_pack(self, refs, read): # store the incoming pack in the repository fd, name = tempfile.mkstemp(suffix='pack', prefix='', dir=self.repo.pack_dir()) os.write(fd, read()) os.close(fd) # 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__": gitdir = None if len(sys.argv) > 1: gitdir = sys.argv[1] backend = GitBackend(gitdir) server = TCPGitServer(backend, ('localhost', 9418)) server.serve_forever()