diff options
author | nulltoken <emeric.fermas@gmail.com> | 2012-02-27 20:14:57 +0400 |
---|---|---|
committer | nulltoken <emeric.fermas@gmail.com> | 2012-02-27 23:30:44 +0400 |
commit | 35d14259b990651727ff9de2ec338315a790badd (patch) | |
tree | 3cf89ae6bb2a3c3fa5218e340495c49b404a6d17 /LibGit2Sharp | |
parent | e27e18a83a8c422e5fa80fe679aa77948c1f5f63 (diff) |
Remove some code duplication
Diffstat (limited to 'LibGit2Sharp')
-rw-r--r-- | LibGit2Sharp/Core/NativeMethods.cs | 11 | ||||
-rw-r--r-- | LibGit2Sharp/Repository.cs | 2 | ||||
-rw-r--r-- | LibGit2Sharp/RepositoryInformation.cs | 19 |
3 files changed, 14 insertions, 18 deletions
diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs index 917ee9a1..a2328587 100644 --- a/LibGit2Sharp/Core/NativeMethods.cs +++ b/LibGit2Sharp/Core/NativeMethods.cs @@ -42,6 +42,14 @@ namespace LibGit2Sharp.Core return (p == 4) || (p == 6) || (p == 128); } + public static bool RepositoryStateChecker(RepositorySafeHandle repositoryPtr, Func<RepositorySafeHandle, int> checker) + { + int res = checker(repositoryPtr); + Ensure.Success(res, true); + + return (res == 1); + } + [DllImport(libgit2)] public static extern IntPtr git_blob_rawcontent(IntPtr blob); @@ -319,8 +327,7 @@ namespace LibGit2Sharp.Core [MarshalAs(UnmanagedType.Bool)] bool isBare); [DllImport(libgit2)] - [return: MarshalAs(UnmanagedType.Bool)] - public static extern bool git_repository_is_bare(RepositorySafeHandle handle); + public static extern int git_repository_is_bare(RepositorySafeHandle handle); [DllImport(libgit2)] public static extern int git_repository_is_empty(RepositorySafeHandle repo); diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs index 92f5b240..e0e01342 100644 --- a/LibGit2Sharp/Repository.cs +++ b/LibGit2Sharp/Repository.cs @@ -35,7 +35,7 @@ namespace LibGit2Sharp int res = NativeMethods.git_repository_open(out handle, PosixPathHelper.ToPosix(path)); Ensure.Success(res); - isBare = NativeMethods.git_repository_is_bare(handle); + isBare = NativeMethods.RepositoryStateChecker(handle, NativeMethods.git_repository_is_bare); if (!isBare) { diff --git a/LibGit2Sharp/RepositoryInformation.cs b/LibGit2Sharp/RepositoryInformation.cs index 9453c754..52c630cf 100644 --- a/LibGit2Sharp/RepositoryInformation.cs +++ b/LibGit2Sharp/RepositoryInformation.cs @@ -1,4 +1,5 @@ -using LibGit2Sharp.Core; +using System; +using LibGit2Sharp.Core; namespace LibGit2Sharp { @@ -47,13 +48,7 @@ namespace LibGit2Sharp /// </value> public bool IsEmpty { - get - { - int res = NativeMethods.git_repository_is_empty(repo.Handle); - Ensure.Success(res, true); - - return (res == 1); - } + get { return NativeMethods.RepositoryStateChecker(repo.Handle, NativeMethods.git_repository_is_empty); } } /// <summary> @@ -61,13 +56,7 @@ namespace LibGit2Sharp /// </summary> public bool IsHeadDetached { - get - { - int res = NativeMethods.git_repository_head_detached(repo.Handle); - Ensure.Success(res, true); - - return (res == 1); - } + get { return NativeMethods.RepositoryStateChecker(repo.Handle, NativeMethods.git_repository_head_detached); } } } } |