dul-fetch-pack 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. from getopt import getopt
  23. opts, args = getopt(sys.argv[1:], "", ["all"])
  24. opts = dict(opts)
  25. if args == []:
  26. print "Usage: dul-fetch-pack host:path"
  27. sys.exit(1)
  28. if not ":" in args[0]:
  29. print "Usage: dul-fetch-pack host:path"
  30. sys.exit(1)
  31. (host, path) = args.pop(0).split(":", 1)
  32. client = TCPGitClient(host)
  33. if "--all" in opts:
  34. determine_wants = lambda x: [y for y in x.values() if not y in r.object_store]
  35. else:
  36. determine_wants = lambda x: [y for y in args if not y in r.object_store]
  37. r = Repo(".")
  38. # FIXME: Will just fetch everything..
  39. graphwalker = SimpleFetchGraphWalker(r.heads().values(), r.get_parents)
  40. f, commit = r.object_store.add_pack()
  41. try:
  42. client.fetch_pack(path, determine_wants, graphwalker, f.write, sys.stdout.write)
  43. f.close()
  44. commit()
  45. except:
  46. f.close()
  47. raise