Skip to content

Commit 9cf43a3

Browse files
committed
Expose enable/disable cache setting
1 parent f12a329 commit 9cf43a3

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,10 @@ internal static extern int git_filter_unregister(
636636
internal static extern int git_libgit2_opts(int option, uint level,
637637
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))]string path);
638638

639+
// git_libgit2_opts(GIT_OPT_ENABLE_CACHING, uint enabled)
640+
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
641+
internal static extern int git_libgit2_opts(int option, uint enabled);
642+
639643
#endregion
640644

641645
[DllImport(libgit2)]

LibGit2Sharp/Core/Proxy.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3403,6 +3403,17 @@ public static void git_libgit2_opts_set_search_path(ConfigurationLevel level, st
34033403
Ensure.ZeroResult(res);
34043404
}
34053405

3406+
/// <summary>
3407+
/// Enable or disable the libgit2 cache
3408+
/// </summary>
3409+
/// <param name="enabled">true to enable the cache, false otherwise</param>
3410+
public static void git_libgit2_opts_set_enable_caching(bool enabled)
3411+
{
3412+
// libgit2 expects non-zero value for true
3413+
var res = NativeMethods.git_libgit2_opts((int)LibGitOption.EnableCaching, (uint)(enabled ? 1 : 0));
3414+
Ensure.ZeroResult(res);
3415+
}
3416+
34063417
#endregion
34073418

34083419
private static ICollection<TResult> git_foreach<T, TResult>(

LibGit2Sharp/GlobalSettings.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,5 +299,14 @@ public static void SetConfigSearchPaths(ConfigurationLevel level, params string[
299299
var pathString = (paths == null) ? null : string.Join(Path.PathSeparator.ToString(), paths);
300300
Proxy.git_libgit2_opts_set_search_path(level, pathString);
301301
}
302+
303+
/// <summary>
304+
/// Enable or disable the libgit2 cache
305+
/// </summary>
306+
/// <param name="enabled">true to enable the cache, false otherwise</param>
307+
public static void SetEnableCaching(bool enabled)
308+
{
309+
Proxy.git_libgit2_opts_set_enable_caching(enabled);
310+
}
302311
}
303312
}

0 commit comments

Comments
 (0)