package datakit-github

  1. Overview
  2. Docs

All changes to a branch are made in transactions. When a transaction is committed, it is merged with the current contents of the branch.

Reading

include Datakit_client.READABLE_TREE with type 'a result := 'a result
type t

The type for trees.

read t path is the contents of the object at the path.

stat t path is the metadata of the object at path.

val exists : t -> Datakit_client.Path.t -> bool result

exists t path is true if stat t path isn't None.

val exists_file : t -> Datakit_client.Path.t -> bool result

exists_file t path is similar to exists but for files only.

val exists_dir : t -> Datakit_client.Path.t -> bool result

exists_dir t path is similar to exists but for directories only.

val read_file : t -> Datakit_client.Path.t -> Cstruct.t result

read_file t path resolves path to a file, or returns an error if it isn't a file.

val read_dir : t -> Datakit_client.Path.t -> string list result

read_dir t path resolves path to a directory, or returns an error if it isn't one.

read_link t path resolves path to a symlink, or returns an error if it isn't one.

Writing

val create_dir : t -> Datakit_client.Path.t -> unit result

create_dir t path creates the directory path.

val create_file : t -> Datakit_client.Path.t -> ?executable:bool -> Cstruct.t -> unit result

create_file t path ?executable content creates the file path.

create_symlink t path target creates the symlink path.

val replace_file : t -> Datakit_client.Path.t -> Cstruct.t -> unit result

replace_file t path new_content changes the content of the existing file path.

val create_or_replace_file : t -> Datakit_client.Path.t -> Cstruct.t -> unit result

create_or_replace_file t path content uses either create_file or replace_file as appropriate to set the contents.

val set_executable : t -> Datakit_client.Path.t -> bool -> unit result

set_executable t path flag marks the file at path as executable or not.

val remove : t -> Datakit_client.Path.t -> unit result

remove t path removes path. If path is a directory then the entire subtree is removed.

val truncate : t -> Datakit_client.Path.t -> int64 -> unit result

truncate t path length sets the length of the file at path to length. If length is longer than the current length, the file is padded with zero bytes.

val make_dirs : t -> Datakit_client.Path.t -> unit result

make_dirs t path ensures that path exists and is a directory, creating it and any missing parents as necessary.

Finishing

val commit : t -> message:string -> unit result

commit t ~message creates a new commit with the given log message and the current contents of the transaction and then merges it into the branch from which the transaction was created. The transaction cannot be used after calling this.

val abort : t -> unit result

abort t aborts the transaction without committing it. The transaction cannot be used after calling this.

Merging and history

type merge_inputs = {
  1. ours : Tree.t;
  2. theirs : Tree.t;
  3. base : Tree.t;
}

When performing a merge, these three directories can be used to calculate the final result. ours is the previous contents of the transaction, theirs is the commit being merged and base is a least common ancestor. If there is no common ancestor then base is an empty tree.

merge t commit merges commit into the transaction. It performs any trivial merges it can and returns (merge_inputs, conflicts) to allow you to resolve the remaining ones. You must write to each path in conflicts at least once before you can commit the transaction. You may perform multiple merges in one transaction, but the merge_inputs returned is only valid until the start of the next merge.

val parents : t -> Commit.t list result

parents t is the parents of the transaction (that is, the parents of the commit that would be generated if you committed now.

val set_parents : t -> Commit.t list -> unit result

set_parents t new_parents replaces the current list of parents. Note that this does not perform a merge - it only affects the metadata. Note also that merge automatically updates the parents, so it is not necessary to call it manually in that case.

val conflicts : t -> Datakit_client.Path.t list result

conflicts t returns the current list of paths that had merge conflicts and have not been written to since. It is not possible to commit while this is non-empty.

diff t c returns the paths differences between c and t's head.

val closed : t -> bool

closed t is true if t is closed and thus it is not valid to read/write on it anymore.

OCaml

Innovation. Community. Security.