Xgit v0.1.0 Xgit.Repository behaviour

Represents an abstract git repository.

Looking for Typical Git Commands?

The operations to inspect or mutate a git repository are not located in this module. (See Design Goals, below, and the README.md file in the lib/xgit folder for an explanation.)

You'll find these operations in the modules named Xgit.Api.* (none yet as of this writing) and Xgit.Plumbing.*

Design Goals

Xgit intends to allow repositories to be stored in multiple different mechanisms. While it includes built-in support for local on-disk repositories (see Xgit.Repository.OnDisk), you could envision repositories stored entirely in memory, or on a remote file system or database.

Implementing a Storage Architecture

To define a new mechanism for storing a git repo, start by creating a new module that uses this module and implements the required callbacks. Consider the information stored in a typical .git directory in a local repository. You will be building an alternative to that storage mechanism.

Link to this section Summary

Types

t()

The process ID for a Repository process.

Functions

Returns a specification to start this module under a supervisor.

Writes a loose object to the repository.

Starts a Repository process linked to the current process.

Returns true if the argument is a PID representing a valid Repository process.

Callbacks

Writes a loose object to the repository.

Link to this section Types

The process ID for a Repository process.

Link to this section Functions

Link to this function

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

put_loose_object(repository, object)
put_loose_object(repository :: t(), object :: Xgit.Core.Object.t()) ::
  :ok | {:error, reason :: String.t()}

Writes a loose object to the repository.

Return Value

:ok if written successfully.

{:error, "reason"} if unable to write the object.

Link to this function

start_link(module, init_arg, options)
start_link(module :: module(), init_arg :: term(), GenServer.options()) ::
  GenServer.on_start()

Starts a Repository process linked to the current process.

IMPORTANT: You should not invoke this function directly unless you are implementing a new storage implementation module that implements this behaviour.

Parameters

module is the name of a module that implements the callbacks defined in this module.

init_arg is passed to the init/1 function of module.

options are passed to GenServer.start_link/3.

Return Value

See GenServer.start_link/3.

Link to this function

valid?(repository)
valid?(repository :: term()) :: boolean()

Returns true if the argument is a PID representing a valid Repository process.

Link to this section Callbacks

Link to this callback

handle_put_loose_object(state, object)
handle_put_loose_object(state :: any(), object :: Xgit.Core.Object.t()) ::
  {:ok, state :: any()} | {:error, reason :: String.t(), state :: any()}

Writes a loose object to the repository.

Called when put_loose_object/2 is called.

Return Value

Should return :ok if written successfully.

Should return {:error, "reason"} if unable to write the object.