dulwich.client module¶
Client side support for the Git protocol.
The Dulwich client supports the following capabilities:
- thin-pack
- multi_ack_detailed
- multi_ack
- side-band-64k
- ofs-delta
- quiet
- report-status
- delete-refs
Known capabilities that are not supported:
- shallow
- no-progress
- include-tag
-
class
dulwich.client.
FetchPackResult
(refs, symrefs, agent, new_shallow=None, new_unshallow=None)¶ Bases:
object
Result of a fetch-pack operation.
Variables: - refs – Dictionary with all remote refs
- symrefs – Dictionary with remote symrefs
- agent – User agent string
-
class
dulwich.client.
GitClient
(thin_packs=True, report_activity=None, quiet=False)¶ Bases:
object
Git smart server client.
Create a new GitClient instance.
Parameters: - thin_packs – Whether or not thin packs should be retrieved
- report_activity – Optional callback for reporting transport activity.
-
fetch
(path, target, determine_wants=None, progress=None, depth=None)¶ Fetch into a target repository.
Parameters: - path – Path to fetch from (as bytestring)
- target – Target repository to fetch into
- determine_wants – Optional function to determine what refs to fetch. Receives dictionary of name->sha, should return list of shas to fetch. Defaults to all shas.
- progress – Optional progress function
- depth – Depth to fetch at
Returns: Dictionary with all remote refs (not just those fetched)
-
fetch_pack
(path, determine_wants, graph_walker, pack_data, progress=None, depth=None)¶ Retrieve a pack from a git smart server.
Parameters: - path – Remote path to fetch from
- determine_wants – Function determine what refs to fetch. Receives dictionary of name->sha, should return list of shas to fetch.
- graph_walker – Object with next() and ack().
- pack_data – Callback called for each bit of data in the pack
- progress – Callback for progress reports (strings)
- depth – Shallow fetch depth
Returns: FetchPackResult object
-
classmethod
from_parsedurl
(parsedurl, **kwargs)¶ Create an instance of this client from a urlparse.parsed object.
Parameters: parsedurl – Result of urlparse.urlparse() Returns: A GitClient object
-
get_refs
(path)¶ Retrieve the current refs from a git smart server.
Parameters: path – Path to the repo to fetch from. (as bytestring)
-
get_url
(path)¶ Retrieves full url to given path.
Parameters: path – Repository path (as string) Returns: Url to path (as string)
-
send_pack
(path, update_refs, generate_pack_data, progress=None)¶ Upload a pack to a remote repository.
Parameters: - path – Repository path (as bytestring)
- update_refs – Function to determine changes to remote refs. Receive dict with existing remote refs, returns dict with changed refs (name -> sha, where sha=ZERO_SHA for deletions)
- generate_pack_data – Function that can return a tuple with number of objects and list of pack data to include
- progress – Optional progress function
Raises: - SendPackError – if server rejects the pack data
- UpdateRefsError – if the server supports report-status and rejects ref updates
Returns: new_refs dictionary containing the changes that were made {refname: new_ref}, including deleted refs.
-
class
dulwich.client.
HttpGitClient
(base_url, dumb=None, pool_manager=None, config=None, username=None, password=None, **kwargs)¶ Bases:
dulwich.client.GitClient
-
fetch_pack
(path, determine_wants, graph_walker, pack_data, progress=None, depth=None)¶ Retrieve a pack from a git smart server.
Parameters: - determine_wants – Callback that returns list of commits to fetch
- graph_walker – Object with next() and ack().
- pack_data – Callback called for each bit of data in the pack
- progress – Callback for progress reports (strings)
- depth – Depth for request
Returns: FetchPackResult object
-
classmethod
from_parsedurl
(parsedurl, **kwargs)¶ Create an instance of this client from a urlparse.parsed object.
Parameters: parsedurl – Result of urlparse.urlparse() Returns: A GitClient object
-
get_refs
(path)¶ Retrieve the current refs from a git smart server.
-
get_url
(path)¶ Retrieves full url to given path.
Parameters: path – Repository path (as string) Returns: Url to path (as string)
-
send_pack
(path, update_refs, generate_pack_data, progress=None)¶ Upload a pack to a remote repository.
Parameters: - path – Repository path (as bytestring)
- update_refs – Function to determine changes to remote refs. Receive dict with existing remote refs, returns dict with changed refs (name -> sha, where sha=ZERO_SHA for deletions)
- generate_pack_data – Function that can return a tuple with number of elements and pack data to upload.
- progress – Optional progress function
Raises: - SendPackError – if server rejects the pack data
- UpdateRefsError – if the server supports report-status and rejects ref updates
Returns: new_refs dictionary containing the changes that were made {refname: new_ref}, including deleted refs.
-
-
exception
dulwich.client.
InvalidWants
(wants)¶ Bases:
exceptions.Exception
Invalid wants.
-
class
dulwich.client.
LocalGitClient
(thin_packs=True, report_activity=None, config=None)¶ Bases:
dulwich.client.GitClient
Git Client that just uses a local Repo.
Create a new LocalGitClient instance.
Parameters: - thin_packs – Whether or not thin packs should be retrieved
- report_activity – Optional callback for reporting transport activity.
-
fetch
(path, target, determine_wants=None, progress=None, depth=None)¶ Fetch into a target repository.
Parameters: - path – Path to fetch from (as bytestring)
- target – Target repository to fetch into
- determine_wants – Optional function determine what refs to fetch. Receives dictionary of name->sha, should return list of shas to fetch. Defaults to all shas.
- progress – Optional progress function
- depth – Shallow fetch depth
Returns: FetchPackResult object
-
fetch_pack
(path, determine_wants, graph_walker, pack_data, progress=None, depth=None)¶ Retrieve a pack from a git smart server.
Parameters: - path – Remote path to fetch from
- determine_wants – Function determine what refs to fetch. Receives dictionary of name->sha, should return list of shas to fetch.
- graph_walker – Object with next() and ack().
- pack_data – Callback called for each bit of data in the pack
- progress – Callback for progress reports (strings)
- depth – Shallow fetch depth
Returns: FetchPackResult object
-
classmethod
from_parsedurl
(parsedurl, **kwargs)¶ Create an instance of this client from a urlparse.parsed object.
Parameters: parsedurl – Result of urlparse.urlparse() Returns: A GitClient object
-
get_refs
(path)¶ Retrieve the current refs from a git smart server.
-
get_url
(path)¶ Retrieves full url to given path.
Parameters: path – Repository path (as string) Returns: Url to path (as string)
-
send_pack
(path, update_refs, generate_pack_data, progress=None)¶ Upload a pack to a remote repository.
Parameters: - path – Repository path (as bytestring)
- update_refs – Function to determine changes to remote refs. Receive dict with existing remote refs, returns dict with changed refs (name -> sha, where sha=ZERO_SHA for deletions)
- generate_pack_data – Function that can return a tuple with number of items and pack data to upload.
- progress – Optional progress function
Raises: - SendPackError – if server rejects the pack data
- UpdateRefsError – if the server supports report-status and rejects ref updates
Returns: new_refs dictionary containing the changes that were made {refname: new_ref}, including deleted refs.
-
class
dulwich.client.
PLinkSSHVendor
¶ Bases:
dulwich.client.SSHVendor
SSH vendor that shells out to the local ‘plink’ command.
-
run_command
(host, command, username=None, port=None, password=None, key_filename=None)¶ Connect to an SSH server.
Run a command remotely and return a file-like object for interaction with the remote command.
Parameters: - host – Host name
- command – Command to run (as argv array)
- username – Optional ame of user to log in as
- port – Optional SSH port to use
- password – Optional ssh password for login or private key
- key_filename – Optional path to private keyfile
-
-
dulwich.client.
ParamikoSSHVendor
(**kwargs)¶
-
class
dulwich.client.
ReportStatusParser
¶ Bases:
object
Handle status as reported by servers with ‘report-status’ capability.
-
check
()¶ Check if there were any errors and, if so, raise exceptions.
Raises: - SendPackError – Raised when the server could not unpack
- UpdateRefsError – Raised when refs could not be updated
-
handle_packet
(pkt)¶ Handle a packet.
Raises: GitProtocolError – Raised when packets are received after a flush packet.
-
-
class
dulwich.client.
SSHGitClient
(host, port=None, username=None, vendor=None, config=None, password=None, key_filename=None, **kwargs)¶ Bases:
dulwich.client.TraditionalGitClient
-
classmethod
from_parsedurl
(parsedurl, **kwargs)¶ Create an instance of this client from a urlparse.parsed object.
Parameters: parsedurl – Result of urlparse.urlparse() Returns: A GitClient object
-
get_url
(path)¶ Retrieves full url to given path.
Parameters: path – Repository path (as string) Returns: Url to path (as string)
-
classmethod
-
class
dulwich.client.
SSHVendor
¶ Bases:
object
A client side SSH implementation.
-
connect_ssh
(host, command, username=None, port=None, password=None, key_filename=None)¶
-
run_command
(host, command, username=None, port=None, password=None, key_filename=None)¶ Connect to an SSH server.
Run a command remotely and return a file-like object for interaction with the remote command.
Parameters: - host – Host name
- command – Command to run (as argv array)
- username – Optional ame of user to log in as
- port – Optional SSH port to use
- password – Optional ssh password for login or private key
- key_filename – Optional path to private keyfile
-
-
exception
dulwich.client.
StrangeHostname
(hostname)¶ Bases:
exceptions.Exception
Refusing to connect to strange SSH hostname.
-
class
dulwich.client.
SubprocessGitClient
(path_encoding='utf-8', **kwargs)¶ Bases:
dulwich.client.TraditionalGitClient
Git client that talks to a server using a subprocess.
-
classmethod
from_parsedurl
(parsedurl, **kwargs)¶ Create an instance of this client from a urlparse.parsed object.
Parameters: parsedurl – Result of urlparse.urlparse() Returns: A GitClient object
-
git_command
= None¶
-
classmethod
-
class
dulwich.client.
SubprocessSSHVendor
¶ Bases:
dulwich.client.SSHVendor
SSH vendor that shells out to the local ‘ssh’ command.
-
run_command
(host, command, username=None, port=None, password=None, key_filename=None)¶ Connect to an SSH server.
Run a command remotely and return a file-like object for interaction with the remote command.
Parameters: - host – Host name
- command – Command to run (as argv array)
- username – Optional ame of user to log in as
- port – Optional SSH port to use
- password – Optional ssh password for login or private key
- key_filename – Optional path to private keyfile
-
-
class
dulwich.client.
SubprocessWrapper
(proc)¶ Bases:
object
A socket-like object that talks to a subprocess via pipes.
-
can_read
()¶
-
close
()¶
-
stderr
¶
-
-
class
dulwich.client.
TCPGitClient
(host, port=None, **kwargs)¶ Bases:
dulwich.client.TraditionalGitClient
A Git Client that works over TCP directly (i.e. git://).
-
classmethod
from_parsedurl
(parsedurl, **kwargs)¶ Create an instance of this client from a urlparse.parsed object.
Parameters: parsedurl – Result of urlparse.urlparse() Returns: A GitClient object
-
get_url
(path)¶ Retrieves full url to given path.
Parameters: path – Repository path (as string) Returns: Url to path (as string)
-
classmethod
-
class
dulwich.client.
TraditionalGitClient
(path_encoding='utf-8', **kwargs)¶ Bases:
dulwich.client.GitClient
Traditional Git client.
-
DEFAULT_ENCODING
= 'utf-8'¶
-
archive
(path, committish, write_data, progress=None, write_error=None, format=None, subdirs=None, prefix=None)¶
-
fetch_pack
(path, determine_wants, graph_walker, pack_data, progress=None, depth=None)¶ Retrieve a pack from a git smart server.
Parameters: - path – Remote path to fetch from
- determine_wants – Function determine what refs to fetch. Receives dictionary of name->sha, should return list of shas to fetch.
- graph_walker – Object with next() and ack().
- pack_data – Callback called for each bit of data in the pack
- progress – Callback for progress reports (strings)
- depth – Shallow fetch depth
Returns: FetchPackResult object
-
get_refs
(path)¶ Retrieve the current refs from a git smart server.
-
send_pack
(path, update_refs, generate_pack_data, progress=None)¶ Upload a pack to a remote repository.
Parameters: - path – Repository path (as bytestring)
- update_refs – Function to determine changes to remote refs. Receive dict with existing remote refs, returns dict with changed refs (name -> sha, where sha=ZERO_SHA for deletions)
- generate_pack_data – Function that can return a tuple with number of objects and pack data to upload.
- progress – Optional callback called with progress updates
Raises: - SendPackError – if server rejects the pack data
- UpdateRefsError – if the server supports report-status and rejects ref updates
Returns: new_refs dictionary containing the changes that were made {refname: new_ref}, including deleted refs.
-
-
dulwich.client.
check_wants
(wants, refs)¶ Check that a set of wants is valid.
Parameters: - wants – Set of object SHAs to fetch
- refs – Refs dictionary to check against
-
dulwich.client.
default_local_git_client_cls
¶ alias of
dulwich.client.LocalGitClient
-
dulwich.client.
default_urllib3_manager
(config, **override_kwargs)¶ Return urllib3 connection pool manager.
Honour detected proxy configurations.
Parameters: - config – dulwich.config.ConfigDict instance with Git configuration.
- kwargs – Additional arguments for urllib3.ProxyManager
Returns: urllib3.ProxyManager instance for proxy configurations, urllib3.PoolManager otherwise.
-
dulwich.client.
default_user_agent_string
()¶
-
dulwich.client.
find_git_command
()¶ Find command to run for system Git (usually C Git).
-
dulwich.client.
get_ssh_vendor
¶ alias of
dulwich.client.SubprocessSSHVendor
-
dulwich.client.
get_transport_and_path
(location, **kwargs)¶ Obtain a git client from a URL.
Parameters: - location – URL or path (a string)
- config – Optional config object
- thin_packs – Whether or not thin packs should be retrieved
- report_activity – Optional callback for reporting transport activity.
Returns: Tuple with client instance and relative path.
-
dulwich.client.
get_transport_and_path_from_url
(url, config=None, **kwargs)¶ Obtain a git client from a URL.
Parameters: - url – URL to open (a unicode string)
- config – Optional config object
- thin_packs – Whether or not thin packs should be retrieved
- report_activity – Optional callback for reporting transport activity.
Returns: Tuple with client instance and relative path.
-
dulwich.client.
parse_rsync_url
(location)¶ Parse a rsync-style URL.
-
dulwich.client.
read_pkt_refs
(proto)¶
-
dulwich.client.
remote_error_from_stderr
(stderr)¶ Return an appropriate exception based on stderr output.