Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ba308b8

Browse files
committed
git_error: instead of giterr
libgit2 has updated some function signatures for consistency, including the `giterr` family of functions which is now `git_error`.
1 parent 2d6d3e6 commit ba308b8

10 files changed

+114
-114
lines changed

LibGit2Sharp/Core/Ensure.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ private static unsafe void HandleError(int result)
134134
{
135135
string errorMessage;
136136
GitErrorCategory errorCategory = GitErrorCategory.Unknown;
137-
GitError* error = NativeMethods.giterr_last();
137+
GitError* error = NativeMethods.git_error_last();
138138

139139
if (error == null)
140140
{

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,15 @@ private sealed class NativeShutdownObject : CriticalFinalizerObject
9696
}
9797

9898
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
99-
internal static extern unsafe GitError* giterr_last();
99+
internal static extern unsafe GitError* git_error_last();
100100

101101
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
102-
internal static extern void giterr_set_str(
102+
internal static extern void git_error_set_str(
103103
GitErrorCategory error_class,
104104
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string errorString);
105105

106106
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
107-
internal static extern void giterr_set_oom();
107+
internal static extern void git_error_set_oom();
108108

109109
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
110110
internal static extern unsafe UInt32 git_blame_get_hunk_count(git_blame* blame);

LibGit2Sharp/Core/Proxy.cs

Lines changed: 79 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -14,85 +14,6 @@ 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-
9617
#region git_blame_
9718

9819
public static unsafe BlameHandle git_blame_file(
@@ -924,6 +845,85 @@ public static unsafe int git_diff_num_deltas(DiffHandle diff)
924845

925846
#endregion
926847

848+
#region git_error_
849+
850+
public static void git_error_set_str(GitErrorCategory error_class, Exception exception)
851+
{
852+
if (exception is OutOfMemoryException)
853+
{
854+
NativeMethods.git_error_set_oom();
855+
}
856+
else
857+
{
858+
NativeMethods.git_error_set_str(error_class, ErrorMessageFromException(exception));
859+
}
860+
}
861+
862+
public static void git_error_set_str(GitErrorCategory error_class, String errorString)
863+
{
864+
NativeMethods.git_error_set_str(error_class, errorString);
865+
}
866+
867+
/// <summary>
868+
/// This method will take an exception and try to generate an error message
869+
/// that captures the important messages of the error.
870+
/// The formatting is a bit subjective.
871+
/// </summary>
872+
/// <param name="ex"></param>
873+
/// <returns></returns>
874+
public static string ErrorMessageFromException(Exception ex)
875+
{
876+
StringBuilder sb = new StringBuilder();
877+
BuildErrorMessageFromException(sb, 0, ex);
878+
return sb.ToString();
879+
}
880+
881+
private static void BuildErrorMessageFromException(StringBuilder sb, int level, Exception ex)
882+
{
883+
string indent = new string(' ', level * 4);
884+
sb.AppendFormat("{0}{1}", indent, ex.Message);
885+
886+
if (ex is AggregateException)
887+
{
888+
AggregateException aggregateException = ((AggregateException)ex).Flatten();
889+
890+
if (aggregateException.InnerExceptions.Count == 1)
891+
{
892+
sb.AppendLine();
893+
sb.AppendLine();
894+
895+
sb.AppendFormat("{0}Contained Exception:{1}", indent, Environment.NewLine);
896+
BuildErrorMessageFromException(sb, level + 1, aggregateException.InnerException);
897+
}
898+
else
899+
{
900+
sb.AppendLine();
901+
sb.AppendLine();
902+
903+
sb.AppendFormat("{0}Contained Exceptions:{1}", indent, Environment.NewLine);
904+
for (int i = 0; i < aggregateException.InnerExceptions.Count; i++)
905+
{
906+
if (i != 0)
907+
{
908+
sb.AppendLine();
909+
sb.AppendLine();
910+
}
911+
912+
BuildErrorMessageFromException(sb, level + 1, aggregateException.InnerExceptions[i]);
913+
}
914+
}
915+
}
916+
else if (ex.InnerException != null)
917+
{
918+
sb.AppendLine();
919+
sb.AppendLine();
920+
sb.AppendFormat("{0}Inner Exception:{1}", indent, Environment.NewLine);
921+
BuildErrorMessageFromException(sb, level + 1, ex.InnerException);
922+
}
923+
}
924+
925+
#endregion
926+
927927
#region git_filter_
928928

929929
public static void git_filter_register(string name, IntPtr filterPtr, int priority)

LibGit2Sharp/Filter.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ int InitializeCallback(IntPtr filterPointer)
236236
{
237237
Log.Write(LogLevel.Error, "Filter.InitializeCallback exception");
238238
Log.Write(LogLevel.Error, exception.ToString());
239-
Proxy.giterr_set_str(GitErrorCategory.Filter, exception);
239+
Proxy.git_error_set_str(GitErrorCategory.Filter, exception);
240240
result = (int)GitErrorCode.Error;
241241
}
242242
return result;
@@ -286,7 +286,7 @@ int StreamCreateCallback(out IntPtr git_writestream_out, GitFilter self, IntPtr
286286

287287
Log.Write(LogLevel.Error, "Filter.StreamCreateCallback exception");
288288
Log.Write(LogLevel.Error, exception.ToString());
289-
Proxy.giterr_set_str(GitErrorCategory.Filter, exception);
289+
Proxy.git_error_set_str(GitErrorCategory.Filter, exception);
290290
result = (int)GitErrorCode.Error;
291291
}
292292

@@ -322,7 +322,7 @@ int StreamCloseCallback(IntPtr stream)
322322
{
323323
Log.Write(LogLevel.Error, "Filter.StreamCloseCallback exception");
324324
Log.Write(LogLevel.Error, exception.ToString());
325-
Proxy.giterr_set_str(GitErrorCategory.Filter, exception);
325+
Proxy.git_error_set_str(GitErrorCategory.Filter, exception);
326326
result = (int)GitErrorCode.Error;
327327
}
328328

@@ -384,7 +384,7 @@ unsafe int StreamWriteCallback(IntPtr stream, IntPtr buffer, UIntPtr len)
384384
break;
385385

386386
default:
387-
Proxy.giterr_set_str(GitErrorCategory.Filter, "Unexpected filter mode.");
387+
Proxy.git_error_set_str(GitErrorCategory.Filter, "Unexpected filter mode.");
388388
return (int)GitErrorCode.Ambiguous;
389389
}
390390
}
@@ -393,7 +393,7 @@ unsafe int StreamWriteCallback(IntPtr stream, IntPtr buffer, UIntPtr len)
393393
{
394394
Log.Write(LogLevel.Error, "Filter.StreamWriteCallback exception");
395395
Log.Write(LogLevel.Error, exception.ToString());
396-
Proxy.giterr_set_str(GitErrorCategory.Filter, exception);
396+
Proxy.git_error_set_str(GitErrorCategory.Filter, exception);
397397
result = (int)GitErrorCode.Error;
398398
}
399399

LibGit2Sharp/OdbBackend.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ private static OdbBackend MarshalOdbBackend(IntPtr backendPtr)
238238

239239
if (odbBackend == null)
240240
{
241-
Proxy.giterr_set_str(GitErrorCategory.Reference, "Cannot retrieve the managed OdbBackend.");
241+
Proxy.git_error_set_str(GitErrorCategory.Reference, "Cannot retrieve the managed OdbBackend.");
242242
return null;
243243
}
244244

@@ -288,7 +288,7 @@ private unsafe static int Read(
288288
}
289289
catch (Exception ex)
290290
{
291-
Proxy.giterr_set_str(GitErrorCategory.Odb, ex);
291+
Proxy.git_error_set_str(GitErrorCategory.Odb, ex);
292292
return (int)GitErrorCode.Error;
293293
}
294294
finally
@@ -352,7 +352,7 @@ private unsafe static int ReadPrefix(
352352
}
353353
catch (Exception ex)
354354
{
355-
Proxy.giterr_set_str(GitErrorCategory.Odb, ex);
355+
Proxy.git_error_set_str(GitErrorCategory.Odb, ex);
356356
return (int)GitErrorCode.Error;
357357
}
358358
finally
@@ -397,7 +397,7 @@ private static int ReadHeader(
397397
}
398398
catch (Exception ex)
399399
{
400-
Proxy.giterr_set_str(GitErrorCategory.Odb, ex);
400+
Proxy.git_error_set_str(GitErrorCategory.Odb, ex);
401401
return (int)GitErrorCode.Error;
402402
}
403403

@@ -428,7 +428,7 @@ private static unsafe int Write(
428428
}
429429
catch (Exception ex)
430430
{
431-
Proxy.giterr_set_str(GitErrorCategory.Odb, ex);
431+
Proxy.git_error_set_str(GitErrorCategory.Odb, ex);
432432
return (int)GitErrorCode.Error;
433433
}
434434
}
@@ -463,7 +463,7 @@ private static int WriteStream(
463463
}
464464
catch (Exception ex)
465465
{
466-
Proxy.giterr_set_str(GitErrorCategory.Odb, ex);
466+
Proxy.git_error_set_str(GitErrorCategory.Odb, ex);
467467
return (int)GitErrorCode.Error;
468468
}
469469
}
@@ -495,7 +495,7 @@ private static int ReadStream(
495495
}
496496
catch (Exception ex)
497497
{
498-
Proxy.giterr_set_str(GitErrorCategory.Odb, ex);
498+
Proxy.git_error_set_str(GitErrorCategory.Odb, ex);
499499
return (int)GitErrorCode.Error;
500500
}
501501
}
@@ -516,7 +516,7 @@ private static bool Exists(
516516
}
517517
catch (Exception ex)
518518
{
519-
Proxy.giterr_set_str(GitErrorCategory.Odb, ex);
519+
Proxy.git_error_set_str(GitErrorCategory.Odb, ex);
520520
return false;
521521
}
522522
}
@@ -550,7 +550,7 @@ private static int ExistsPrefix(
550550
}
551551
catch (Exception ex)
552552
{
553-
Proxy.giterr_set_str(GitErrorCategory.Odb, ex);
553+
Proxy.git_error_set_str(GitErrorCategory.Odb, ex);
554554
return (int)GitErrorCode.Error;
555555
}
556556
}
@@ -572,7 +572,7 @@ private static int Foreach(
572572
}
573573
catch (Exception ex)
574574
{
575-
Proxy.giterr_set_str(GitErrorCategory.Odb, ex);
575+
Proxy.git_error_set_str(GitErrorCategory.Odb, ex);
576576
return (int)GitErrorCode.Error;
577577
}
578578
}
@@ -601,7 +601,7 @@ private static void Free(
601601
}
602602
catch (Exception ex)
603603
{
604-
Proxy.giterr_set_str(GitErrorCategory.Odb, ex);
604+
Proxy.git_error_set_str(GitErrorCategory.Odb, ex);
605605
}
606606
}
607607

