Skip to content

Commit 81952ab

Browse files
committed
Make TagFetchMode.Auto the explicit default
1 parent 4b7412b commit 81952ab

File tree

2 files changed

+15
-20
lines changed

2 files changed

+15
-20
lines changed

LibGit2Sharp/Remote.cs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ internal static Remote BuildFromPtr(RemoteSafeHandle handle, Repository repo)
5757
/// <param name="onCompletion">Completion callback. Corresponds to libgit2 completion callback.</param>
5858
/// <param name="onUpdateTips">UpdateTips callback. Corresponds to libgit2 update_tips callback.</param>
5959
public virtual void Fetch(FetchProgress progress = null,
60-
TagFetchMode? tagFetchMode = null,
60+
TagFetchMode tagFetchMode = TagFetchMode.Auto,
6161
ProgressHandler onProgress = null,
6262
CompletionHandler onCompletion = null,
6363
UpdateTipsHandler onUpdateTips = null)
@@ -67,28 +67,23 @@ public virtual void Fetch(FetchProgress progress = null,
6767

6868
using (RemoteSafeHandle remoteHandle = Proxy.git_remote_load(repository.Handle, this.Name, true))
6969
{
70-
RemoteCallbacks callbacks = new RemoteCallbacks(onProgress, onCompletion, onUpdateTips);
70+
var callbacks = new RemoteCallbacks(onProgress, onCompletion, onUpdateTips);
7171
GitRemoteCallbacks gitCallbacks = callbacks.GenerateCallbacks();
7272

73+
Proxy.git_remote_set_autotag(remoteHandle, tagFetchMode);
74+
75+
// It is OK to pass the reference to the GitCallbacks directly here because libgit2 makes a copy of
76+
// the data in the git_remote_callbacks structure. If, in the future, libgit2 changes its implementation
77+
// to store a reference to the git_remote_callbacks structure this would introduce a subtle bug
78+
// where the managed layer could move the git_remote_callbacks to a different location in memory,
79+
// but libgit2 would still reference the old address.
80+
//
81+
// Also, if GitRemoteCallbacks were a class instead of a struct, we would need to guard against
82+
// GC occuring in between setting the remote callbacks and actual usage in one of the functions afterwords.
83+
Proxy.git_remote_set_callbacks(remoteHandle, ref gitCallbacks);
84+
7385
try
7486
{
75-
// If a TagFetchMode value has been specified, pass it on to
76-
// to the libgit2 layer
77-
if (tagFetchMode.HasValue)
78-
{
79-
Proxy.git_remote_set_autotag(remoteHandle, tagFetchMode.Value);
80-
}
81-
82-
// It is OK to pass the reference to the GitCallbacks directly here because libgit2 makes a copy of
83-
// the data in the git_remote_callbacks structure. If, in the future, libgit2 changes its implementation
84-
// to store a reference to the git_remote_callbacks structure this would introduce a subtle bug
85-
// where the managed layer could move the git_remote_callbacks to a different location in memory,
86-
// but libgit2 would still reference the old address.
87-
//
88-
// Also, if GitRemoteCallbacks were a class instead of a struct, we would need to guard against
89-
// GC occuring in between setting the remote callbacks and actual usage in one of the functions afterwords.
90-
Proxy.git_remote_set_callbacks(remoteHandle, ref gitCallbacks);
91-
9287
Proxy.git_remote_connect(remoteHandle, GitDirection.Fetch);
9388

9489
Proxy.git_remote_download(remoteHandle, ref progress.bytes, ref progress.IndexerStats.gitIndexerStats);

LibGit2Sharp/RepositoryExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public static Commit Commit(this IRepository repository, string message, Signatu
157157
/// <param name="onCompletion"></param>
158158
/// <param name="onUpdateTips"></param>
159159
public static void Fetch(this IRepository repository, string remoteName, FetchProgress progress = null,
160-
TagFetchMode? tagFetchMode = null,
160+
TagFetchMode tagFetchMode = TagFetchMode.Auto,
161161
ProgressHandler onProgress = null,
162162
CompletionHandler onCompletion = null,
163163
UpdateTipsHandler onUpdateTips = null)

0 commit comments

Comments
 (0)