diff options
-rw-r--r-- | LibGit2Sharp/Commit.cs | 4 | ||||
-rw-r--r-- | LibGit2Sharp/Core/Ensure.cs | 2 | ||||
-rw-r--r-- | LibGit2Sharp/Core/IntPtrExtensions.cs | 13 | ||||
-rw-r--r-- | LibGit2Sharp/Core/NativeMethods.cs | 30 | ||||
-rw-r--r-- | LibGit2Sharp/LibGit2Sharp.csproj | 1 | ||||
-rw-r--r-- | LibGit2Sharp/Reference.cs | 6 | ||||
-rw-r--r-- | LibGit2Sharp/Repository.cs | 6 | ||||
-rw-r--r-- | LibGit2Sharp/TagAnnotation.cs | 4 | ||||
-rwxr-xr-x | LibGit2Sharp/TreeEntry.cs | 2 |
9 files changed, 36 insertions, 32 deletions
diff --git a/LibGit2Sharp/Commit.cs b/LibGit2Sharp/Commit.cs index a67ff6ef..b9368ec6 100644 --- a/LibGit2Sharp/Commit.cs +++ b/LibGit2Sharp/Commit.cs @@ -89,8 +89,8 @@ namespace LibGit2Sharp return new Commit(id, treeId, repo) { - Message = NativeMethods.git_commit_message(obj), - MessageShort = NativeMethods.git_commit_message_short(obj), + Message = NativeMethods.git_commit_message(obj).MarshallAsString(), + MessageShort = NativeMethods.git_commit_message_short(obj).MarshallAsString(), Author = new Signature(NativeMethods.git_commit_author(obj)), Committer = new Signature(NativeMethods.git_commit_committer(obj)), }; diff --git a/LibGit2Sharp/Core/Ensure.cs b/LibGit2Sharp/Core/Ensure.cs index 4cbc6099..e0813fd4 100644 --- a/LibGit2Sharp/Core/Ensure.cs +++ b/LibGit2Sharp/Core/Ensure.cs @@ -47,7 +47,7 @@ namespace LibGit2Sharp.Core return; } - string errorMessage = NativeMethods.git_lasterror(); + string errorMessage = NativeMethods.git_lasterror().MarshallAsString(); throw new ApplicationException( 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)); diff --git a/LibGit2Sharp/Core/IntPtrExtensions.cs b/LibGit2Sharp/Core/IntPtrExtensions.cs new file mode 100644 index 00000000..b6378b07 --- /dev/null +++ b/LibGit2Sharp/Core/IntPtrExtensions.cs @@ -0,0 +1,13 @@ +using System; +using System.Runtime.InteropServices; + +namespace LibGit2Sharp.Core +{ + internal static class IntPtrExtensions + { + public static string MarshallAsString(this IntPtr intPtr) + { + return Marshal.PtrToStringAnsi(intPtr); + } + } +}
\ No newline at end of file diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs index 4344ec97..c51e2d46 100644 --- a/LibGit2Sharp/Core/NativeMethods.cs +++ b/LibGit2Sharp/Core/NativeMethods.cs @@ -23,12 +23,10 @@ namespace LibGit2Sharp.Core public static extern int git_commit_create_o(out GitOid oid, RepositorySafeHandle repo, string updateRef, IntPtr author, IntPtr committer, string message, IntPtr tree, int parentCount, IntPtr parents); [DllImport(libgit2)] - [return: MarshalAs(UnmanagedType.AnsiBStr)] - public static extern string git_commit_message(IntPtr commit); + public static extern IntPtr git_commit_message(IntPtr commit); [DllImport(libgit2)] - [return: MarshalAs(UnmanagedType.AnsiBStr)] - public static extern string git_commit_message_short(IntPtr commit); + public static extern IntPtr git_commit_message_short(IntPtr commit); [DllImport(libgit2)] public static extern int git_commit_parent(out IntPtr parentCommit, IntPtr commit, uint n); @@ -61,8 +59,7 @@ namespace LibGit2Sharp.Core public static extern int git_index_open_inrepo(out IndexSafeHandle index, RepositorySafeHandle repo); [DllImport(libgit2)] - [return: MarshalAs(UnmanagedType.AnsiBStr)] - public static extern string git_lasterror(); + public static extern IntPtr git_lasterror(); [DllImport(libgit2)] public static extern void git_object_close(IntPtr obj); @@ -111,8 +108,7 @@ namespace LibGit2Sharp.Core public static extern int git_reference_lookup(out IntPtr reference, RepositorySafeHandle repo, string name); [DllImport(libgit2)] - [return: MarshalAs(UnmanagedType.AnsiBStr)] - public static extern string git_reference_name(IntPtr reference); + public static extern IntPtr git_reference_name(IntPtr reference); [DllImport(libgit2)] public static extern IntPtr git_reference_oid(IntPtr reference); @@ -133,8 +129,7 @@ namespace LibGit2Sharp.Core public static extern int git_reference_set_target(IntPtr reference, string target); [DllImport(libgit2)] - [return: MarshalAs(UnmanagedType.AnsiBStr)] - public static extern string git_reference_target(IntPtr reference); + public static extern IntPtr git_reference_target(IntPtr reference); [DllImport(libgit2)] public static extern GitReferenceType git_reference_type(IntPtr reference); @@ -156,12 +151,10 @@ namespace LibGit2Sharp.Core public static extern int git_repository_open(out RepositorySafeHandle repository, string path); [DllImport(libgit2)] - [return: MarshalAs(UnmanagedType.AnsiBStr)] - public static extern string git_repository_path(RepositorySafeHandle repository); + public static extern IntPtr git_repository_path(RepositorySafeHandle repository); [DllImport(libgit2)] - [return: MarshalAs(UnmanagedType.AnsiBStr)] - public static extern string git_repository_workdir(RepositorySafeHandle repository); + public static extern IntPtr git_repository_workdir(RepositorySafeHandle repository); [DllImport(libgit2)] public static extern void git_revwalk_free(IntPtr walker); @@ -197,12 +190,10 @@ namespace LibGit2Sharp.Core public static extern int git_tag_delete(RepositorySafeHandle repo, string tagName); [DllImport(libgit2)] - [return: MarshalAs(UnmanagedType.AnsiBStr)] - public static extern string git_tag_message(IntPtr tag); + public static extern IntPtr git_tag_message(IntPtr tag); [DllImport(libgit2)] - [return: MarshalAs(UnmanagedType.AnsiBStr)] - public static extern string git_tag_name(IntPtr tag); + public static extern IntPtr git_tag_name(IntPtr tag); [DllImport(libgit2)] public static extern IntPtr git_tag_tagger(IntPtr tag); @@ -226,8 +217,7 @@ namespace LibGit2Sharp.Core public static extern IntPtr git_tree_entry_id(IntPtr tree); [DllImport(libgit2)] - [return: MarshalAs(UnmanagedType.AnsiBStr)] - public static extern string git_tree_entry_name(IntPtr entry); + public static extern IntPtr git_tree_entry_name(IntPtr entry); [DllImport(libgit2)] public static extern int git_tree_entrycount(IntPtr tree); diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj index 4579d277..a98f3d74 100644 --- a/LibGit2Sharp/LibGit2Sharp.csproj +++ b/LibGit2Sharp/LibGit2Sharp.csproj @@ -58,6 +58,7 @@ <Compile Include="Core\GitReferenceType.cs" /> <Compile Include="Core\GitSignature.cs" /> <Compile Include="Core\GitTime.cs" /> + <Compile Include="Core\IntPtrExtensions.cs" /> <Compile Include="Core\NativeMethods.cs" /> <Compile Include="Core\ObjectSafeWrapper.cs" /> <Compile Include="Core\PosixPathHelper.cs"> diff --git a/LibGit2Sharp/Reference.cs b/LibGit2Sharp/Reference.cs index 442f5367..fd73026a 100644 --- a/LibGit2Sharp/Reference.cs +++ b/LibGit2Sharp/Reference.cs @@ -26,8 +26,8 @@ namespace LibGit2Sharp return default(T); } - var name = NativeMethods.git_reference_name(ptr); - var type = NativeMethods.git_reference_type(ptr); + string name = NativeMethods.git_reference_name(ptr).MarshallAsString(); + GitReferenceType type = NativeMethods.git_reference_type(ptr); Reference reference; string targetIdentifier; @@ -36,7 +36,7 @@ namespace LibGit2Sharp { case GitReferenceType.Symbolic: IntPtr resolveRef; - targetIdentifier = NativeMethods.git_reference_target(ptr); + targetIdentifier = NativeMethods.git_reference_target(ptr).MarshallAsString(); int res = NativeMethods.git_reference_resolve(out resolveRef, ptr); if (res == (int) GitErrorCode.GIT_ENOTFOUND) diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs index f1671e6f..34131982 100644 --- a/LibGit2Sharp/Repository.cs +++ b/LibGit2Sharp/Repository.cs @@ -27,8 +27,8 @@ namespace LibGit2Sharp var res = NativeMethods.git_repository_open(out handle, PosixPathHelper.ToPosix(path)); Ensure.Success(res); - string normalizedPath = NativeMethods.git_repository_path(handle); - string normalizedWorkDir = NativeMethods.git_repository_workdir(handle); + string normalizedPath = NativeMethods.git_repository_path(handle).MarshallAsString(); + string normalizedWorkDir = NativeMethods.git_repository_workdir(handle).MarshallAsString(); Info = new RepositoryInformation(this, normalizedPath, normalizedWorkDir, normalizedWorkDir == null); @@ -164,7 +164,7 @@ namespace LibGit2Sharp var res = NativeMethods.git_repository_init(out repo, PosixPathHelper.ToPosix(path), bare); Ensure.Success(res); - string normalizedPath = NativeMethods.git_repository_path(repo); + string normalizedPath = NativeMethods.git_repository_path(repo).MarshallAsString(); repo.Dispose(); return PosixPathHelper.ToNative(normalizedPath); diff --git a/LibGit2Sharp/TagAnnotation.cs b/LibGit2Sharp/TagAnnotation.cs index 005e7ccd..47280e3c 100644 --- a/LibGit2Sharp/TagAnnotation.cs +++ b/LibGit2Sharp/TagAnnotation.cs @@ -41,8 +41,8 @@ namespace LibGit2Sharp return new TagAnnotation(id) { - Message = NativeMethods.git_tag_message(obj), - Name = NativeMethods.git_tag_name(obj), + Message = NativeMethods.git_tag_message(obj).MarshallAsString(), + Name = NativeMethods.git_tag_name(obj).MarshallAsString(), Tagger = new Signature(NativeMethods.git_tag_tagger(obj)), TargetId = new ObjectId(oid) }; diff --git a/LibGit2Sharp/TreeEntry.cs b/LibGit2Sharp/TreeEntry.cs index 72f42baa..20eea0d6 100755 --- a/LibGit2Sharp/TreeEntry.cs +++ b/LibGit2Sharp/TreeEntry.cs @@ -22,7 +22,7 @@ namespace LibGit2Sharp targetOid = new ObjectId((GitOid)Marshal.PtrToStructure(gitTreeEntryId, typeof(GitOid)));
Attributes = NativeMethods.git_tree_entry_attributes(obj);
- Name = NativeMethods.git_tree_entry_name(obj);
+ Name = NativeMethods.git_tree_entry_name(obj).MarshallAsString();
}
public int Attributes { get; private set; }
|