odb – Git object database interaction

Helper classes for reading cached objects from Git’s Object Database.

class gitrevise.odb.Blob

In memory representation of a git blob object

class gitrevise.odb.Commit

In memory representation of a git commit object

author

Signature of this commit’s author

committer

Signature of this commit’s committer

message

Body of this commit’s message

parent() → gitrevise.odb.Commit

Helper method to get the single parent of a commit. Raises ValueError if the incorrect number of parents are present.

parent_oids

List of Oid for this commit’s parents

parents() → Sequence[gitrevise.odb.Commit]

List of parent commits

rebase(parent: gitrevise.odb.Commit) → gitrevise.odb.Commit

Create a new commit with the same changes, except with parent as it’s parent.

summary() → str

The summary line (first line) of the commit message

tree() → gitrevise.odb.Tree

tree object corresponding to this commit

tree_oid

Oid of this commit’s tree object

update(tree: Optional[Tree] = None, parents: Optional[Sequence[Commit]] = None, message: Optional[bytes] = None, author: Optional[gitrevise.odb.Signature] = None) → gitrevise.odb.Commit

Create a new commit with specific properties updated or replaced

class gitrevise.odb.Entry(repo: gitrevise.odb.Repository, mode: gitrevise.odb.Mode, oid: gitrevise.odb.Oid)

In memory representation of a single tree entry

blob() → gitrevise.odb.Blob

Get the data for this entry as a Blob

mode

Mode of the entry

oid

Oid of this entry’s object

persist() → None

GitObj.persist() the git object referenced by this entry

repo

Repository this entry originates from

Get the data for this entry as a symlink

tree() → gitrevise.odb.Tree

Get the data for this entry as a Tree

class gitrevise.odb.GitObj

In-memory representation of a git object. Instances of this object should be one of Commit, Tree or Blob

body

Raw body of object in bytes

oid

Oid of this git object

persist() → gitrevise.odb.Oid

If this object has not been persisted to disk yet, persist it

persisted

If True, the object has been persisted to disk

repo

Repository object is associated with

class gitrevise.odb.Index(repo: gitrevise.odb.Repository, index_file: Optional[pathlib.Path] = None)

Handle on an index file

commit(message: bytes = b'<git index>', parent: Optional[gitrevise.odb.Commit] = None) → gitrevise.odb.Commit

Get a Commit for this index’s state. If parent is None, use the current HEAD

git(*cmd, cwd: Optional[pathlib.Path] = None, stdin: Optional[bytes] = None, newline: bool = True, env: Optional[Mapping[str, str]] = None, nocapture: bool = False) → bytes

Invoke git with the given index as active

index_file = None

Index file being referenced

repo = None
tree() → gitrevise.odb.Tree

Get a Tree object for this index’s state

exception gitrevise.odb.MissingObject(ref: str)

Exception raised when a commit cannot be found in the ODB

class gitrevise.odb.Mode

Mode for an entry in a tree

DIR = b'40000'

directory entry

EXEC = b'100755'

executable entry

submodule entry

REGULAR = b'100644'

regular entry

symlink entry

class gitrevise.odb.Oid

Git object identifier

classmethod for_object(tag: str, body: bytes)

Hash an object with the given type tag and body to determine its Oid

classmethod fromhex(instr: str) → gitrevise.odb.Oid

Parse an Oid from a hexadecimal string

classmethod null() → gitrevise.odb.Oid

An Oid consisting of entirely 0s

short() → str

A shortened version of the Oid’s hexadecimal form

class gitrevise.odb.Reference(obj_type: Type[GitObjT], repo: gitrevise.odb.Repository, name: str)

A git reference

name = None

Resolved reference name, e.g. ‘refs/tags/1.0.0’ or ‘refs/heads/master’

refresh()

Re-read the target of this reference from disk

repo = None

Repository reference is attached to

shortname = None

Short unresolved reference name, e.g. ‘HEAD’ or ‘master’

target = None

Referenced git object

update(new: GitObjT, reason: str)

Update this refreence to point to a new object. An entry with the reason reason will be added to the reflog.

class gitrevise.odb.Repository(cwd: Optional[pathlib.Path] = None)

Main entry point for a git repository

default_author

author used by default for new commits

default_committer

committer used by default for new commits

get_blob(ref: Union[gitrevise.odb.Oid, str]) → gitrevise.odb.Blob

Like get_obj(), but returns a Blob

get_blob_ref(ref: str) → gitrevise.odb.Reference[gitrevise.odb.Blob]

Get a Reference to a Blob

get_commit(ref: Union[gitrevise.odb.Oid, str]) → gitrevise.odb.Commit

Like get_obj(), but returns a Commit

get_commit_ref(ref: str) → gitrevise.odb.Reference[gitrevise.odb.Commit]

Get a Reference to a Commit

get_obj(ref: Union[gitrevise.odb.Oid, str]) → gitrevise.odb.GitObj

Get the identified git object from this repository. If given an Oid, the cache will be checked before asking git.

get_obj_ref(ref: str) → gitrevise.odb.Reference[gitrevise.odb.GitObj]

Get a Reference to a GitObj

get_tempdir() → pathlib.Path

Return a temporary directory to use for modifications to this repository

get_tree(ref: Union[gitrevise.odb.Oid, str]) → gitrevise.odb.Tree

Like get_obj(), but returns a Tree

get_tree_ref(ref: str) → gitrevise.odb.Reference[gitrevise.odb.Tree]

Get a Reference to a Tree

git_path(path: Union[str, pathlib.Path]) → pathlib.Path

Get the path to a file in the .git directory, respecting the environment

gitdir

.git directory for this repository

index

current index state

new_commit(tree: gitrevise.odb.Tree, parents: Sequence[Commit], message: bytes, author: Optional[gitrevise.odb.Signature] = None, committer: Optional[gitrevise.odb.Signature] = None) → gitrevise.odb.Commit

Directly create an in-memory commit object, without persisting it. If a commit object with these properties already exists, it will be returned instead.

new_tree(entries: Mapping[bytes, Entry]) → gitrevise.odb.Tree

Directly create an in-memory tree object, without persisting it. If a tree object with these entries already exists, it will be returned instead.

workdir

working directory for this repository

class gitrevise.odb.Signature

Git user signature

email

user email

name

user name

offset

timezone offset from UTC

timestamp

unix timestamp

class gitrevise.odb.Tree

In memory representation of a git tree object

entries

mapping from entry names to entry objects in this tree

to_index(path: pathlib.Path, skip_worktree: bool = False) → gitrevise.odb.Index

Read tree into a temporary index. If skip_workdir is True, every entry in the index will have its “Skip Workdir” bit set.