Skip to content

Commit e32dba4

Browse files
anaisbettsnulltoken
authored andcommitted
Strings in structures are being marshalled as ASCII, Hack fix it
1 parent 9196a48 commit e32dba4

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

LibGit2Sharp/Core/GitIndexEntry.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Runtime.InteropServices;
1+
using System;
2+
using System.Runtime.InteropServices;
23

34
namespace LibGit2Sharp.Core
45
{
@@ -16,6 +17,6 @@ internal class GitIndexEntry
1617
public GitOid oid;
1718
public ushort Flags;
1819
public ushort ExtendedFlags;
19-
public string Path;
20+
public IntPtr Path;
2021
}
2122
}

LibGit2Sharp/Core/GitSignature.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
using System.Runtime.InteropServices;
1+
using System;
2+
using System.Runtime.InteropServices;
23

34
namespace LibGit2Sharp.Core
45
{
56
[StructLayout(LayoutKind.Sequential)]
67
internal class GitSignature
78
{
8-
public string Name;
9-
public string Email;
9+
public IntPtr Name;
10+
public IntPtr Email;
1011
public GitTime When;
1112
}
1213
}

LibGit2Sharp/IndexEntry.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public class IndexEntry : IEquatable<IndexEntry>
1414

1515
private Func<FileStatus> state;
1616

17+
private static readonly Utf8Marshaler marshaler = new Utf8Marshaler();
18+
1719
/// <summary>
1820
/// State of the version of the <see cref = "Blob" /> pointed at by this <see cref = "IndexEntry" />,
1921
/// compared against the <see cref = "Blob" /> known from the <see cref = "Repository.Head" /> and the file in the working directory.
@@ -36,11 +38,13 @@ public FileStatus State
3638
internal static IndexEntry CreateFromPtr(Repository repo, IntPtr ptr)
3739
{
3840
var entry = (GitIndexEntry)Marshal.PtrToStructure(ptr, typeof(GitIndexEntry));
41+
var path = (string)marshaler.MarshalNativeToManaged(entry.Path);
42+
3943
return new IndexEntry
4044
{
41-
Path = PosixPathHelper.ToNative(entry.Path),
45+
Path = PosixPathHelper.ToNative(path),
4246
Id = new ObjectId(entry.oid),
43-
state = () => repo.Index.RetrieveStatus(entry.Path)
47+
state = () => repo.Index.RetrieveStatus(path)
4448
};
4549
}
4650

LibGit2Sharp/Signature.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@ public class Signature
1313
private readonly string name;
1414
private readonly string email;
1515

16+
private static readonly Utf8Marshaler marshaler = new Utf8Marshaler();
17+
1618
internal Signature(IntPtr signaturePtr)
1719
{
1820
var handle = new GitSignature();
1921
Marshal.PtrToStructure(signaturePtr, handle);
2022

21-
name = handle.Name;
22-
email = handle.Email;
23+
// XXX: This is unbelievably hacky, but I can't get the
24+
// Utf8Marshaller to work properly.
25+
name = (string)marshaler.MarshalNativeToManaged(handle.Name);
26+
email = (string)marshaler.MarshalNativeToManaged(handle.Email);
2327
when = Epoch.ToDateTimeOffset(handle.When.Time, handle.When.Offset);
2428
}
2529

0 commit comments

Comments
 (0)