dulwich.server module

Git smart network protocol server implementation.

For more detailed implementation on the network protocol, see the Documentation/technical directory in the cgit distribution, and in particular:

  • Documentation/technical/protocol-capabilities.txt

  • Documentation/technical/pack-protocol.txt

Currently supported capabilities:

  • include-tag

  • thin-pack

  • multi_ack_detailed

  • multi_ack

  • side-band-64k

  • ofs-delta

  • no-progress

  • report-status

  • delete-refs

  • shallow

  • symref

class dulwich.server.Backend

Bases: object

A backend for the Git smart server implementation.

open_repository(path)

Open the repository at a path.

Parameters

path – Path to the repository

Raises

NotGitRepository – no git repository was found at path

Returns: Instance of BackendRepo

class dulwich.server.BackendRepo

Bases: object

Repository abstraction used by the Git server.

The methods required here are a subset of those provided by dulwich.repo.Repo.

fetch_objects(determine_wants, graph_walker, progress, get_tagged=None)

Yield the objects required for a list of commits.

Parameters
  • progress – is a callback to send progress messages to the client

  • get_tagged – Function that returns a dict of pointed-to sha -> tag sha for including tags.

get_peeled(name: bytes)Optional[bytes]

Return the cached peeled value of a ref, if available.

Parameters

name – Name of the ref to peel

Returns: The peeled value of the ref. If the ref is known not point to

a tag, this will be the SHA the ref refers to. If no cached information about a tag is available, this method may return None, but it should attempt to peel the tag if possible.

get_refs()Dict[bytes, bytes]

Get all the refs in the repository

Returns: dict of name -> sha

object_store = None
refs = None
class dulwich.server.DictBackend(repos)

Bases: dulwich.server.Backend

Trivial backend that looks up Git repositories in a dictionary.

open_repository(path: str)dulwich.repo.BaseRepo

Open the repository at a path.

Parameters

path – Path to the repository

Raises

NotGitRepository – no git repository was found at path

Returns: Instance of BackendRepo

class dulwich.server.FileSystemBackend(root='/')

Bases: dulwich.server.Backend

Simple backend looking up Git repositories in the local file system.

open_repository(path)

Open the repository at a path.

Parameters

path – Path to the repository

Raises

NotGitRepository – no git repository was found at path

Returns: Instance of BackendRepo

class dulwich.server.Handler(backend, proto, stateless_rpc=None)

Bases: object

Smart protocol command handler base class.

handle()
class dulwich.server.MultiAckDetailedGraphWalkerImpl(walker)

Bases: object

Graph walker implementation speaking the multi-ack-detailed protocol.

ack(have_ref)
handle_done(done_required, done_received)
next()
class dulwich.server.MultiAckGraphWalkerImpl(walker)

Bases: object

Graph walker implementation that speaks the multi-ack protocol.

ack(have_ref)
handle_done(done_required, done_received)
next()
class dulwich.server.PackHandler(backend, proto, stateless_rpc=None)

Bases: dulwich.server.Handler

Protocol handler for packs.

classmethod capabilities()Iterable[bytes]
classmethod capability_line(capabilities)
has_capability(cap: bytes)bool
classmethod innocuous_capabilities()Iterable[bytes]
notify_done()None
classmethod required_capabilities()Iterable[bytes]

Return a list of capabilities that we require the client to have.

set_client_capabilities(caps: Iterable[bytes])None
class dulwich.server.ReceivePackHandler(backend, args, proto, stateless_rpc=None, advertise_refs=False)

Bases: dulwich.server.PackHandler

Protocol handler for downloading a pack from the client.

classmethod capabilities()Iterable[bytes]
handle()None
class dulwich.server.SingleAckGraphWalkerImpl(walker)

Bases: object

Graph walker implementation that speaks the single-ack protocol.

ack(have_ref)
handle_done(done_required, done_received)
next()
class dulwich.server.TCPGitRequestHandler(handlers, *args, **kwargs)

Bases: socketserver.StreamRequestHandler

handle()
class dulwich.server.TCPGitServer(backend, listen_addr, port=9418, handlers=None)

Bases: socketserver.TCPServer

Constructor. May be extended, do not override.

allow_reuse_address = True
handle_error(request, client_address)

Handle an error gracefully. May be overridden.

The default is to print a traceback and continue.

serve(poll_interval=0.5)

Handle one request at a time until shutdown.

Polls for shutdown every poll_interval seconds. Ignores self.timeout. If you need to do periodic tasks, do them in another thread.

verify_request(request, client_address)

Verify the request. May be overridden.

Return True if we should proceed with this request.

class dulwich.server.UploadArchiveHandler(backend, args, proto, stateless_rpc=None)

Bases: dulwich.server.Handler

handle()
class dulwich.server.UploadPackHandler(backend, args, proto, stateless_rpc=None, advertise_refs=False)

Bases: dulwich.server.PackHandler

Protocol handler for uploading a pack to the client.

classmethod capabilities()
get_tagged(refs=None, repo=None)

Get a dict of peeled values of tags to their original tag shas.

Parameters
  • refs – dict of refname -> sha of possible tags; defaults to all of the backend’s refs.

  • repo – optional Repo instance for getting peeled refs; defaults to the backend’s repo, if available

Returns: dict of peeled_sha -> tag_sha, where tag_sha is the sha of a

tag whose peeled value is peeled_sha.

handle()
progress(message)
classmethod required_capabilities()

Return a list of capabilities that we require the client to have.

dulwich.server.generate_info_refs(repo)

Generate an info refs file.

dulwich.server.generate_objects_info_packs(repo)

Generate an index for for packs.

dulwich.server.main(argv=['/usr/bin/sphinx-build', '-b', 'html', '-d', 'build/doctrees', '.', 'build/html'])

Entry point for starting a TCP git server.

dulwich.server.serve_command(handler_cls, argv=['/usr/bin/sphinx-build', '-b', 'html', '-d', 'build/doctrees', '.', 'build/html'], backend=None, inf=<_io.TextIOWrapper name='<stdin>' mode='r' encoding='utf-8'>, outf=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)

Serve a single command.

This is mostly useful for the implementation of commands used by e.g. git+ssh.

Parameters
  • handler_clsHandler class to use for the request

  • argv – execv-style command-line arguments. Defaults to sys.argv.

  • backendBackend to use

  • inf – File-like object to read from, defaults to standard input.

  • outf – File-like object to write to, defaults to standard output.

Returns: Exit code for use with sys.exit. 0 on success, 1 on failure.

dulwich.server.update_server_info(repo)

Generate server info for dumb file access.

This generates info/refs and objects/info/packs, similar to “git update-server-info”.