diff --git a/LibGit2Sharp/RefSpecCollection.cs b/LibGit2Sharp/RefSpecCollection.cs index 06bef5316..81d4b70c8 100644 --- a/LibGit2Sharp/RefSpecCollection.cs +++ b/LibGit2Sharp/RefSpecCollection.cs @@ -16,7 +16,7 @@ namespace LibGit2Sharp [DebuggerDisplay("{DebuggerDisplay,nq}")] public class RefSpecCollection : IEnumerable { - private readonly Lazy> refSpecsLazy; + readonly IList refspecs; /// /// Needed for mocking purposes. @@ -24,30 +24,28 @@ public class RefSpecCollection : IEnumerable protected RefSpecCollection() { } - internal RefSpecCollection(Remote remote) + internal RefSpecCollection(RemoteSafeHandle handle) { - Ensure.ArgumentNotNull(remote, "remote"); + Ensure.ArgumentNotNull(handle, "handle"); - refSpecsLazy = new Lazy>(() => RetrieveRefSpecs(remote)); + refspecs = RetrieveRefSpecs(handle); } - private static IList RetrieveRefSpecs(Remote remote) + static IList RetrieveRefSpecs(RemoteSafeHandle remoteHandle) { - using (RemoteSafeHandle remoteHandle = Proxy.git_remote_load(remote.repository.Handle, remote.Name, true)) - { - int count = Proxy.git_remote_refspec_count(remoteHandle); - List refSpecs = new List(); + int count = Proxy.git_remote_refspec_count(remoteHandle); + List refSpecs = new List(); - for (int i = 0; i < count; i++) + for (int i = 0; i < count; i++) + { + using (GitRefSpecHandle handle = Proxy.git_remote_get_refspec(remoteHandle, i)) { - using (GitRefSpecHandle handle = Proxy.git_remote_get_refspec(remoteHandle, i)) - { - refSpecs.Add(RefSpec.BuildFromPtr(handle)); - } + refSpecs.Add(RefSpec.BuildFromPtr(handle)); } - - return refSpecs; } + + return refSpecs; + } /// @@ -56,7 +54,7 @@ private static IList RetrieveRefSpecs(Remote remote) /// An object that can be used to iterate through the collection. public virtual IEnumerator GetEnumerator() { - return refSpecsLazy.Value.GetEnumerator(); + return refspecs.GetEnumerator(); } /// diff --git a/LibGit2Sharp/Remote.cs b/LibGit2Sharp/Remote.cs index ccf3d98d7..4524e77aa 100644 --- a/LibGit2Sharp/Remote.cs +++ b/LibGit2Sharp/Remote.cs @@ -27,22 +27,18 @@ public class Remote : IEquatable protected Remote() { } - private Remote(Repository repository, string name, string url, TagFetchMode tagFetchMode) + private Remote(RemoteSafeHandle handle, Repository repository) { this.repository = repository; - Name = name; - Url = url; - TagFetchMode = tagFetchMode; - refSpecs = new RefSpecCollection(this); + Name = Proxy.git_remote_name(handle); + Url = Proxy.git_remote_url(handle); + TagFetchMode = Proxy.git_remote_autotag(handle); + refSpecs = new RefSpecCollection(handle); } internal static Remote BuildFromPtr(RemoteSafeHandle handle, Repository repo) { - string name = Proxy.git_remote_name(handle); - string url = Proxy.git_remote_url(handle); - TagFetchMode tagFetchMode = Proxy.git_remote_autotag(handle); - - var remote = new Remote(repo, name, url, tagFetchMode); + var remote = new Remote(handle, repo); return remote; }