@@ -14,6 +14,85 @@ namespace LibGit2Sharp.Core
1414{
1515 internal class Proxy
1616 {
17+ #region giterr_
18+
19+ public static void giterr_set_str ( GitErrorCategory error_class , Exception exception )
20+ {
21+ if ( exception is OutOfMemoryException )
22+ {
23+ NativeMethods . giterr_set_oom ( ) ;
24+ }
25+ else
26+ {
27+ NativeMethods . giterr_set_str ( error_class , ErrorMessageFromException ( exception ) ) ;
28+ }
29+ }
30+
31+ public static void giterr_set_str ( GitErrorCategory error_class , String errorString )
32+ {
33+ NativeMethods . giterr_set_str ( error_class , errorString ) ;
34+ }
35+
36+ /// <summary>
37+ /// This method will take an exception and try to generate an error message
38+ /// that captures the important messages of the error.
39+ /// The formatting is a bit subjective.
40+ /// </summary>
41+ /// <param name="ex"></param>
42+ /// <returns></returns>
43+ public static string ErrorMessageFromException ( Exception ex )
44+ {
45+ StringBuilder sb = new StringBuilder ( ) ;
46+ BuildErrorMessageFromException ( sb , 0 , ex ) ;
47+ return sb . ToString ( ) ;
48+ }
49+
50+ private static void BuildErrorMessageFromException ( StringBuilder sb , int level , Exception ex )
51+ {
52+ string indent = new string ( ' ' , level * 4 ) ;
53+ sb . AppendFormat ( "{0}{1}" , indent , ex . Message ) ;
54+
55+ if ( ex is AggregateException )
56+ {
57+ AggregateException aggregateException = ( ( AggregateException ) ex ) . Flatten ( ) ;
58+
59+ if ( aggregateException . InnerExceptions . Count == 1 )
60+ {
61+ sb . AppendLine ( ) ;
62+ sb . AppendLine ( ) ;
63+
64+ sb . AppendFormat ( "{0}Contained Exception:{1}" , indent , Environment . NewLine ) ;
65+ BuildErrorMessageFromException ( sb , level + 1 , aggregateException . InnerException ) ;
66+ }
67+ else
68+ {
69+ sb . AppendLine ( ) ;
70+ sb . AppendLine ( ) ;
71+
72+ sb . AppendFormat ( "{0}Contained Exceptions:{1}" , indent , Environment . NewLine ) ;
73+ for ( int i = 0 ; i < aggregateException . InnerExceptions . Count ; i ++ )
74+ {
75+ if ( i != 0 )
76+ {
77+ sb . AppendLine ( ) ;
78+ sb . AppendLine ( ) ;
79+ }
80+
81+ BuildErrorMessageFromException ( sb , level + 1 , aggregateException . InnerExceptions [ i ] ) ;
82+ }
83+ }
84+ }
85+ else if ( ex . InnerException != null )
86+ {
87+ sb . AppendLine ( ) ;
88+ sb . AppendLine ( ) ;
89+ sb . AppendFormat ( "{0}Inner Exception:{1}" , indent , Environment . NewLine ) ;
90+ BuildErrorMessageFromException ( sb , level + 1 , ex . InnerException ) ;
91+ }
92+ }
93+
94+ #endregion
95+
1796 #region git_blame_
1897
1998 public static unsafe BlameHandle git_blame_file (
@@ -207,9 +286,9 @@ public static unsafe string git_branch_upstream_name(RepositoryHandle handle, st
207286
208287 #region git_buf_
209288
210- public static void git_buf_dispose ( GitBuf buf )
289+ public static void git_buf_free ( GitBuf buf )
211290 {
212- NativeMethods . git_buf_dispose ( buf ) ;
291+ NativeMethods . git_buf_free ( buf ) ;
213292 }
214293
215294 #endregion
@@ -851,85 +930,6 @@ public static unsafe int git_diff_num_deltas(DiffHandle diff)
851930
852931 #endregion
853932
854- #region git_error_
855-
856- public static void git_error_set_str ( GitErrorCategory error_class , Exception exception )
857- {
858- if ( exception is OutOfMemoryException )
859- {
860- NativeMethods . git_error_set_oom ( ) ;
861- }
862- else
863- {
864- NativeMethods . git_error_set_str ( error_class , ErrorMessageFromException ( exception ) ) ;
865- }
866- }
867-
868- public static void git_error_set_str ( GitErrorCategory error_class , String errorString )
869- {
870- NativeMethods . git_error_set_str ( error_class , errorString ) ;
871- }
872-
873- /// <summary>
874- /// This method will take an exception and try to generate an error message
875- /// that captures the important messages of the error.
876- /// The formatting is a bit subjective.
877- /// </summary>
878- /// <param name="ex"></param>
879- /// <returns></returns>
880- public static string ErrorMessageFromException ( Exception ex )
881- {
882- StringBuilder sb = new StringBuilder ( ) ;
883- BuildErrorMessageFromException ( sb , 0 , ex ) ;
884- return sb . ToString ( ) ;
885- }
886-
887- private static void BuildErrorMessageFromException ( StringBuilder sb , int level , Exception ex )
888- {
889- string indent = new string ( ' ' , level * 4 ) ;
890- sb . AppendFormat ( "{0}{1}" , indent , ex . Message ) ;
891-
892- if ( ex is AggregateException )
893- {
894- AggregateException aggregateException = ( ( AggregateException ) ex ) . Flatten ( ) ;
895-
896- if ( aggregateException . InnerExceptions . Count == 1 )
897- {
898- sb . AppendLine ( ) ;
899- sb . AppendLine ( ) ;
900-
901- sb . AppendFormat ( "{0}Contained Exception:{1}" , indent , Environment . NewLine ) ;
902- BuildErrorMessageFromException ( sb , level + 1 , aggregateException . InnerException ) ;
903- }
904- else
905- {
906- sb . AppendLine ( ) ;
907- sb . AppendLine ( ) ;
908-
909- sb . AppendFormat ( "{0}Contained Exceptions:{1}" , indent , Environment . NewLine ) ;
910- for ( int i = 0 ; i < aggregateException . InnerExceptions . Count ; i ++ )
911- {
912- if ( i != 0 )
913- {
914- sb . AppendLine ( ) ;
915- sb . AppendLine ( ) ;
916- }
917-
918- BuildErrorMessageFromException ( sb , level + 1 , aggregateException . InnerExceptions [ i ] ) ;
919- }
920- }
921- }
922- else if ( ex . InnerException != null )
923- {
924- sb . AppendLine ( ) ;
925- sb . AppendLine ( ) ;
926- sb . AppendFormat ( "{0}Inner Exception:{1}" , indent , Environment . NewLine ) ;
927- BuildErrorMessageFromException ( sb , level + 1 , ex . InnerException ) ;
928- }
929- }
930-
931- #endregion
932-
933933 #region git_filter_
934934
935935 public static void git_filter_register ( string name , IntPtr filterPtr , int priority )
0 commit comments