class Agate::Object

Overview

Base class for git objects (commits, trees, blobs, tags).

Included Modules

Defined in:

agate/object.cr
agate/revparse.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.from_obj(obj : C::GitObject) : Object #

Wraps a raw C object pointer. Subclasses override this to return the appropriate Crystal type. :nodoc:


[View source]
def self.lookup(repo : Repository, oid : OID, type : Type = Type::Any) : Object #

Looks up an object by OID in the given repository. Raises on failure.


[View source]
def self.rev_parse(repo : Repository, spec : String) : Object #

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

[View source]

Class Method Detail

def self.lookup?(repo : Repository, oid : OID, type : Type = Type::Any) : Object | Nil #

Looks up an object by OID, returning nil if not found.


[View source]
def self.rev_parse?(repo : Repository, spec : String) : Object | Nil #

Parses a revision spec, returning nil if it cannot be resolved.


[View source]
def self.rev_parse_oid(repo : Repository, spec : String) : OID #

Parses a revision spec and returns just the OID. Raises on failure.


[View source]
def self.rev_parse_oid?(repo : Repository, spec : String) : OID | Nil #

Parses a revision spec and returns just the OID, or nil.


[View source]
def self.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}. 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

[View source]

Instance Method Detail

def <=>(other : Object) : Int32 #

Three-way comparison by OID.


[View source]
def ==(other : Object) : Bool #

Compares two objects by OID.


[View source]
def oid : OID #

Returns the OID of this object.


[View source]
def read_raw(repo : Repository) : OdbObject #

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

[View source]
def type : Type #

Returns the type of this object.


[View source]