55using System . Linq ;
66using LibGit2Sharp . Core ;
77using LibGit2Sharp . Core . Handles ;
8+ using System . Text ;
9+ using System ;
810
911namespace LibGit2Sharp
1012{
@@ -14,7 +16,7 @@ namespace LibGit2Sharp
1416 [ DebuggerDisplay ( "{DebuggerDisplay,nq}" ) ]
1517 public class Tree : GitObject , IEnumerable < TreeEntry >
1618 {
17- private readonly FilePath path ;
19+ private readonly string path ;
1820
1921 private readonly ILazy < int > lazyCount ;
2022
@@ -24,7 +26,7 @@ public class Tree : GitObject, IEnumerable<TreeEntry>
2426 protected Tree ( )
2527 { }
2628
27- internal Tree ( Repository repo , ObjectId id , FilePath path )
29+ internal Tree ( Repository repo , ObjectId id , string path )
2830 : base ( repo , id )
2931 {
3032 this . path = path ?? "" ;
@@ -47,9 +49,9 @@ public virtual TreeEntry this[string relativePath]
4749 get { return RetrieveFromPath ( relativePath ) ; }
4850 }
4951
50- private unsafe TreeEntry RetrieveFromPath ( FilePath relativePath )
52+ private unsafe TreeEntry RetrieveFromPath ( string relativePath )
5153 {
52- if ( relativePath . IsNullOrEmpty ( ) )
54+ if ( string . IsNullOrEmpty ( relativePath ) )
5355 {
5456 return null ;
5557 }
@@ -61,28 +63,42 @@ private unsafe TreeEntry RetrieveFromPath(FilePath relativePath)
6163 return null ;
6264 }
6365
64- string posixPath = relativePath . Posix ;
65- string filename = posixPath . Split ( '/' ) . Last ( ) ;
66- string parentPath = posixPath . Substring ( 0 , posixPath . Length - filename . Length ) ;
67- return new TreeEntry ( treeEntry , Id , repo , path . Combine ( parentPath ) ) ;
66+ string filename = relativePath . Split ( '/' ) . Last ( ) ;
67+ string parentPath = relativePath . Substring ( 0 , relativePath . Length - filename . Length ) ;
68+ return new TreeEntry ( treeEntry , Id , repo , Tree . CombinePath ( path , parentPath ) ) ;
6869 }
6970 }
7071
7172 internal string Path
7273 {
73- get { return path . Native ; }
74+ get { return path ; }
7475 }
7576
7677 #region IEnumerable<TreeEntry> Members
7778
78- unsafe TreeEntry byIndex ( ObjectSafeWrapper obj , uint i , ObjectId parentTreeId , Repository repo , FilePath parentPath )
79+ unsafe TreeEntry byIndex ( ObjectSafeWrapper obj , uint i , ObjectId parentTreeId , Repository repo , string parentPath )
7980 {
8081 using ( var entryHandle = Proxy . git_tree_entry_byindex ( obj . ObjectPtr , i ) )
8182 {
8283 return new TreeEntry ( entryHandle , parentTreeId , repo , parentPath ) ;
8384 }
8485 }
8586
87+ internal static string CombinePath ( string a , string b )
88+ {
89+ var bld = new StringBuilder ( ) ;
90+ bld . Append ( a ) ;
91+ if ( ! String . IsNullOrEmpty ( a ) &&
92+ ! a . EndsWith ( "/" , StringComparison . InvariantCulture ) &&
93+ ! b . StartsWith ( "/" , StringComparison . InvariantCulture ) )
94+ {
95+ bld . Append ( '/' ) ;
96+ }
97+ bld . Append ( b ) ;
98+
99+ return bld . ToString ( ) ;
100+ }
101+
86102 /// <summary>
87103 /// Returns an enumerator that iterates through the collection.
88104 /// </summary>
0 commit comments