diff --git a/LibGit2Sharp/Core/GitCheckoutOpts.cs b/LibGit2Sharp/Core/GitCheckoutOpts.cs
index 214251d60..29d6aa370 100644
--- a/LibGit2Sharp/Core/GitCheckoutOpts.cs
+++ b/LibGit2Sharp/Core/GitCheckoutOpts.cs
@@ -138,7 +138,7 @@ internal struct GitCheckoutOpts
public progress_cb progress_cb;
public IntPtr progress_payload;
- public GitStrArrayIn paths;
+ public GitStrArray paths;
public IntPtr baseline;
public IntPtr target_directory;
diff --git a/LibGit2Sharp/Core/GitCheckoutOptsWrapper.cs b/LibGit2Sharp/Core/GitCheckoutOptsWrapper.cs
index b98a5cd96..7fda697a4 100644
--- a/LibGit2Sharp/Core/GitCheckoutOptsWrapper.cs
+++ b/LibGit2Sharp/Core/GitCheckoutOptsWrapper.cs
@@ -22,7 +22,7 @@ public GitCheckoutOptsWrapper(IConvertableToGitCheckoutOpts options, FilePath[]
if (paths != null)
{
- PathArray = GitStrArrayIn.BuildFrom(paths);
+ PathArray = GitStrArrayManaged.BuildFrom(paths);
}
Options = new GitCheckoutOpts
@@ -32,7 +32,7 @@ public GitCheckoutOptsWrapper(IConvertableToGitCheckoutOpts options, FilePath[]
progress_cb = Callbacks.CheckoutProgressCallback,
notify_cb = Callbacks.CheckoutNotifyCallback,
notify_flags = options.CheckoutNotifyFlags,
- paths = PathArray,
+ paths = PathArray.Array,
};
}
@@ -50,23 +50,11 @@ public GitCheckoutOptsWrapper(IConvertableToGitCheckoutOpts options, FilePath[]
///
/// Keep the paths around so we can dispose them.
///
- private GitStrArrayIn PathArray;
+ private GitStrArrayManaged PathArray;
public void Dispose()
{
- Dispose(true);
- }
-
- private void Dispose(bool disposing)
- {
- if (disposing)
- {
- if (PathArray != null)
- {
- PathArray.Dispose();
- PathArray = null;
- }
- }
+ PathArray.Dispose();
}
///
diff --git a/LibGit2Sharp/Core/GitDiff.cs b/LibGit2Sharp/Core/GitDiff.cs
index 4ef6a251f..7581bcfbc 100644
--- a/LibGit2Sharp/Core/GitDiff.cs
+++ b/LibGit2Sharp/Core/GitDiff.cs
@@ -189,7 +189,7 @@ internal class GitDiffOptions : IDisposable
/* options controlling which files are in the diff */
public SubmoduleIgnore IgnoreSubmodules;
- public GitStrArrayIn PathSpec;
+ public GitStrArrayManaged PathSpec;
public diff_notify_cb NotifyCallback;
public IntPtr NotifyPayload;
@@ -204,11 +204,6 @@ internal class GitDiffOptions : IDisposable
public void Dispose()
{
- if (PathSpec == null)
- {
- return;
- }
-
PathSpec.Dispose();
}
}
diff --git a/LibGit2Sharp/Core/GitStatusOptions.cs b/LibGit2Sharp/Core/GitStatusOptions.cs
index ce8504109..af753a437 100644
--- a/LibGit2Sharp/Core/GitStatusOptions.cs
+++ b/LibGit2Sharp/Core/GitStatusOptions.cs
@@ -14,15 +14,10 @@ internal class GitStatusOptions : IDisposable
public GitStatusShow Show;
public GitStatusOptionFlags Flags;
- GitStrArrayIn PathSpec;
+ GitStrArrayManaged PathSpec;
public void Dispose()
{
- if (PathSpec == null)
- {
- return;
- }
-
PathSpec.Dispose();
}
}
diff --git a/LibGit2Sharp/Core/GitStrArray.cs b/LibGit2Sharp/Core/GitStrArray.cs
new file mode 100644
index 000000000..a94187e1b
--- /dev/null
+++ b/LibGit2Sharp/Core/GitStrArray.cs
@@ -0,0 +1,30 @@
+using System;
+using System.Collections.Generic;
+using System.Runtime.InteropServices;
+using System.Text;
+
+namespace LibGit2Sharp.Core
+{
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct GitStrArray
+ {
+ ///
+ /// A pointer to an array of null-terminated strings.
+ ///
+ public IntPtr Strings;
+
+ ///
+ /// The number of strings in the array.
+ ///
+ public UIntPtr Count;
+
+ ///
+ /// Resets the GitStrArray to default values.
+ ///
+ public void Reset()
+ {
+ Strings = IntPtr.Zero;
+ Count = UIntPtr.Zero;
+ }
+ }
+}
diff --git a/LibGit2Sharp/Core/GitStrArrayIn.cs b/LibGit2Sharp/Core/GitStrArrayIn.cs
deleted file mode 100644
index 9abfcf3f9..000000000
--- a/LibGit2Sharp/Core/GitStrArrayIn.cs
+++ /dev/null
@@ -1,62 +0,0 @@
-using System;
-using System.Runtime.InteropServices;
-
-namespace LibGit2Sharp.Core
-{
- [StructLayout(LayoutKind.Sequential)]
- internal class GitStrArrayIn : IDisposable
- {
- public IntPtr strings;
- public uint size;
-
- public static GitStrArrayIn BuildFrom(string[] strings)
- {
- return BuildFrom(strings, StrictUtf8Marshaler.FromManaged);
- }
-
- public static GitStrArrayIn BuildFrom(FilePath[] paths)
- {
- return BuildFrom(paths, StrictFilePathMarshaler.FromManaged);
- }
-
- private static GitStrArrayIn BuildFrom(T[] input, Func marshaler)
- {
- var count = input.Length;
- var pointers = new IntPtr[count];
-
- for (int i = 0; i < count; i++)
- {
- var item = input[i];
- pointers[i] = marshaler(item);
- }
-
- int dim = IntPtr.Size * count;
-
- IntPtr arrayPtr = Marshal.AllocHGlobal(dim);
- Marshal.Copy(pointers, 0, arrayPtr, count);
-
- return new GitStrArrayIn { strings = arrayPtr, size = (uint)count };
- }
-
- public void Dispose()
- {
- if (size == 0)
- {
- return;
- }
-
- var count = (int)size;
-
- var pointers = new IntPtr[count];
- Marshal.Copy(strings, pointers, 0, count);
-
- for (int i = 0; i < count; i++)
- {
- EncodingMarshaler.Cleanup(pointers[i]);
- }
-
- Marshal.FreeHGlobal(strings);
- size = 0;
- }
- }
-}
diff --git a/LibGit2Sharp/Core/GitStrArrayManaged.cs b/LibGit2Sharp/Core/GitStrArrayManaged.cs
new file mode 100644
index 000000000..320221fcf
--- /dev/null
+++ b/LibGit2Sharp/Core/GitStrArrayManaged.cs
@@ -0,0 +1,62 @@
+using System;
+using System.Runtime.InteropServices;
+
+namespace LibGit2Sharp.Core
+{
+ ///
+ /// A git_strarray where the string array and strings themselves were allocated
+ /// with LibGit2Sharp's allocator (Marshal.AllocHGlobal).
+ ///
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct GitStrArrayManaged : IDisposable
+ {
+ public GitStrArray Array;
+
+ public static GitStrArrayManaged BuildFrom(string[] strings)
+ {
+ return BuildFrom(strings, StrictUtf8Marshaler.FromManaged);
+ }
+
+ public static GitStrArrayManaged BuildFrom(FilePath[] paths)
+ {
+ return BuildFrom(paths, StrictFilePathMarshaler.FromManaged);
+ }
+
+ private static GitStrArrayManaged BuildFrom(T[] input, Func marshaler)
+ {
+ var pointers = new IntPtr[input.Length];
+
+ for (int i = 0; i < input.Length; i++)
+ {
+ var item = input[i];
+ pointers[i] = marshaler(item);
+ }
+
+ var toReturn = new GitStrArrayManaged();
+
+ toReturn.Array.Strings = Marshal.AllocHGlobal(checked(IntPtr.Size * input.Length));
+ Marshal.Copy(pointers, 0, toReturn.Array.Strings, input.Length);
+ toReturn.Array.Count = new UIntPtr((uint)input.Length);
+
+ return toReturn;
+ }
+
+ public void Dispose()
+ {
+ var count = checked((int)Array.Count.ToUInt32());
+
+ for (int i = 0; i < count; i++)
+ {
+ EncodingMarshaler.Cleanup(Marshal.ReadIntPtr(Array.Strings, i * IntPtr.Size));
+ }
+
+ if (Array.Strings != IntPtr.Zero)
+ {
+ Marshal.FreeHGlobal(Array.Strings);
+ }
+
+ // Now that we've freed the memory, zero out the structure.
+ Array.Reset();
+ }
+ }
+}
diff --git a/LibGit2Sharp/Core/GitStrArrayNative.cs b/LibGit2Sharp/Core/GitStrArrayNative.cs
new file mode 100644
index 000000000..2db550c0f
--- /dev/null
+++ b/LibGit2Sharp/Core/GitStrArrayNative.cs
@@ -0,0 +1,44 @@
+using System;
+using System.Collections.Generic;
+using System.Runtime.InteropServices;
+
+namespace LibGit2Sharp.Core
+{
+ ///
+ /// A git_strarray where the string array and strings themselves were allocated
+ /// with libgit2's allocator. Only libgit2 can free this git_strarray.
+ ///
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct GitStrArrayNative : IDisposable
+ {
+ public GitStrArray Array;
+
+ ///
+ /// Enumerates each string from the array using the UTF-8 marshaler.
+ ///
+ public String[] ReadStrings()
+ {
+ var count = checked((int)Array.Count.ToUInt32());
+
+ String[] toReturn = new String[count];
+
+ for (int i = 0; i < count; i++)
+ {
+ toReturn[i] = LaxUtf8Marshaler.FromNative(Marshal.ReadIntPtr(Array.Strings, i * IntPtr.Size));
+ }
+
+ return toReturn;
+ }
+
+ public void Dispose()
+ {
+ if (Array.Strings != IntPtr.Zero)
+ {
+ NativeMethods.git_strarray_free(ref Array);
+ }
+
+ // Now that we've freed the memory, zero out the structure.
+ Array.Reset();
+ }
+ }
+}
diff --git a/LibGit2Sharp/Core/GitStrArrayOut.cs b/LibGit2Sharp/Core/GitStrArrayOut.cs
deleted file mode 100644
index 0bc2f6765..000000000
--- a/LibGit2Sharp/Core/GitStrArrayOut.cs
+++ /dev/null
@@ -1,47 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Runtime.InteropServices;
-
-namespace LibGit2Sharp.Core
-{
- [StructLayout(LayoutKind.Sequential)]
- internal class GitStrArrayOut : IDisposable
- {
- public IntPtr strings;
- public uint size;
-
- public IEnumerable Build()
- {
- int count = (int)size;
- var pointers = new IntPtr[count];
-
- Marshal.Copy(strings, pointers, 0, count);
-
- for (int i = 0; i < count; i++)
- {
- yield return LaxUtf8Marshaler.FromNative(pointers[i]);
- }
- }
-
- public void Dispose()
- {
- if (size == 0)
- {
- return;
- }
-
- var count = (int)size;
-
- var pointers = new IntPtr[count];
- Marshal.Copy(strings, pointers, 0, count);
-
- for (int i = 0; i < count; i++)
- {
- EncodingMarshaler.Cleanup(pointers[i]);
- }
-
- Marshal.FreeHGlobal(strings);
- size = 0;
- }
- }
-}
diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs
index 52963e344..f6bb9c759 100644
--- a/LibGit2Sharp/Core/NativeMethods.cs
+++ b/LibGit2Sharp/Core/NativeMethods.cs
@@ -214,7 +214,7 @@ internal static extern int git_branch_remote_name(
[DllImport(libgit2)]
internal static extern int git_remote_rename(
- GitStrArrayOut problems,
+ ref GitStrArray problems,
RemoteSafeHandle remote,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string new_name);
@@ -887,6 +887,9 @@ internal static extern int git_reference_foreach_glob(
internal static extern int git_reference_is_valid_name(
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string refname);
+ [DllImport(libgit2)]
+ internal static extern int git_reference_list(out GitStrArray array, RepositorySafeHandle repo);
+
[DllImport(libgit2)]
internal static extern int git_reference_lookup(
out ReferenceSafeHandle reference,
@@ -1048,22 +1051,31 @@ internal static extern int git_remote_fetch(
[DllImport(libgit2)]
internal static extern void git_remote_free(IntPtr remote);
+ [DllImport(libgit2)]
+ internal static extern int git_remote_get_fetch_refspecs(out GitStrArray array, RemoteSafeHandle remote);
+
[DllImport(libgit2)]
internal static extern GitRefSpecHandle git_remote_get_refspec(RemoteSafeHandle remote, UIntPtr n);
+ [DllImport(libgit2)]
+ internal static extern int git_remote_get_push_refspecs(out GitStrArray array, RemoteSafeHandle remote);
+
[DllImport(libgit2)]
internal static extern UIntPtr git_remote_refspec_count(RemoteSafeHandle remote);
[DllImport(libgit2)]
- internal static extern int git_remote_set_fetch_refspecs(RemoteSafeHandle remote, GitStrArrayIn array);
+ internal static extern int git_remote_set_fetch_refspecs(RemoteSafeHandle remote, ref GitStrArray array);
[DllImport(libgit2)]
- internal static extern int git_remote_set_push_refspecs(RemoteSafeHandle remote, GitStrArrayIn array);
+ internal static extern int git_remote_set_push_refspecs(RemoteSafeHandle remote, ref GitStrArray array);
[DllImport(libgit2)]
internal static extern int git_remote_is_valid_name(
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string remote_name);
+ [DllImport(libgit2)]
+ internal static extern int git_remote_list(out GitStrArray array, RepositorySafeHandle repo);
+
[DllImport(libgit2)]
internal static extern int git_remote_load(
out RemoteSafeHandle remote,
@@ -1331,6 +1343,10 @@ internal static extern StatusEntrySafeHandle git_status_byindex(
internal static extern void git_status_list_free(
IntPtr statusList);
+ [DllImport(libgit2)]
+ internal static extern void git_strarray_free(
+ ref GitStrArray array);
+
[DllImport(libgit2)]
internal static extern int git_submodule_lookup(
out SubmoduleSafeHandle reference,
@@ -1439,6 +1455,9 @@ internal static extern int git_tag_delete(
RepositorySafeHandle repo,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string tagName);
+ [DllImport(libgit2)]
+ internal static extern int git_tag_list(out GitStrArray array, RepositorySafeHandle repo);
+
[DllImport(libgit2)]
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(LaxUtf8NoCleanupMarshaler))]
internal static extern string git_tag_message(GitObjectSafeHandle tag);
diff --git a/LibGit2Sharp/Core/Proxy.cs b/LibGit2Sharp/Core/Proxy.cs
index 97f829304..f49ea662a 100644
--- a/LibGit2Sharp/Core/Proxy.cs
+++ b/LibGit2Sharp/Core/Proxy.cs
@@ -1597,11 +1597,19 @@ public static IList git_reference_list(RepositorySafeHandle repo)
{
using (ThreadAffinity())
{
- UnSafeNativeMethods.git_strarray arr;
- int res = UnSafeNativeMethods.git_reference_list(out arr, repo);
- Ensure.ZeroResult(res);
+ var array = new GitStrArrayNative();
- return Libgit2UnsafeHelper.BuildListOf(arr);
+ try
+ {
+ int res = NativeMethods.git_reference_list(out array.Array, repo);
+ Ensure.ZeroResult(res);
+
+ return array.ReadStrings();
+ }
+ finally
+ {
+ array.Dispose();
+ }
}
}
@@ -1891,11 +1899,19 @@ public static IList git_remote_get_fetch_refspecs(RemoteSafeHandle remot
{
using (ThreadAffinity())
{
- UnSafeNativeMethods.git_strarray arr;
- int res = UnSafeNativeMethods.git_remote_get_fetch_refspecs(out arr, remote);
- Ensure.ZeroResult(res);
+ var array = new GitStrArrayNative();
- return Libgit2UnsafeHelper.BuildListOf(arr);
+ try
+ {
+ int res = NativeMethods.git_remote_get_fetch_refspecs(out array.Array, remote);
+ Ensure.ZeroResult(res);
+
+ return array.ReadStrings();
+ }
+ finally
+ {
+ array.Dispose();
+ }
}
}
@@ -1903,31 +1919,59 @@ public static IList git_remote_get_push_refspecs(RemoteSafeHandle remote
{
using (ThreadAffinity())
{
- UnSafeNativeMethods.git_strarray arr;
- int res = UnSafeNativeMethods.git_remote_get_push_refspecs(out arr, remote);
- Ensure.ZeroResult(res);
+ var array = new GitStrArrayNative();
- return Libgit2UnsafeHelper.BuildListOf(arr);
+ try
+ {
+ int res = NativeMethods.git_remote_get_push_refspecs(out array.Array, remote);
+ Ensure.ZeroResult(res);
+
+ return array.ReadStrings();
+ }
+ finally
+ {
+ array.Dispose();
+ }
}
}
public static void git_remote_set_fetch_refspecs(RemoteSafeHandle remote, IEnumerable refSpecs)
{
using (ThreadAffinity())
- using (GitStrArrayIn array = GitStrArrayIn.BuildFrom(refSpecs.ToArray()))
{
- int res = NativeMethods.git_remote_set_fetch_refspecs(remote, array);
- Ensure.ZeroResult(res);
+ var array = new GitStrArrayManaged();
+
+ try
+ {
+ array = GitStrArrayManaged.BuildFrom(refSpecs.ToArray());
+
+ int res = NativeMethods.git_remote_set_fetch_refspecs(remote, ref array.Array);
+ Ensure.ZeroResult(res);
+ }
+ finally
+ {
+ array.Dispose();
+ }
}
}
public static void git_remote_set_push_refspecs(RemoteSafeHandle remote, IEnumerable refSpecs)
{
using (ThreadAffinity())
- using (GitStrArrayIn array = GitStrArrayIn.BuildFrom(refSpecs.ToArray()))
{
- int res = NativeMethods.git_remote_set_push_refspecs(remote, array);
- Ensure.ZeroResult(res);
+ var array = new GitStrArrayManaged();
+
+ try
+ {
+ array = GitStrArrayManaged.BuildFrom(refSpecs.ToArray());
+
+ int res = NativeMethods.git_remote_set_push_refspecs(remote, ref array.Array);
+ Ensure.ZeroResult(res);
+ }
+ finally
+ {
+ array.Dispose();
+ }
}
}
@@ -1958,30 +2002,47 @@ public static IList git_remote_list(RepositorySafeHandle repo)
{
using (ThreadAffinity())
{
- UnSafeNativeMethods.git_strarray arr;
- int res = UnSafeNativeMethods.git_remote_list(out arr, repo);
- Ensure.ZeroResult(res);
+ var array = new GitStrArrayNative();
+
+ try
+ {
+ int res = NativeMethods.git_remote_list(out array.Array, repo);
+ Ensure.ZeroResult(res);
- return Libgit2UnsafeHelper.BuildListOf(arr);
+ return array.ReadStrings();
+ }
+ finally
+ {
+ array.Dispose();
+ }
}
}
public static IEnumerable git_remote_ls(Repository repository, RemoteSafeHandle remote)
{
- var refs = new List();
IntPtr heads;
- UIntPtr size;
+ UIntPtr count;
using (ThreadAffinity())
{
- int res = NativeMethods.git_remote_ls(out heads, out size, remote);
+ int res = NativeMethods.git_remote_ls(out heads, out count, remote);
Ensure.ZeroResult(res);
}
- var grheads = Libgit2UnsafeHelper.RemoteLsHelper(heads, size);
+ var intCount = (int)count.ToUInt32();
+
+ if (intCount < 0)
+ {
+ throw new OverflowException();
+ }
+
+ var refs = new List();
+ IntPtr currentHead = heads;
- foreach (var remoteHead in grheads)
+ for (int i = 0; i < intCount; i++)
{
+ var remoteHead = Marshal.ReadIntPtr(currentHead).MarshalAs();
+
// The name pointer should never be null - if it is,
// this indicates a bug somewhere (libgit2, server, etc).
if (remoteHead.NamePtr == IntPtr.Zero)
@@ -1991,6 +2052,8 @@ public static IEnumerable git_remote_ls(Repository repository,
string name = LaxUtf8Marshaler.FromNative(remoteHead.NamePtr);
refs.Add(new DirectReference(name, repository, remoteHead.Oid));
+
+ currentHead = IntPtr.Add(currentHead, IntPtr.Size);
}
return refs;
@@ -2034,20 +2097,26 @@ public static void git_remote_rename(RepositorySafeHandle repo, string name, str
callback = problem => {};
}
- using (var array = new GitStrArrayOut())
+ var array = new GitStrArrayNative();
+
+ try
{
int res = NativeMethods.git_remote_rename(
- array,
- remote,
- new_name);
+ ref array.Array,
+ remote,
+ new_name);
Ensure.ZeroResult(res);
- foreach (var item in array.Build ())
+ foreach (var item in array.ReadStrings())
{
callback(item);
}
}
+ finally
+ {
+ array.Dispose();
+ }
}
}
}
@@ -2788,11 +2857,19 @@ public static IList git_tag_list(RepositorySafeHandle repo)
{
using (ThreadAffinity())
{
- UnSafeNativeMethods.git_strarray arr;
- int res = UnSafeNativeMethods.git_tag_list(out arr, repo);
- Ensure.ZeroResult(res);
+ var array = new GitStrArrayNative();
- return Libgit2UnsafeHelper.BuildListOf(arr);
+ try
+ {
+ int res = NativeMethods.git_tag_list(out array.Array, repo);
+ Ensure.ZeroResult(res);
+
+ return array.ReadStrings();
+ }
+ finally
+ {
+ array.Dispose();
+ }
}
}
@@ -3095,45 +3172,6 @@ Func resultSelector
}
}
- private static unsafe class Libgit2UnsafeHelper
- {
- public static IList BuildListOf(UnSafeNativeMethods.git_strarray strArray)
- {
-
- try
- {
- UnSafeNativeMethods.git_strarray* gitStrArray = &strArray;
-
- var numberOfEntries = (int)gitStrArray->size;
- var list = new List(numberOfEntries);
- for (uint i = 0; i < numberOfEntries; i++)
- {
- var name = LaxUtf8Marshaler.FromNative((IntPtr)gitStrArray->strings[i]);
- list.Add(name);
- }
-
- return list;
- }
- finally
- {
- UnSafeNativeMethods.git_strarray_free(ref strArray);
- }
- }
-
- public static IList RemoteLsHelper(IntPtr heads, UIntPtr size)
- {
- var rawHeads = (IntPtr*) heads;
- var count = (int) size;
-
- var list = new List(count);
- for (int i = 0; i < count; i++)
- {
- list.Add(rawHeads[i].MarshalAs());
- }
- return list;
- }
- }
-
private static bool RepositoryStateChecker(RepositorySafeHandle repo, Func checker)
{
using (ThreadAffinity())
diff --git a/LibGit2Sharp/Core/UnSafeNativeMethods.cs b/LibGit2Sharp/Core/UnSafeNativeMethods.cs
deleted file mode 100644
index be17f4397..000000000
--- a/LibGit2Sharp/Core/UnSafeNativeMethods.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-using System;
-using System.Runtime.InteropServices;
-using LibGit2Sharp.Core.Handles;
-
-namespace LibGit2Sharp.Core
-{
- internal static unsafe class UnSafeNativeMethods
- {
- private const string libgit2 = NativeDllName.Name;
-
- [DllImport(libgit2)]
- internal static extern int git_reference_list(out git_strarray array, RepositorySafeHandle repo);
-
- [DllImport(libgit2)]
- internal static extern int git_remote_list(out git_strarray array, RepositorySafeHandle repo);
-
- [DllImport(libgit2)]
- internal static extern int git_tag_list(out git_strarray array, RepositorySafeHandle repo);
-
- [DllImport(libgit2)]
- internal static extern void git_strarray_free(ref git_strarray array);
-
- [DllImport(libgit2)]
- internal static extern int git_remote_get_fetch_refspecs(out git_strarray array, RemoteSafeHandle remote);
-
- [DllImport(libgit2)]
- internal static extern int git_remote_get_push_refspecs(out git_strarray array, RemoteSafeHandle remote);
-
- #region Nested type: git_strarray
-
- internal struct git_strarray
- {
- public sbyte** strings;
- public UIntPtr size;
- }
-
- #endregion
- }
-}
diff --git a/LibGit2Sharp/Diff.cs b/LibGit2Sharp/Diff.cs
index 6f0191e78..a1e87e3b3 100644
--- a/LibGit2Sharp/Diff.cs
+++ b/LibGit2Sharp/Diff.cs
@@ -60,12 +60,11 @@ private static GitDiffOptions BuildOptions(DiffModifiers diffOptions, FilePath[]
options.NotifyCallback = matchedPathsAggregator.OnGitDiffNotify;
}
- if (filePaths == null)
+ if (filePaths != null)
{
- return options;
+ options.PathSpec = GitStrArrayManaged.BuildFrom(filePaths);
}
- options.PathSpec = GitStrArrayIn.BuildFrom(filePaths);
return options;
}
diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj
index 9a033be72..8ed8c54c1 100644
--- a/LibGit2Sharp/LibGit2Sharp.csproj
+++ b/LibGit2Sharp/LibGit2Sharp.csproj
@@ -138,7 +138,9 @@
-
+
+
+
@@ -277,7 +279,6 @@
Code
-
@@ -326,7 +327,6 @@
-