Skip to content

Commit

Permalink
Move get_transport_and_path to dulwich.client.
Browse files Browse the repository at this point in the history
  • Loading branch information
jelmer committed Mar 24, 2010
1 parent 839d13c commit 12e1c54
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
30 changes: 7 additions & 23 deletions bin/dulwich
Expand Up @@ -17,21 +17,18 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.

import os
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
from dulwich.client import get_transport_and_path
from dulwich.errors import ApplyDeltaError
from dulwich.index import Index
from dulwich.pack import Pack, sha_to_hex
from dulwich.repo import Repo


def cmd_fetch_pack(args):
from dulwich.repo import Repo
opts, args = getopt(args, "", ["all"])
opts = dict(opts)
client, path = get_transport_and_path(args.pop(0))
Expand All @@ -45,7 +42,6 @@ def cmd_fetch_pack(args):


def cmd_log(args):
from dulwich.repo import Repo
opts, args = getopt(args, "", [])
if len(args) > 0:
path = args.pop(0)
Expand All @@ -60,7 +56,7 @@ def cmd_log(args):
if sha in done:
continue
done.add(sha)
commit = r.commit(sha)
commit = r[sha]
print "-" * 50
print "commit: %s" % sha
if len(commit.parents) > 1:
Expand All @@ -74,10 +70,6 @@ def cmd_log(args):


def cmd_dump_pack(args):
from dulwich.errors import ApplyDeltaError
from dulwich.pack import Pack, sha_to_hex
import os
import sys

opts, args = getopt(args, "", [])

Expand All @@ -102,7 +94,6 @@ def cmd_dump_pack(args):


def cmd_dump_index(args):
from dulwich.index import Index

opts, args = getopt(args, "", [])

Expand All @@ -118,8 +109,6 @@ def cmd_dump_index(args):


def cmd_init(args):
from dulwich.repo import Repo
import os
opts, args = getopt(args, "", ["--bare"])
opts = dict(opts)

Expand All @@ -138,9 +127,6 @@ def cmd_init(args):


def cmd_clone(args):
from dulwich.repo import Repo
import os
import sys
opts, args = getopt(args, "", [])
opts = dict(opts)

Expand All @@ -164,8 +150,6 @@ def cmd_clone(args):


def cmd_commit(args):
from dulwich.repo import Repo
import os
opts, args = getopt(args, "", ["message"])
opts = dict(opts)
r = Repo(".")
Expand Down
15 changes: 15 additions & 0 deletions dulwich/client.py
Expand Up @@ -334,3 +334,18 @@ def fetch_pack(self, path, determine_wants, graph_walker, pack_data,
client = GitClient(lambda: _fileno_can_read(remote.proc.stdout.fileno()), remote.recv, remote.send, *self._args, **self._kwargs)
return client.fetch_pack(path, determine_wants, graph_walker, pack_data,
progress)


def get_transport_and_path(uri):
"""Obtain a git client from a URI or path.
:param uri: URI or path
:return: Tuple with client instance and relative path.
"""
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

0 comments on commit 12e1c54

Please sign in to comment.