class Agate::Tree

Overview

Represents a git tree object (directory listing).

Included Modules

Defined in:

agate/tree.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.lookup(repo : Repository, oid : OID) : Tree #

Looks up a tree by OID. Raises on failure.


[View source]

Class Method Detail

def self.build(repo : Repository, source : Tree | Nil = nil, & : TreeBuilder -> ) : OID #

Builds a new tree by yielding a TreeBuilder, then writes it and returns the OID.

tree_oid = Tree.build(repo) do |b|
  b.insert("README.md", readme_oid)
  b.insert("src/main.cr", main_oid)
end

[View source]
def self.lookup?(repo : Repository, oid : OID) : Tree | Nil #

Looks up a tree by OID, returning nil if not found.


[View source]

Instance Method Detail

def [](index : Int32) : TreeEntry #

Returns the entry at the given index.


[View source]
def [](name : String) : TreeEntry #

Returns the entry with the given name. Raises KeyError if not found.


[View source]
def []?(name : String) : TreeEntry | Nil #

Returns the entry with the given name, or nil.


[View source]
def count : Int32 #

Returns the number of entries in this tree.


[View source]
def diff(repo : Repository, other : Tree | Nil = nil) : Diff #

Diffs this tree against another tree.


[View source]
def each(& : TreeEntry -> ) : Nil #

Iterates over all entries in this tree.


[View source]
def each_blob(& : TreeEntry -> ) : Nil #

Iterates over blob entries only.


[View source]
def each_tree(& : TreeEntry -> ) : Nil #

Iterates over tree (subdirectory) entries only.


[View source]
def merge(repo : Repository, our_tree : Tree, their_tree : Tree) : Index #

Three-way merge of this tree with another tree and an ancestor.


[View source]
def oid : OID #

Returns the OID of this tree.


[View source]
def path(path : String) : TreeEntry #

Returns the entry at the given path (can include '/'). The returned entry must be freed, so we read it immediately.


[View source]
def size : Int32 #

Alias for count.


[View source]
def walk(mode : WalkMode = WalkMode::Pre, &block : String, TreeEntry -> ) : Nil #

Recursively walks the tree in the given mode (:pre or :post order). Yields the root path (e.g., "src/") and each entry.


[View source]
def walk_blobs(mode : WalkMode = WalkMode::Post, &block : String, TreeEntry -> ) : Nil #

Recursively walks blobs only.


[View source]
def walk_trees(mode : WalkMode = WalkMode::Pre, &block : String, TreeEntry -> ) : Nil #

Recursively walks subtrees only.


[View source]