8000 Upgrade libgit2 binaries to 54695f4 · mm201/libgit2sharp@ba918bb · GitHub
[go: up one dir, main page]

Skip to content

Commit ba918bb

Browse files
committed
Upgrade libgit2 binaries to 54695f4
1 parent 5b219c8 commit ba918bb

File tree

16 files changed

+101
-168
lines changed

16 files changed

+101
-168
lines changed

Lib/NativeBinaries/x86/git2.dll

3.5 KB
Binary file not shown.

Lib/NativeBinaries/x86/git2.pdb

72 KB
Binary file not shown.

LibGit2Sharp.Tests/DiffFixture.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ public class DiffFixture : BaseFixture
1010
//TODO Test binary files (do we have hunks/line callbacks)
1111
//TODO What does content contain when dealing with a Binary file?
1212
//TODO When does it make sense to expose the Binary property?
13-
//TODO The PrintCallBack lacks some context (GitDiffDelta)
1413

1514
[Fact]
1615
public void ComparingATreeAgainstItselfReturnsNoDifference()
@@ -325,8 +324,7 @@ public void CanCompareTwoVersionsOfAFileWithADiffOfTwoHunks()
325324
.Append("+Really!!!!\n")
326325
.Append("+Yeah! Better!\n");
327326

328-
// TODO: uncomment the line below when https://github.com/libgit2/libgit2/pull/643 is merged into development branch.
329-
//Assert.Equal(expected.ToString(), changes.Patch);
327+
Assert.Equal(expected.ToString(), changes.Patch);
330328
}
331329
}
332330
}

LibGit2Sharp/Core/Ensure.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ namespace LibGit2Sharp.Core
1010
[DebuggerStepThrough]
1111
internal static class Ensure
1212
{
13+
private static readonly Utf8Marshaler marshaler = (Utf8Marshaler)Utf8Marshaler.GetInstance(string.Empty);
14+
1315
/// <summary>
1416
/// Checks an argument to ensure it isn't null.
1517
/// </summary>
@@ -62,10 +64,16 @@ public static void Success(int result, bool allowPositiveResult = false)
6264
return;
6365
}
6466

65-
string errorMessage = NativeMethods.git_lasterror();
67+
GitError error = NativeMethods.giterr_last().MarshalAsGitError();
68+
69+
var errorMessage = (string)marshaler.MarshalNativeToManaged(error.Message);
6670

6771
throw new LibGit2Exception(
68-
String.Format(CultureInfo.InvariantCulture, "An error was raised by libgit2. Error code = {0} ({1}).{2}{3}", Enum.GetName(typeof(GitErrorCode), result), result, Environment.NewLine, errorMessage));
72+
String.Format(CultureInfo.InvariantCulture, "An error was raised by libgit2. Class = {0} ({1}).{2}{3}",
73+
Enum.GetName(typeof(GitErrorClass), error.Klass.ToInt32()),
74+
result,
75+
Environment.NewLine,
76+
errorMessage));
6977
}
7078

7179
/// <summary>

LibGit2Sharp/Core/GitError.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
4+
namespace LibGit2Sharp.Core
5+
{
6+
[StructLayout(LayoutKind.Sequential)]
7+
internal class GitError
8+
{
9+
public IntPtr Message;
10+
public IntPtr Klass;
11+
}
12+
13+
internal enum GitErrorClass
14+
{
15+
GITERR_NOMEMORY,
16+
GITERR_OS,
17+
GITERR_INVALID,
18+
GITERR_REFERENCE,
19+
GITERR_ZLIB,
20+
GITERR_REPOSITORY,
21+
GITERR_CONFIG,
22+
GITERR_REGEX,
23+
GITERR_ODB,
24+
GITERR_INDEX,
25+
GITERR_OBJECT,
26+
GITERR_NET,
27+
GITERR_TAG,
28+
GITERR_TREE,
29+
}
30+
}

LibGit2Sharp/Core/GitErrorCode.cs

Lines changed: 8 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -15,111 +15,11 @@ internal enum GitErrorCode
1515
/// </summary>
1616
GIT_ERROR = -1,
1717

18-
/// <summary>
19-
/// Input was not a properly formatted Git object id.
20-
/// </summary>
21-
GIT_ENOTOID = -2,
22-
2318
/// <summary>
2419
/// Input does not exist in the scope searched.
2520
/// </summary>
2621
GIT_ENOTFOUND = -3,
2722

