diff options
author | nulltoken <emeric.fermas@gmail.com> | 2012-01-24 01:57:10 +0400 |
---|---|---|
committer | nulltoken <emeric.fermas@gmail.com> | 2012-02-07 00:51:39 +0400 |
commit | 8abb5303b8e6d8043797e30d918a02b9a962b8a5 (patch) | |
tree | cd12634282af8296a93cb6d34b0d910157ec02ce /LibGit2Sharp | |
parent | 62b8e4c0b8c15b6c17f37c2971d0a12e060c59be (diff) |
Expose remote handles to internal callers
Diffstat (limited to 'LibGit2Sharp')
-rw-r--r-- | LibGit2Sharp/RemoteCollection.cs | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/LibGit2Sharp/RemoteCollection.cs b/LibGit2Sharp/RemoteCollection.cs index dcb582b8..bbc4e71b 100644 --- a/LibGit2Sharp/RemoteCollection.cs +++ b/LibGit2Sharp/RemoteCollection.cs @@ -1,4 +1,5 @@ -using LibGit2Sharp.Core; +using System; +using LibGit2Sharp.Core; namespace LibGit2Sharp { @@ -16,23 +17,35 @@ namespace LibGit2Sharp get { return RemoteForName(name); } } - private Remote RemoteForName(string name) + internal RemoteSafeHandle LoadRemote(string name, bool throwsIfNotFound) { - var remote = new Remote(); RemoteSafeHandle handle; int res = NativeMethods.git_remote_load(out handle, repository.Handle, name); - if (res == (int)GitErrorCode.GIT_ENOTFOUND) + if (res == (int)GitErrorCode.GIT_ENOTFOUND && !throwsIfNotFound) { return null; } Ensure.Success(res); + return handle; + } + + private Remote RemoteForName(string name) + { + RemoteSafeHandle handle = LoadRemote(name, false); + + if (handle == null) + { + return null; + } + + var remote = new Remote(); using (handle) { - var ptr = NativeMethods.git_remote_name(handle); + IntPtr ptr = NativeMethods.git_remote_name(handle); remote.Name = ptr.MarshallAsString(); ptr = NativeMethods.git_remote_url(handle); |