class
Agate::Object
- Agate::Object
- Reference
- Object
Overview
Base class for git objects (commits, trees, blobs, tags).
Included Modules
- Comparable(Agate::Object)
Defined in:
agate/object.cragate/revparse.cr
Constructors
-
.from_obj(obj : C::GitObject) : Object
Wraps a raw C object pointer.
-
.lookup(repo : Repository, oid : OID, type : Type = Type::Any) : Object
Looks up an object by OID in the given repository.
-
.rev_parse(repo : Repository, spec : String) : Object
Parses a revision spec (e.g., "HEAD", "HEAD~2", a SHA) and returns the matching object.
Class Method Summary
-
.lookup?(repo : Repository, oid : OID, type : Type = Type::Any) : Object | Nil
Looks up an object by OID, returning nil if not found.
-
.rev_parse?(repo : Repository, spec : String) : Object | Nil
Parses a revision spec, returning nil if it cannot be resolved.
-
.rev_parse_oid(repo : Repository, spec : String) : OID
Parses a revision spec and returns just the OID.
-
.rev_parse_oid?(repo : Repository, spec : String) : OID | Nil
Parses a revision spec and returns just the OID, or nil.
-
.rev_parse_range(repo : Repository, spec : String) : Tuple(Object, Object | Nil, RevparseMode)
Parses a range revision spec (e.g., "HEAD~3..HEAD", "v1.0...v2.0") and returns
{from, to, mode}.
Instance Method Summary
-
#<=>(other : Object) : Int32
Three-way comparison by OID.
-
#==(other : Object) : Bool
Compares two objects by OID.
-
#oid : OID
Returns the OID of this object.
-
#read_raw(repo : Repository) : OdbObject
Reads the raw ODB data for this object.
-
#type : Type
Returns the type of this object.
Constructor Detail
Wraps a raw C object pointer. Subclasses override this to return the appropriate Crystal type. :nodoc:
Looks up an object by OID in the given repository. Raises on failure.
Parses a revision spec (e.g., "HEAD", "HEAD~2", a SHA) and returns the matching object. Raises on failure.
obj = Object.rev_parse(repo, "HEAD~2")
obj.type # => Object::Type::Commit
Class Method Detail
Looks up an object by OID, returning nil if not found.
Parses a revision spec, returning nil if it cannot be resolved.
Parses a revision spec and returns just the OID. Raises on failure.
Parses a revision spec and returns just the OID, or nil.
Parses a range revision spec (e.g., "HEAD~3..HEAD", "v1.0...v2.0")
and returns {from, to, mode}. Both objects must be freed by the
caller (they are wrapped in Object instances with finalizers).
from, to, mode = Object.rev_parse_range(repo, "HEAD~3..HEAD")
mode.range? # => true
Instance Method Detail
Reads the raw ODB data for this object.
Convenience wrapper for repo.odb.read(oid).
obj = Object.lookup(repo, oid)
raw = obj.read_raw(repo)
raw.type # => Object::Type::Commit
raw.data # => Bytes