dul-fetch-pack 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/python
  2. # dul-daemon - Simple git smart server client
  3. # Copyright (C) 2008 Jelmer Vernooij <jelmer@samba.org>
  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. # or (at your option) a later version 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. from dulwich.client import TCPGitClient, SimpleFetchGraphWalker
  20. from dulwich.repo import Repo
  21. import sys
  22. (host, path) = sys.argv[1].split(":", 1)
  23. client = TCPGitClient(host)
  24. all = True
  25. if all:
  26. determine_wants = lambda x: x.values()
  27. else:
  28. determine_wants = lambda x: sys.argv[1:]
  29. r = Repo(".")
  30. # FIXME: Will just fetch everything..
  31. graphwalker = SimpleFetchGraphWalker(r.heads().values(), r.get_parents)
  32. f, commit = r.add_pack()
  33. try:
  34. client.fetch_pack(path, determine_wants, graphwalker, f.write, sys.stdout.write)
  35. f.close()
  36. commit()
  37. except:
  38. f.close()
  39. raise