Skip to content

Commit

Permalink
Expose enable/disable cache setting
Browse files Browse the repository at this point in the history
  • Loading branch information
mitesch committed Aug 17, 2016
1 parent f12a329 commit 9cf43a3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions LibGit2Sharp/Core/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,10 @@ static NativeMethods()
internal static extern int git_libgit2_opts(int option, uint level,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))]string path);

// git_libgit2_opts(GIT_OPT_ENABLE_CACHING, uint enabled)
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
internal static extern int git_libgit2_opts(int option, uint enabled);

#endregion

[DllImport(libgit2)]
Expand Down
11 changes: 11 additions & 0 deletions LibGit2Sharp/Core/Proxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3403,6 +3403,17 @@ public static void git_libgit2_opts_set_search_path(ConfigurationLevel level, st
Ensure.ZeroResult(res);
}

/// <summary>
/// Enable or disable the libgit2 cache
/// </summary>
/// <param name="enabled">true to enable the cache, false otherwise</param>
public static void git_libgit2_opts_set_enable_caching(bool enabled)
{
// libgit2 expects non-zero value for true
var res = NativeMethods.git_libgit2_opts((int)LibGitOption.EnableCaching, (uint)(enabled ? 1 : 0));
Ensure.ZeroResult(res);
}

#endregion

private static ICollection<TResult> git_foreach<T, TResult>(
Expand Down
9 changes: 9 additions & 0 deletions LibGit2Sharp/GlobalSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,5 +299,14 @@ public static void SetConfigSearchPaths(ConfigurationLevel level, params string[
var pathString = (paths == null) ? null : string.Join(Path.PathSeparator.ToString(), paths);
Proxy.git_libgit2_opts_set_search_path(level, pathString);
}

/// <summary>
/// Enable or disable the libgit2 cache
/// </summary>
/// <param name="enabled">true to enable the cache, false otherwise</param>
public static void SetEnableCaching(bool enabled)
{
Proxy.git_libgit2_opts_set_enable_caching(enabled);
}
}
}

0 comments on commit 9cf43a3

Please sign in to comment.