I noticed that I can get the contents of a particular Leaf (blob) object from a specific branch by iterating over a Tree's children like so:
_repository = new Repository(git_url);
IEnumerable<AbstractObject> currentBranchItems = _repository.CurrentBranch.CurrentCommit.Tree.Children;
foreach (var currentBranchItem in currentBranchItems)
{
var currentBranchLeaf = currentBranchItem as Leaf;
_lastLeafHash = currentBranchLeaf.Hash;
Console.WriteLine("Name: " + currentBranchLeaf.Name + " Hash: " + currentBranchLeaf.Hash);
}
However, this seems pretty inefficient if I have the hash of the leaf that I would like to retrieve. Is there a way that I can access a Leaf directly from the repository if I have the hash? The following does not work:
private static void GetLeafByHash(string hash)
{
var leafAbs = _repository.Get<AbstractObject>(hash);
var leaf = leafAbs as Leaf;
Console.WriteLine("Found Leaf Named: " + leaf.Name);
Console.WriteLine("The data is this big: " + leaf.RawData.Length);
Console.Read();
}
The Get method always returns NULL. So is there a way to accomplish the direct retrieval of a Leaf by hash? The documentation states the following about the Get method:
Access a git object by name, id or path. Use the type parameter to tell what kind of object you like to get. Supported types are Branches, Commits or Tags may be accessed by name or reference expression. Currently supported are combinations of these: Not supported is Tree or Leaf (Blob) objects can be addressed by long hash or by their relative repository path
It's not clear.. does this mean that Tree or Leaf objects can or cannot be accessed via a hash?
Thanks a lot!