@@ -17,7 +17,7 @@ public LibGit2Repo(ITracer tracer, string repoPath)
1717 Native . Init ( ) ;
1818
1919 IntPtr repoHandle ;
20- if ( Native . Repo . Open ( out repoHandle , repoPath ) != Native . SuccessCode )
20+ if ( Native . Repo . Open ( out repoHandle , repoPath ) != Native . ResultCode . Success )
2121 {
2222 string reason = Native . GetLastError ( ) ;
2323 string message = "Couldn't open repo at " + repoPath + ": " + reason ;
@@ -45,7 +45,7 @@ protected LibGit2Repo()
4545 public Native . ObjectTypes ? GetObjectType ( string sha )
4646 {
4747 IntPtr objHandle ;
48- if ( Native . RevParseSingle ( out objHandle , this . RepoHandle , sha ) != Native . SuccessCode )
48+ if ( Native . RevParseSingle ( out objHandle , this . RepoHandle , sha ) != Native . ResultCode . Success )
4949 {
5050 return null ;
5151 }
@@ -63,7 +63,7 @@ protected LibGit2Repo()
6363 public virtual string GetTreeSha ( string commitish )
6464 {
6565 IntPtr objHandle ;
66- if ( Native . RevParseSingle ( out objHandle , this . RepoHandle , commitish ) != Native . SuccessCode )
66+ if ( Native . RevParseSingle ( out objHandle , this . RepoHandle , commitish ) != Native . ResultCode . Success )
6767 {
6868 return null ;
6969 }
@@ -99,7 +99,7 @@ public virtual bool CommitAndRootTreeExists(string commitish, out string treeSha
9999 public virtual bool ObjectExists ( string sha )
100100 {
101101 IntPtr objHandle ;
102- if ( Native . RevParseSingle ( out objHandle , this . RepoHandle , sha ) != Native . SuccessCode )
102+ if ( Native . RevParseSingle ( out objHandle , this . RepoHandle , sha ) != Native . ResultCode . Success )
103103 {
104104 return false ;
105105 }
@@ -111,7 +111,7 @@ public virtual bool ObjectExists(string sha)
111111 public virtual bool TryCopyBlob ( string sha , Action < Stream , long > writeAction )
112112 {
113113 IntPtr objHandle ;
114- if ( Native . RevParseSingle ( out objHandle , this . RepoHandle , sha ) != Native . SuccessCode )
114+ if ( Native . RevParseSingle ( out objHandle , this . RepoHandle , sha ) != Native . ResultCode . Success )
115115 {
116116 return false ;
117117 }
@@ -157,7 +157,7 @@ public virtual string[] GetMissingSubTrees(string treeSha)
157157 {
158158 List < string > missingSubtreesList = new List < string > ( ) ;
159159 IntPtr treeHandle ;
160- if ( Native . RevParseSingle ( out treeHandle , this . RepoHandle , treeSha ) != Native . SuccessCode
160+ if ( Native . RevParseSingle ( out treeHandle , this . RepoHandle , treeSha ) != Native . ResultCode . Success
161161 || treeHandle == IntPtr . Zero )
162162 {
163163 return Array . Empty < string > ( ) ;
@@ -187,6 +187,68 @@ public virtual string[] GetMissingSubTrees(string treeSha)
187187 return missingSubtreesList . ToArray ( ) ;
188188 }
189189
190+ /// <summary>
191+ /// Get a config value from the repo's git config.
192+ /// </summary>
193+ /// <param name="name">Name of the config entry</param>
194+ /// <returns>The config value, or null if not found.</returns>
195+ public virtual string GetConfigString ( string name )
196+ {
197+ IntPtr configHandle ;
198+ if ( Native . Config . GetConfig ( out configHandle , this . RepoHandle ) != Native . ResultCode . Success )
199+ {
200+ throw new LibGit2Exception ( $ "Failed to get config handle: { Native . GetLastError ( ) } ") ;
201+ }
202+ try
203+ {
204+ string value ;
205+ Native . ResultCode resultCode = Native . Config . GetString ( out value , configHandle , name ) ;
206+ if ( resultCode == Native . ResultCode . NotFound )
207+ {
208+ return null ;
209+ }
210+ else if ( resultCode != Native . ResultCode . Success )
211+ {
212+ throw new LibGit2Exception ( $ "Failed to get config value for '{ name } ': { Native . GetLastError ( ) } ") ;
213+ }
214+
215+ return value ;
216+ }
217+ finally
218+ {
219+ Native . Config . Free ( configHandle ) ;
220+ }
221+ }
222+
223+ public virtual bool ? GetConfigBool ( string name )
224+ {
225+ IntPtr configHandle ;
226+ if ( Native . Config . GetConfig ( out configHandle , this . RepoHandle ) != Native . ResultCode . Success )
227+ {
228+ throw new LibGit2Exception ( $ "Failed to get config handle: { Native . GetLastError ( ) } ") ;
229+ }
230+ try
231+ {
232+ bool value ;
233+ Native . ResultCode resultCode = Native . Config . GetBool ( out value , configHandle , name ) ;
234+ if ( resultCode == Native . ResultCode . NotFound )
235+ {
236+ return null ;
237+ }
238+ else if ( resultCode != Native . ResultCode . Success )
239+ {
240+ throw new LibGit2Exception ( $ "Failed to get config value for '{ name } ': { Native . GetLastError ( ) } ") ;
241+ }
242+
243+ return value ;
244+ }
245+ finally
246+ {
247+ Native . Config . Free ( configHandle ) ;
248+ }
249+
250+ }
251+
190252 /// <summary>
191253 /// Determine if the given index of a tree is a subtree and if it is missing.
192254 /// If it is a missing subtree, return the SHA of the subtree.
@@ -242,7 +304,11 @@ protected virtual void Dispose(bool disposing)
242304
243305 public static class Native
244306 {
245- public const uint SuccessCode = 0 ;
307+ public enum ResultCode : int
308+ {
309+ Success = 0 ,
310+ NotFound = - 3 ,
311+ }
246312
247313 public const string Git2NativeLibName = GVFSConstants . LibGit2LibraryName ;
248314
@@ -265,7 +331,7 @@ public static GitOid IntPtrToGitOid(IntPtr oidPtr)
265331 public static extern int Shutdown ( ) ;
266332
267333 [ DllImport ( Git2NativeLibName , EntryPoint = "git_revparse_single" ) ]
268- public static extern uint RevParseSingle ( out IntPtr objectHandle , IntPtr repoHandle , string oid ) ;
334+ public static extern ResultCode RevParseSingle ( out IntPtr objectHandle , IntPtr repoHandle , string oid ) ;
269335
270336 public static string GetLastError ( )
271337 {
@@ -293,12 +359,27 @@ private struct GitError
293359 public static class Repo
294360 {
295361 [ DllImport ( Git2NativeLibName , EntryPoint = "git_repository_open" ) ]
296- public static extern uint Open ( out IntPtr repoHandle , string path ) ;
362+ public static extern ResultCode Open ( out IntPtr repoHandle , string path ) ;
297363
298364 [ DllImport ( Git2NativeLibName , EntryPoint = "git_repository_free" ) ]
299365 public static extern void Free ( IntPtr repoHandle ) ;
300366 }
301367
368+ public static class Config
369+ {
370+ [ DllImport ( Git2NativeLibName , EntryPoint = "git_repository_config" ) ]
371+ public static extern ResultCode GetConfig ( out IntPtr configHandle , IntPtr repoHandle ) ;
372+
373+ [ DllImport ( Git2NativeLibName , EntryPoint = "git_config_get_string" ) ]
374+ public static extern ResultCode GetString ( out string value , IntPtr configHandle , string name ) ;
375+
376+ [ DllImport ( Git2NativeLibName , EntryPoint = "git_config_get_bool" ) ]
377+ public static extern ResultCode GetBool ( out bool value , IntPtr configHandle , string name ) ;
378+
379+ [ DllImport ( Git2NativeLibName , EntryPoint = "git_config_free" ) ]
380+ public static extern void Free ( IntPtr configHandle ) ;
381+ }
382+
302383 public static class Object
303384 {
304385 [ DllImport ( Git2NativeLibName , EntryPoint = "git_object_type" ) ]
0 commit comments