Skip to content

Commit

Permalink
Expose remote handles to internal callers
Browse files Browse the repository at this point in the history
  • Loading branch information
nulltoken committed Feb 6, 2012
1 parent 62b8e4c commit 8abb530
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions LibGit2Sharp/RemoteCollection.cs
@@ -1,4 +1,5 @@
using LibGit2Sharp.Core;
using System;
using LibGit2Sharp.Core;

namespace LibGit2Sharp
{
Expand All @@ -16,23 +17,35 @@ internal RemoteCollection(Repository repository)
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);
Expand Down

0 comments on commit 8abb530

Please sign in to comment.