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
blobobject
-
class
gitrevise.odb.Commit¶ In memory representation of a git
commitobjectSignatureof this commit’s author
-
gpgsig¶ GPG signature of this commit
-
is_root¶ Whether this commit has no parents
-
message¶ Body of this commit’s message
-
parent() → gitrevise.odb.Commit¶ Helper method to get the single parent of a commit. Raises
ValueErrorif the incorrect number of parents are present.
-
parent_tree() → gitrevise.odb.Tree¶ treeobject corresponding to the first parent of this commit, or the null tree if this is a root commit
-
parents() → Sequence[gitrevise.odb.Commit]¶ List of parent commits
-
rebase(parent: Optional[gitrevise.odb.Commit]) → gitrevise.odb.Commit¶ Create a new commit with the same changes, except with
parentas its parent. IfparentisNone, this becomes a root commit.
-
summary() → str¶ The summary line of the commit message. Returns the summary as a single line, even if it spans multiple lines.
-
tree() → gitrevise.odb.Tree¶ treeobject corresponding to this commit
-
update(tree: Optional[gitrevise.odb.Tree] = None, parents: Optional[Sequence[gitrevise.odb.Commit]] = None, message: Optional[bytes] = None, author: Optional[gitrevise.odb.Signature] = None, recommit: bool = False) → 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
treeentry-
persist() → None¶ GitObj.persist()the git object referenced by this entry
-
repo¶ Repositorythis entry originates from
-
symlink() → bytes¶ Get the data for this entry as a symlink
-
-
exception
gitrevise.odb.GPGSignError(stderr: str)¶ Exception raised when we fail to sign a commit
-
class
gitrevise.odb.GitObj¶ In-memory representation of a git object. Instances of this object should be one of
Commit,TreeorBlob-
body¶ Raw body of object in bytes
-
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¶ Repositoryobject 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
Commitfor this index’s state. IfparentisNone, use the currentHEAD
-
git(*cmd, cwd: Optional[pathlib.Path] = None, stdin: Optional[bytes] = None, trim_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¶
-
-
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
-
GITLINK= b'160000'¶ submodule entry
-
REGULAR= b'100644'¶ regular entry
-
SYMLINK= b'120000'¶ symlink entry
-
-
class
gitrevise.odb.Oid¶ Git object identifier
-
classmethod
for_object(tag: str, body: bytes) → gitrevise.odb.Oid¶ Hash an object with the given type tag and body to determine its Oid
-
classmethod
fromhex(instr: str) → gitrevise.odb.Oid¶ Parse an
Oidfrom a hexadecimal string
-
classmethod
null() → gitrevise.odb.Oid¶ An
Oidconsisting of entirely 0s
-
short() → str¶ A shortened version of the Oid’s hexadecimal form
-
classmethod
-
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() → None¶ 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) → None¶ Update this refreence to point to a new object. An entry with the reason
reasonwill be added to the reflog.
-
-
class
gitrevise.odb.Repository(cwd: Optional[pathlib.Path] = None)¶ Main entry point for a git repository
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¶
-
get_blob_ref(ref: str) → gitrevise.odb.Reference[gitrevise.odb.Blob][gitrevise.odb.Blob]¶
-
get_commit(ref: Union[gitrevise.odb.Oid, str]) → gitrevise.odb.Commit¶
-
get_commit_ref(ref: str) → gitrevise.odb.Reference[gitrevise.odb.Commit][gitrevise.odb.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][gitrevise.odb.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¶
-
get_tree_ref(ref: str) → gitrevise.odb.Reference[gitrevise.odb.Tree][gitrevise.odb.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
-
gpg¶ path to GnuPG binary
-
index¶ current index state
-
new_commit(tree: gitrevise.odb.Tree, parents: Sequence[gitrevise.odb.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, gitrevise.odb.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.
-
sign_buffer(buffer: bytes) → bytes¶ Return the text of the signed commit object.
-
sign_commits¶ sign commits with gpg
-
workdir¶ working directory for this repository
-
class
gitrevise.odb.Signature¶ Git user signature
-
email¶ user email
-
name¶ user name
-
offset¶ timezone offset from UTC
-
signing_key¶ user name <email>
-
timestamp¶ unix timestamp
-
-
class
gitrevise.odb.Tree¶ In memory representation of a git
treeobject-
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.
-