dul-daemon 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 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(gitdir)
  30. def get_refs(self):
  31. return [('HEAD', self.repo.head())] +
  32. [tuple(refsha) for refsha in self.repo.heads().items()]
  33. def has_revision(self, sha):
  34. return False
  35. def apply_pack(self, refs, read):
  36. # store the incoming pack in the repository
  37. fd, name = tempfile.mkstemp(suffix='pack', prefix='', dir=self.repo.packdir())
  38. fd.write(read())
  39. fd.close()
  40. # strip '.pack' off our filename
  41. basename = name[:-5]
  42. # generate an index for it
  43. pd = PackData(name)
  44. pd.create_index_v2(basename+".idx")
  45. # FIXME: Update heads
  46. def generate_pack(self, want, have, write, progress):
  47. pass
  48. if __name__ == "__main__":
  49. gitdir = None
  50. if len(sys.argv) > 1:
  51. gitdir = sys.argv[1]
  52. backend = GitBackend(gitdir)
  53. server = TCPGitServer(backend, ('localhost', 9418))
  54. server.serve_forever()