28-
/// <summary>
29-
/// Not enough space available.
30-
/// </summary>
31-
GIT_ENOMEM = -4,
32-
33-
/// <summary>
34-
/// Consult the OS error information.
35-
/// </summary>
36-
GIT_EOSERR = -5,
37-
38-
/// <summary>
39-
/// The specified object is of invalid type
40-
/// </summary>
41-
GIT_EOBJTYPE = -6,
42-
43-
/// <summary>
44-
/// The specified repository is invalid
45-
/// </summary>
46-
GIT_ENOTAREPO = -7,
47-
48-
/// <summary>
49-
/// The object type is invalid or doesn't match
50-
/// </summary>
51-
GIT_EINVALIDTYPE = -8,
52-
53-
/// <summary>
54-
/// The object cannot be written that because it's missing internal data
55-
/// </summary>
56-
GIT_EMISSINGOBJDATA = -9,
57-
58-
/// <summary>
59-
/// The packfile for the ODB is corrupted
60-
/// </summary>
61-
GIT_EPACKCORRUPTED = -10,
62-
63-
/// <summary>
64-
/// Failed to adquire or release a file lock
65-
/// </summary>
66-
GIT_EFLOCKFAIL = -11,
67-
68-
/// <summary>
69-
/// The Z library failed to inflate/deflate an object's data
70-
/// </summary>
71-
GIT_EZLIB = -12,
72-
73-
/// <summary>
74-
/// The queried object is currently busy
75-
/// </summary>
76-
GIT_EBUSY = -13,
77-
78-
/// <summary>
79-
/// The index file is not backed up by an existing repository
80-
/// </summary>
81-
GIT_EBAREINDEX = -14,
82-
83-
/// <summary>
84-
/// The name of the reference is not valid
85-
/// </summary>
86-
GIT_EINVALIDREFNAME = -15,
87-
88-
/// <summary>
89-
/// The specified reference has its data corrupted
90-
/// </summary>
91-
GIT_EREFCORRUPTED = -16,
92-
93-
/// <summary>
94-
/// The specified symbolic reference is too deeply nested
95-
/// </summary>
96-
GIT_ETOONESTEDSYMREF = -17,
97-
98-
/// <summary>
99-
/// The pack-refs file is either corrupted of its format is not currently supported
100-
/// </summary>
101-
GIT_EPACKEDREFSCORRUPTED = -18,
102-
103-
/// <summary>
104-
/// The path is invalid
105-
/// </summary>
106-
GIT_EINVALIDPATH = -19,
107-
108-
/// <summary>
109-
/// The revision walker is empty; there are no more commits left to iterate
110-
/// </summary>
111-
GIT_EREVWALKOVER = -20,
112-
113-
/// <summary>
114-
/// The state of the reference is not valid
115-
/// </summary>
116-
GIT_EINVALIDREFSTATE = -21,
117-
118-
/// <summary>
119-
/// This feature has not been implemented yet
120-
/// </summary>
121-
GIT_ENOTIMPLEMENTED = -22,
122-
12323
/// <summary>
12424
/// A reference with this name already exists
12525
/// </summary>
@@ -131,33 +31,23 @@ internal enum GitErrorCode
13131
GIT_EOVERFLOW = -24,
13232

13333
/// <summary>
134-
/// The given literal is not a valid number
135-
/// </summary>
136-
GIT_ENOTNUM = -25,
137-
138-
/// <summary>
139-
/// Streaming error
140-
/// </summary>
141-
GIT_ESTREAM = -26,
142-
143-
/// <summary>
144-
/// invalid arguments to function
34+
/// The given short oid is ambiguous
14535
/// </summary>
146-
GIT_EINVALIDARGS = -27,
36+
GIT_EAMBIGUOUS = -29,
14737

14838
/// <summary>
149-
/// The specified object has its data corrupted
39+
/// Skip and passthrough the given ODB backend
15040
/// </summary>
151-
GIT_EOBJCORRUPTED = -28,
41+
GIT_EPASSTHROUGH = -30,
15242

15343
/// <summary>
154-
/// The given short oid is ambiguous
44+
/// The buffer is too short to satisfy the request
15545
/// </summary>
156-
GIT_EAMBIGUOUSOIDPREFIX = -29,
46+
GIT_ESHORTBUFFER = -32,
15747

