diff options
-rw-r--r-- | LibGit2Sharp/Core/NativeMethods.cs | 5 | ||||
-rw-r--r-- | LibGit2Sharp/Tree.cs | 10 | ||||
-rwxr-xr-x | LibGit2Sharp/TreeEntry.cs | 26 |
3 files changed, 35 insertions, 6 deletions
diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs index 10b2594a..b48d37a3 100644 --- a/LibGit2Sharp/Core/NativeMethods.cs +++ b/LibGit2Sharp/Core/NativeMethods.cs @@ -236,12 +236,15 @@ namespace LibGit2Sharp.Core public static extern IntPtr git_tree_entry_byname(IntPtr tree, string filename); [DllImport(libgit2)] - public static extern IntPtr git_tree_entry_id(IntPtr tree); + public static extern IntPtr git_tree_entry_id(IntPtr entry); [DllImport(libgit2)] public static extern IntPtr git_tree_entry_name(IntPtr entry); [DllImport(libgit2)] + public static extern GitObjectType git_tree_entry_type(IntPtr entry); + + [DllImport(libgit2)] public static extern uint git_tree_entrycount(IntPtr tree); } }
\ No newline at end of file diff --git a/LibGit2Sharp/Tree.cs b/LibGit2Sharp/Tree.cs index 0981db1a..bcb47346 100644 --- a/LibGit2Sharp/Tree.cs +++ b/LibGit2Sharp/Tree.cs @@ -33,7 +33,10 @@ namespace LibGit2Sharp {
get
{
- return this.Select(e => e.Target).OfType<Tree>();
+ return this
+ .Where(e => e.Type == GitObjectType.Tree)
+ .Select(e => e.Target)
+ .Cast<Tree>();
}
}
@@ -41,7 +44,10 @@ namespace LibGit2Sharp {
get
{
- return this.Select(e => e.Target).OfType<Blob>();
+ return this
+ .Where(e => e.Type == GitObjectType.Blob)
+ .Select(e => e.Target)
+ .Cast<Blob>();
}
}
diff --git a/LibGit2Sharp/TreeEntry.cs b/LibGit2Sharp/TreeEntry.cs index 20eea0d6..aa057a96 100755 --- a/LibGit2Sharp/TreeEntry.cs +++ b/LibGit2Sharp/TreeEntry.cs @@ -4,6 +4,9 @@ using LibGit2Sharp.Core; namespace LibGit2Sharp
{
+ /// <summary>
+ /// Representation of an entry in a <see cref="Tree"/>.
+ /// </summary>
public class TreeEntry : IEquatable<TreeEntry>
{
private readonly ObjectId parentTreeId;
@@ -14,29 +17,46 @@ namespace LibGit2Sharp private static readonly LambdaEqualityHelper<TreeEntry> equalityHelper =
new LambdaEqualityHelper<TreeEntry>(new Func<TreeEntry, object>[] { x => x.Name, x => x.parentTreeId });
- public TreeEntry(IntPtr obj, ObjectId parentTreeId, Repository repo)
+ internal TreeEntry(IntPtr obj, ObjectId parentTreeId, Repository repo)
{
this.parentTreeId = parentTreeId;
this.repo = repo;
IntPtr gitTreeEntryId = NativeMethods.git_tree_entry_id(obj);
targetOid = new ObjectId((GitOid)Marshal.PtrToStructure(gitTreeEntryId, typeof(GitOid)));
+ Type = NativeMethods.git_tree_entry_type(obj);
Attributes = NativeMethods.git_tree_entry_attributes(obj);
Name = NativeMethods.git_tree_entry_name(obj).MarshallAsString();
}
+ /// <summary>
+ /// Gets the UNIX file attributes.
+ /// </summary>
public int Attributes { get; private set; }
-
+
+ /// <summary>
+ /// Gets the filename.
+ /// <para>The filename is expressed in a relative form. Path segments are separated with a forward slash."/></para>
+ /// </summary>
public string Name { get; private set; }
+ /// <summary>
+ /// Gets the <see cref="GitObject"/> being pointed at.
+ /// </summary>
public GitObject Target { get { return target ?? (target = RetreiveTreeEntryTarget()); } }
+ /// <summary>
+ /// Gets the <see cref="GitObjectType"/> of the <see cref="Target"/> being pointed at.
+ /// </summary>
+ public GitObjectType Type { get; private set; }
+
private GitObject RetreiveTreeEntryTarget()
{
GitObject treeEntryTarget = repo.Lookup(targetOid);
+ //TODO: Warning submodules will appear as targets of type Commit
Ensure.ArgumentConformsTo(treeEntryTarget.GetType(), t => typeof(Blob).IsAssignableFrom(t) || typeof(Tree).IsAssignableFrom(t), "treeEntryTarget");
-
+
return treeEntryTarget;
}
|