@@ -96,13 +96,21 @@ public virtual IEnumerable<DirectReference> ListReferences(string url)
9696 }
9797 }
9898
99- static void DoFetch ( RemoteSafeHandle remoteHandle , GitRemoteCallbacks gitCallbacks , TagFetchMode ? tagFetchMode )
99+ static void DoFetch ( RemoteSafeHandle remoteHandle , FetchOptions options )
100100 {
101- if ( tagFetchMode . HasValue )
101+ if ( options == null )
102102 {
103- Proxy . git_remote_set_autotag ( remoteHandle , tagFetchMode . Value ) ;
103+ options = new FetchOptions ( ) ;
104104 }
105105
106+ if ( options . TagFetchMode . HasValue )
107+ {
108+ Proxy . git_remote_set_autotag ( remoteHandle , options . TagFetchMode . Value ) ;
109+ }
110+
111+ var callbacks = new RemoteCallbacks ( options ) ;
112+ GitRemoteCallbacks gitCallbacks = callbacks . GenerateCallbacks ( ) ;
113+
106114 // It is OK to pass the reference to the GitCallbacks directly here because libgit2 makes a copy of
107115 // the data in the git_remote_callbacks structure. If, in the future, libgit2 changes its implementation
108116 // to store a reference to the git_remote_callbacks structure this would introduce a subtle bug
@@ -135,22 +143,48 @@ static void DoFetch(RemoteSafeHandle remoteHandle, GitRemoteCallbacks gitCallbac
135143 /// <param name="onTransferProgress">Callback method that transfer progress will be reported through.
136144 /// Reports the client's state regarding the received and processed (bytes, objects) from the server.</param>
137145 /// <param name="credentials">Credentials to use for username/password authentication.</param>
146+ [ Obsolete ( "This overload will be removed in the next release. Please use Fetch(Remote, FetchOptions) instead." ) ]
138147 public virtual void Fetch (
139148 Remote remote ,
140149 TagFetchMode ? tagFetchMode = null ,
141150 ProgressHandler onProgress = null ,
142151 UpdateTipsHandler onUpdateTips = null ,
143152 TransferProgressHandler onTransferProgress = null ,
144153 Credentials credentials = null )
154+ {
155+ Fetch ( remote , new FetchOptions
156+ {
157+ TagFetchMode = tagFetchMode ,
158+ OnProgress = onProgress ,
159+ OnUpdateTips = onUpdateTips ,
160+ OnTransferProgress = onTransferProgress ,
161+ Credentials = credentials
162+ } ) ;
163+ }
164+
165+ /// <summary>
166+ /// Fetch from the <see cref="Remote"/>.
167+ /// </summary>
168+ /// <param name="remote">The remote to fetch</param>
169+ public virtual void Fetch ( Remote remote )
170+ {
171+ // This overload is required as long as the obsolete overload exists.
172+ // Otherwise, Fetch(Remote) is ambiguous.
173+ Fetch ( remote , ( FetchOptions ) null ) ;
174+ }
175+
176+ /// <summary>
177+ /// Fetch from the <see cref="Remote"/>.
178+ /// </summary>
179+ /// <param name="remote">The remote to fetch</param>
180+ /// <param name="options"><see cref="FetchOptions"/> controlling fetch behavior</param>
181+ public virtual void Fetch ( Remote remote , FetchOptions options = null )
145182 {
146183 Ensure . ArgumentNotNull ( remote , "remote" ) ;
147184
148185 using ( RemoteSafeHandle remoteHandle = Proxy . git_remote_load ( repository . Handle , remote . Name , true ) )
149186 {
150- var callbacks = new RemoteCallbacks ( onProgress , onTransferProgress , onUpdateTips , credentials ) ;
151- GitRemoteCallbacks gitCallbacks = callbacks . GenerateCallbacks ( ) ;
152-
153- DoFetch ( remoteHandle , gitCallbacks , tagFetchMode ) ;
187+ DoFetch ( remoteHandle , options ) ;
154188 }
155189 }
156190
@@ -159,30 +193,20 @@ public virtual void Fetch(
159193 /// </summary>
160194 /// <param name="url">The url to fetch from</param>
161195 /// <param name="refspecs">The list of resfpecs to use</param>
162- /// <param name="tagFetchMode">Optional parameter indicating what tags to download.</param>
163- /// <param name="onProgress">Progress callback. Corresponds to libgit2 progress callback.</param>
164- /// <param name="onUpdateTips">UpdateTips callback. Corresponds to libgit2 update_tips callback.</param>
165- /// <param name="onTransferProgress">Callback method that transfer progress will be reported through.
166- /// Reports the client's state regarding the received and processed (bytes, objects) from the server.</param>
167- /// <param name="credentials">Credentials to use for username/password authentication.</param>
196+ /// <param name="options"><see cref="FetchOptions"/> controlling fetch behavior</param>
168197 public virtual void Fetch (
169198 string url ,
170199 IEnumerable < string > refspecs ,
171- TagFetchMode ? tagFetchMode = null ,
172- ProgressHandler onProgress = null ,
173- UpdateTipsHandler onUpdateTips = null ,
174- TransferProgressHandler onTransferProgress = null ,
175- Credentials credentials = null )
200+ FetchOptions options = null )
176201 {
177202 Ensure . ArgumentNotNull ( url , "url" ) ;
203+ Ensure . ArgumentNotNull ( refspecs , "refspecs" ) ;
178204
179205 using ( RemoteSafeHandle remoteHandle = Proxy . git_remote_create_inmemory ( repository . Handle , null , url ) )
180206 {
181207 Proxy . git_remote_set_fetch_refspecs ( remoteHandle , refspecs ) ;
182- var callbacks = new RemoteCallbacks ( onProgress , onTransferProgress , onUpdateTips , credentials ) ;
183- GitRemoteCallbacks gitCallbacks = callbacks . GenerateCallbacks ( ) ;
184208
185- DoFetch ( remoteHandle , gitCallbacks , tagFetchMode ) ;
209+ DoFetch ( remoteHandle , options ) ;
186210 }
187211 }
188212
0 commit comments