diff options
author | Paul Betts <paul@paulbetts.org> | 2012-01-31 10:41:01 +0400 |
---|---|---|
committer | nulltoken <emeric.fermas@gmail.com> | 2012-02-02 02:50:19 +0400 |
commit | e32dba45b0edc7283833d2daad19a5ccc6a6452c (patch) | |
tree | e9f70ad5576ca825a525d3ddc04d122089d2208b /LibGit2Sharp | |
parent | 9196a4823cb75dea011a97b4f1b5a12b9d3c041b (diff) |
Strings in structures are being marshalled as ASCII, Hack fix it
Diffstat (limited to 'LibGit2Sharp')
-rw-r--r-- | LibGit2Sharp/Core/GitIndexEntry.cs | 5 | ||||
-rw-r--r-- | LibGit2Sharp/Core/GitSignature.cs | 7 | ||||
-rw-r--r-- | LibGit2Sharp/IndexEntry.cs | 8 | ||||
-rw-r--r-- | LibGit2Sharp/Signature.cs | 8 |
4 files changed, 19 insertions, 9 deletions
diff --git a/LibGit2Sharp/Core/GitIndexEntry.cs b/LibGit2Sharp/Core/GitIndexEntry.cs index 2066cb0b..bf0df2ca 100644 --- a/LibGit2Sharp/Core/GitIndexEntry.cs +++ b/LibGit2Sharp/Core/GitIndexEntry.cs @@ -1,4 +1,5 @@ -using System.Runtime.InteropServices; +using System; +using System.Runtime.InteropServices; namespace LibGit2Sharp.Core { @@ -16,6 +17,6 @@ namespace LibGit2Sharp.Core public GitOid oid; public ushort Flags; public ushort ExtendedFlags; - public string Path; + public IntPtr Path; } } diff --git a/LibGit2Sharp/Core/GitSignature.cs b/LibGit2Sharp/Core/GitSignature.cs index b1ce4b66..3261d4c5 100644 --- a/LibGit2Sharp/Core/GitSignature.cs +++ b/LibGit2Sharp/Core/GitSignature.cs @@ -1,12 +1,13 @@ -using System.Runtime.InteropServices; +using System; +using System.Runtime.InteropServices; namespace LibGit2Sharp.Core { [StructLayout(LayoutKind.Sequential)] internal class GitSignature { - public string Name; - public string Email; + public IntPtr Name; + public IntPtr Email; public GitTime When; } } diff --git a/LibGit2Sharp/IndexEntry.cs b/LibGit2Sharp/IndexEntry.cs index 9b9dbd20..57d4a373 100644 --- a/LibGit2Sharp/IndexEntry.cs +++ b/LibGit2Sharp/IndexEntry.cs @@ -14,6 +14,8 @@ namespace LibGit2Sharp private Func<FileStatus> state; + private static readonly Utf8Marshaler marshaler = new Utf8Marshaler(); + /// <summary> /// State of the version of the <see cref = "Blob" /> pointed at by this <see cref = "IndexEntry" />, /// compared against the <see cref = "Blob" /> known from the <see cref = "Repository.Head" /> and the file in the working directory. @@ -36,11 +38,13 @@ namespace LibGit2Sharp internal static IndexEntry CreateFromPtr(Repository repo, IntPtr ptr) { var entry = (GitIndexEntry)Marshal.PtrToStructure(ptr, typeof(GitIndexEntry)); + var path = (string)marshaler.MarshalNativeToManaged(entry.Path); + return new IndexEntry { - Path = PosixPathHelper.ToNative(entry.Path), + Path = PosixPathHelper.ToNative(path), Id = new ObjectId(entry.oid), - state = () => repo.Index.RetrieveStatus(entry.Path) + state = () => repo.Index.RetrieveStatus(path) }; } diff --git a/LibGit2Sharp/Signature.cs b/LibGit2Sharp/Signature.cs index 32075609..342c6ee4 100644 --- a/LibGit2Sharp/Signature.cs +++ b/LibGit2Sharp/Signature.cs @@ -13,13 +13,17 @@ namespace LibGit2Sharp private readonly string name; private readonly string email; + private static readonly Utf8Marshaler marshaler = new Utf8Marshaler(); + internal Signature(IntPtr signaturePtr) { var handle = new GitSignature(); Marshal.PtrToStructure(signaturePtr, handle); - name = handle.Name; - email = handle.Email; + // XXX: This is unbelievably hacky, but I can't get the + // Utf8Marshaller to work properly. + name = (string)marshaler.MarshalNativeToManaged(handle.Name); + email = (string)marshaler.MarshalNativeToManaged(handle.Email); when = Epoch.ToDateTimeOffset(handle.When.Time, handle.When.Offset); } |