Skip ^{} tags.
[jelmer/dulwich-libgit2.git] / bin / dulwich
index 0d9b235256dfd6a0eb9a2c30bb9e0d6310212270..83b399791ea5313fe05f6bf84562a1e223baedf5 100755 (executable)
 import sys
 from getopt import getopt
 
+def get_transport_and_path(uri):
+    from dulwich.client import TCPGitClient, SSHGitClient, SubprocessGitClient
+    for handler, transport in (("git://", TCPGitClient), ("git+ssh://", SSHGitClient)):
+        if uri.startswith(handler):
+            host, path = uri[len(handler):].split("/", 1)
+            return transport(host), "/"+path
+    # if its not git or git+ssh, try a local url..
+    return SubprocessGitClient(), uri
+
+
 def cmd_fetch_pack(args):
-       from dulwich.client import TCPGitClient, SimpleFetchGraphWalker
+       from dulwich.client import SimpleFetchGraphWalker
        from dulwich.repo import Repo
        opts, args = getopt(args, "", ["all"])
        opts = dict(opts)
-       if not ":" in args[0]:
-               print "Usage: dulwich fetch-pack [--all] host:path [REF...]"
-               sys.exit(1)
-       (host, path) = args.pop(0).split(":", 1)
-       client = TCPGitClient(host)
+        client, path = get_transport_and_path(args.pop(0))
        if "--all" in opts:
-               determine_wants = lambda x: [y for y in x.values() if not y in r.object_store]
+               determine_wants = r.object_store.determine_wants_all
        else:
                determine_wants = lambda x: [y for y in args if not y in r.object_store]
        r = Repo(".")
@@ -98,6 +104,23 @@ def cmd_dump_pack(args):
                except ApplyDeltaError, e:
                        print "\t%s: Unable to apply delta: %r" % (name, e)
 
+
+def cmd_dump_index(args):
+       from dulwich.index import Index
+
+       opts, args = getopt(args, "", [])
+
+       if args == []:
+               print "Usage: dulwich dump-pack FILENAME"
+               sys.exit(1)
+
+       filename = args[0]
+       idx = Index(filename)
+
+       for o in idx:
+               print o[0]
+
+
 def cmd_init(args):
        from dulwich.repo import Repo
        import os
@@ -120,7 +143,7 @@ def cmd_init(args):
 
 
 def cmd_clone(args):
-       from dulwich.client import TCPGitClient, SimpleFetchGraphWalker
+       from dulwich.client import SimpleFetchGraphWalker
        from dulwich.repo import Repo
        import os
        import sys
@@ -130,12 +153,7 @@ def cmd_clone(args):
        if args == []:
                print "usage: dulwich clone host:path [PATH]"
                sys.exit(1)
-
-       if not ":" in args[0]:
-               print "Usage: dulwich clone host:path [PATH]"
-               sys.exit(1)
-       (host, host_path) = args.pop(0).split(":", 1)
-       client = TCPGitClient(host)
+        client, host_path = get_transport_and_path(args.pop(0))
 
        if len(args) > 0:
                path = args.pop(0)
@@ -146,11 +164,10 @@ def cmd_clone(args):
                os.mkdir(path)
        Repo.init(path)
        r = Repo(path)
-       determine_wants = lambda x: [y for y in x.values() if not y in r.object_store]
        graphwalker = SimpleFetchGraphWalker(r.heads().values(), r.get_parents)
        f, commit = r.object_store.add_pack()
        try:
-               client.fetch_pack(host_path, determine_wants, graphwalker, f.write, 
+               client.fetch_pack(host_path, r.object_store.determine_wants_all, graphwalker, f.write, 
                                          sys.stdout.write)
                f.close()
                commit()
@@ -162,6 +179,7 @@ def cmd_clone(args):
 commands = {
        "fetch-pack": cmd_fetch_pack,
        "dump-pack": cmd_dump_pack,
+       "dump-index": cmd_dump_index,
        "init": cmd_init,
        "log": cmd_log,
        "clone": cmd_clone,