dul-daemon 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/usr/bin/python
  2. # dul-daemon - Simple git-daemon a like
  3. # Copyright (C) 2008 John Carr <john.carr@unrouted.co.uk>
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; version 2
  8. # of the License.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  18. # MA 02110-1301, USA.
  19. import os, sys, tempfile
  20. from dulwich.server import Backend, TCPGitServer
  21. from dulwich.repo import Repo
  22. from dulwich.pack import PackData, Pack
  23. class GitBackend(Backend):
  24. def __init__(self, gitdir=None):
  25. self.gitdir = gitdir
  26. if not self.gitdir:
  27. self.gitdir = tempfile.mkdtemp()
  28. Repo.create(self.gitdir)
  29. self.repo = Repo(self.gitdir)
  30. def get_refs(self):
  31. refs = []
  32. if self.repo.head():
  33. refs.append(('HEAD', self.repo.head()))
  34. for refsha in self.repo.heads().items():
  35. refs.append(refsha)
  36. return refs
  37. def has_revision(self, sha):
  38. return False
  39. def apply_pack(self, refs, read):
  40. # store the incoming pack in the repository
  41. fd, name = tempfile.mkstemp(suffix='pack', prefix='', dir=self.repo.pack_dir())
  42. os.write(fd, read())
  43. os.close(fd)
  44. # strip '.pack' off our filename
  45. basename = name[:-5]
  46. # generate an index for it
  47. pd = PackData(name)
  48. pd.create_index_v2(basename+".idx")
  49. # FIXME: Update heads
  50. def generate_pack(self, want, have, write, progress):
  51. pass
  52. if __name__ == "__main__":
  53. gitdir = None
  54. if len(sys.argv) > 1:
  55. gitdir = sys.argv[1]
  56. backend = GitBackend(gitdir)
  57. server = TCPGitServer(backend, ('localhost', 9418))
  58. server.serve_forever()