15848
/// <summary>
159-
/// Skip and passthrough the given ODB backend
49+
/// The revision walker is empty; there are no more commits left to iterate
16050
/// </summary>
161-
GIT_EPASSTHROUGH = -30,
51+
GIT_EREVWALKOVER = -33,
16252
}
16353
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System.Runtime.InteropServices;
2+
3+
namespace LibGit2Sharp.Core.Handles
4+
{
5+
internal class GitErrorSafeHandle : NotOwnedSafeHandleBase
6+
{
7+
public GitError MarshalAsGitError()
8+
{
9+
return (GitError)Marshal.PtrToStructure(handle, typeof(GitError));
10+
}
11+
}
12+
}

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ public static bool RepositoryStateChecker(RepositorySafeHandle repositoryPtr, Fu
6565
return (res == 1);
6666
}
6767

68+
[DllImport(libgit2)]
69+
public static extern GitErrorSafeHandle giterr_last();
70+
6871
[DllImport(libgit2)]
6972
public static extern int git_blob_create_fromfile(
7073
ref GitOid oid,
@@ -231,31 +234,27 @@ internal delegate int git_diff_hunk_fn(
231234
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string header,
232235
IntPtr headerLen);
233236

234-
internal delegate int git_diff_line_fn(
235-
IntPtr data,
236-
GitDiffDelta delta,
237-
GitDiffLineOrigin lineOrigin,
238-
IntPtr content,
239-
IntPtr contentLen);
240-
241237
[DllImport(libgit2)]
242238
public static extern int git_diff_foreach(
243239
DiffListSafeHandle diff,
244240
IntPtr callbackData,
245241
git_diff_file_fn fileCallback,
246242
git_diff_hunk_fn hunkCallback,
247-
git_diff_line_fn lineCallback);
243+
git_diff_data_fn lineCallback);
248244

249-
internal delegate int git_diff_output_fn(
245+
internal delegate int git_diff_data_fn(
250246
IntPtr data,
247+
GitDiffDelta delta,
248+
GitDiffRange range,
251249
GitDiffLineOrigin lineOrigin,
252-
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string formattedOutput);
250+
IntPtr content,
251+
IntPtr contentLen);
253252

254253
[DllImport(libgit2)]
255254
public static extern int git_diff_print_patch(
256255
DiffListSafeHandle diff,
257256
IntPtr data,
258-
git_diff_output_fn printCallback);
257+
git_diff_data_fn printCallback);
259258

260259
[DllImport(libgit2)]
261260
public static extern int git_diff_blobs(
@@ -265,7 +264,7 @@ public static extern int git_diff_blobs(
265264
GitDiffOptions options,
266265
object data,
267266
git_diff_hunk_fn hunkCallback,
268-
git_diff_line_fn lineCallback);
267+
git_diff_data_fn lineCallback);
269268

270269
[DllImport(libgit2)]
271270
public static extern int git_index_add(
@@ -301,10 +300,6 @@ public static extern int git_index_find(
301300
[DllImport(libgit2)]
302301
public static extern int git_index_write(IndexSafeHandle index);
303302

304-
[DllImport(libgit2)]
305-
[return : MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))]
306-
public static extern string git_lasterror();
307-
308303
[DllImport(libgit2)]
309304
public static extern int git_odb_exists(ObjectDatabaseSafeHandle odb, ref GitOid id);
310305

@@ -405,8 +400,9 @@ public static extern int git_remote_load(
405400
public static extern int git_remote_new(
406401
out RemoteSafeHandle remote,
407402
RepositorySafeHandle repo,
403+
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string name,
408404
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string url,
409-
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string name);
405+
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string fetchrefspec);
410406

411407
[DllImport(libgit2)]
412408
[return : MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))]

LibGit2Sharp/Core/Utf8Marshaler.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ protected unsafe string NativeToString(IntPtr pNativeData)
6161
}
6262
var length = (int)(walk - (byte*)pNativeData);
6363

64+
return NativeToString(pNativeData, length);
65+
}
66+
67+
public string NativeToString(IntPtr pNativeData, int length)
68+
{
6469
// should not be null terminated
6570
var strbuf = new byte[length];
6671

LibGit2Sharp/LibGit2Sharp.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@
6161
<Compile Include="Core\EnumExtensions.cs" />
6262
<Compile Include="ChangeKind.cs" />
6363
<Compile Include="Core\GitDiff.cs" />
64+
<Compile Include="Core\GitError.cs" />
6465
<Compile Include="Core\GitObjectExtensions.cs" />
66+
<Compile Include="Core\Handles\GitErrorSafeHandle.cs" />
6567
<Compile Include="Core\Handles\ObjectDatabaseSafeHandle.cs" />
6668
<Compile Include="Core\Handles\DiffListSafeHandle.cs" />
6769
<Compile Include="Core\Handles\GitObjectSafeHandle.cs" />

0 commit comments

Comments
 (0)
0