2 # dul-daemon - Simple git smart server client
3 # Copyright (C) 2008 Jelmer Vernooij <jelmer@samba.org>
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.
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.
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,
21 from getopt import getopt
23 def cmd_fetch_pack(args):
24 from dulwich.client import TCPGitClient, SimpleFetchGraphWalker
25 from dulwich.repo import Repo
26 opts, args = getopt(args, "", ["all"])
28 if not ":" in args[0]:
29 print "Usage: dulwich fetch-pack [--all] host:path [REF...]"
31 (host, path) = args.pop(0).split(":", 1)
32 client = TCPGitClient(host)
34 determine_wants = lambda x: [y for y in x.values() if not y in r.object_store]
36 determine_wants = lambda x: [y for y in args if not y in r.object_store]
38 graphwalker = SimpleFetchGraphWalker(r.heads().values(), r.get_parents)
39 f, commit = r.object_store.add_pack()
41 client.fetch_pack(path, determine_wants, graphwalker, f.write, sys.stdout.write)
48 def cmd_dump_pack(args):
49 from dulwich.errors import ApplyDeltaError
50 from dulwich.pack import Pack, sha_to_hex
54 opts, args = getopt(args, "", [])
57 print "Usage: dulwich dump-pack FILENAME"
60 basename, _ = os.path.splitext(args[0])
62 print "Object names checksum: %s" % x.name()
63 print "Checksum: %s" % sha_to_hex(x.get_stored_checksum())
65 print "CHECKSUM DOES NOT MATCH"
66 print "Length: %d" % len(x)
69 print "\t%s" % x[name]
71 print "\t%s: Unable to resolve base %s" % (name, k)
72 except ApplyDeltaError, e:
73 print "\t%s: Unable to apply delta: %r" % (name, e)
76 "fetch-pack": cmd_fetch_pack,
77 "dump-pack": cmd_dump_pack,
81 print "Usage: %s <%s> [OPTIONS...]" % (sys.argv[0], "|".join(commands.keys()))
85 if not cmd in commands:
86 print "No such subcommand: %s" % cmd
88 commands[cmd](sys.argv[2:])