Skip to content

Commit 1bd0905

Browse files
committed
Eagerly dispose of Remotes
This is a continuation of #1249. Since Remotes are now disposable we should eagerly clean up their resources rather than wait for GC to call the destructor.
1 parent 45846e2 commit 1bd0905

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

LibGit2Sharp/BranchUpdater.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ private void SetUpstreamRemote(string remoteName)
154154
if (!remoteName.Equals(".", StringComparison.Ordinal))
155155
{
156156
// Verify that remote exists.
157-
repo.Network.Remotes.RemoteForName(remoteName);
157+
using (repo.Network.Remotes.RemoteForName(remoteName)) { }
158158
}
159159

160160
repo.Config.Set(configKey, remoteName);
@@ -183,8 +183,10 @@ private void GetUpstreamInformation(string canonicalName, out string remoteName,
183183
{
184184
remoteName = Proxy.git_branch_remote_name(repo.Handle, canonicalName, true);
185185

186-
Remote remote = repo.Network.Remotes.RemoteForName(remoteName);
187-
mergeBranchName = remote.FetchSpecTransformToSource(canonicalName);
186+
using (Remote remote = repo.Network.Remotes.RemoteForName(remoteName))
187+
{
188+
mergeBranchName = remote.FetchSpecTransformToSource(canonicalName);
189+
}
188190
}
189191
else
190192
{

LibGit2Sharp/RepositoryExtensions.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,10 @@ public static void Fetch(this IRepository repository, string remoteName, FetchOp
221221
Ensure.ArgumentNotNull(repository, "repository");
222222
Ensure.ArgumentNotNullOrEmptyString(remoteName, "remoteName");
223223

224-
Remote remote = repository.Network.Remotes.RemoteForName(remoteName, true);
225-
repository.Network.Fetch(remote, options);
224+
using (Remote remote = repository.Network.Remotes.RemoteForName(remoteName, true))
225+
{
226+
repository.Network.Fetch(remote, options);
227+
}
226228
}
227229

228230
/// <summary>

0 commit comments

Comments
 (0)