LibGit2Sharp/OdbBackendStream.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ private unsafe static int Read(IntPtr stream, IntPtr buffer, UIntPtr len)
140140
}
141141
catch (Exception ex)
142142
{
143-
Proxy.giterr_set_str(GitErrorCategory.Odb, ex);
143+
Proxy.git_error_set_str(GitErrorCategory.Odb, ex);
144144
}
145145
}
146146
}
@@ -164,7 +164,7 @@ private static unsafe int Write(IntPtr stream, IntPtr buffer, UIntPtr len)
164164
}
165165
catch (Exception ex)
166166
{
167-
Proxy.giterr_set_str(GitErrorCategory.Odb, ex);
167+
Proxy.git_error_set_str(GitErrorCategory.Odb, ex);
168168
}
169169
}
170170
}
@@ -184,7 +184,7 @@ private static int FinalizeWrite(IntPtr stream, ref GitOid oid)
184184
}
185185
catch (Exception ex)
186186
{
187-
Proxy.giterr_set_str(GitErrorCategory.Odb, ex);
187+
Proxy.git_error_set_str(GitErrorCategory.Odb, ex);
188188
}
189189
}
190190

@@ -203,7 +203,7 @@ private static void Free(IntPtr stream)
203203
}
204204
catch (Exception ex)
205205
{
206-
Proxy.giterr_set_str(GitErrorCategory.Odb, ex);
206+
Proxy.git_error_set_str(GitErrorCategory.Odb, ex);
207207
}
208208
}
209209
}

0 commit comments

Comments
 (0)