diff options
author | nulltoken <emeric.fermas@gmail.com> | 2011-04-20 17:10:40 +0400 |
---|---|---|
committer | nulltoken <emeric.fermas@gmail.com> | 2011-04-20 22:28:52 +0400 |
commit | 051febd63cc836d63d626ec5bf2d7310de8b9430 (patch) | |
tree | 2b37bbc1ae0786d0c7eed25f6db9cf3a0bfcfe9b /LibGit2Sharp/TreeEntry.cs | |
parent | 38b102f83ac8dd697d50523700d3a3ecee03d437 (diff) |
Straighten Tree and TreeEntry API
Diffstat (limited to 'LibGit2Sharp/TreeEntry.cs')
-rwxr-xr-x | LibGit2Sharp/TreeEntry.cs | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/LibGit2Sharp/TreeEntry.cs b/LibGit2Sharp/TreeEntry.cs index 09b36441..f18a661c 100755 --- a/LibGit2Sharp/TreeEntry.cs +++ b/LibGit2Sharp/TreeEntry.cs @@ -7,27 +7,30 @@ namespace LibGit2Sharp public class TreeEntry
{
private readonly Repository repo;
+ private GitObject target;
+ private readonly ObjectId targetOid;
public TreeEntry(IntPtr obj, Repository repo)
{
this.repo = repo;
IntPtr gitTreeEntryId = NativeMethods.git_tree_entry_id(obj);
+ targetOid = new ObjectId((GitOid)Marshal.PtrToStructure(gitTreeEntryId, typeof(GitOid)));
- Target = new ObjectId((GitOid)Marshal.PtrToStructure(gitTreeEntryId, typeof(GitOid)));
Attributes = NativeMethods.git_tree_entry_attributes(obj);
Name = NativeMethods.git_tree_entry_name(obj);
}
- public ObjectId Target { get; private set; }
-
- public Blob Blob { get { return repo.Lookup<Blob>(Target); } }
-
- public Tree Tree { get { return repo.Lookup<Tree>(Target); } }
-
public int Attributes { get; private set; }
public string Name { get; private set; }
- public GitObject Object { get { return repo.Lookup(Target); } }
+ public GitObject Target { get { return target ?? (target = RetreiveTreeEntryTarget()); } }
+
+ private GitObject RetreiveTreeEntryTarget()
+ {
+ GitObject treeEntryTarget = repo.Lookup(targetOid);
+ Ensure.ArgumentConformsTo(treeEntryTarget.GetType(), t => typeof(Blob).IsAssignableFrom(t) || typeof(Tree).IsAssignableFrom(t), "treeEntryTarget");
+ return treeEntryTarget;
+ }
}
}
\ No newline at end of file |