diff options
author | Jameson Miller <jamill@microsoft.com> | 2013-10-18 22:56:24 +0400 |
---|---|---|
committer | Jameson Miller <jamill@microsoft.com> | 2013-10-19 18:05:04 +0400 |
commit | bd736e2d130bd441fe7e767d9a7289d720bd0aea (patch) | |
tree | 4e41f286a9373b3878debf9c5b36dad7d2836e90 /LibGit2Sharp/RemoteCallbacks.cs | |
parent | 981f43909ca79b3b9e5c5a34590d76ecd5c82e3f (diff) |
Clean up cancellation patterns in callbacks and other small cleanups.
Diffstat (limited to 'LibGit2Sharp/RemoteCallbacks.cs')
-rw-r--r-- | LibGit2Sharp/RemoteCallbacks.cs | 45 |
1 files changed, 6 insertions, 39 deletions
diff --git a/LibGit2Sharp/RemoteCallbacks.cs b/LibGit2Sharp/RemoteCallbacks.cs index 5815ed02..962a5d3a 100644 --- a/LibGit2Sharp/RemoteCallbacks.cs +++ b/LibGit2Sharp/RemoteCallbacks.cs @@ -15,13 +15,11 @@ namespace LibGit2Sharp internal RemoteCallbacks( ProgressHandler onProgress = null, TransferProgressHandler onDownloadProgress = null, - CompletionHandler onCompletion = null, UpdateTipsHandler onUpdateTips = null, Credentials credentials = null) { Progress = onProgress; DownloadTransferProgress = onDownloadProgress; - Completion = onCompletion; UpdateTips = onUpdateTips; Credentials = credentials; } @@ -39,11 +37,6 @@ namespace LibGit2Sharp private readonly UpdateTipsHandler UpdateTips; /// <summary> - /// Completion callback. Corresponds to libgit2 Completion callback. - /// </summary> - private readonly CompletionHandler Completion; - - /// <summary> /// Managed delegate to be called in response to a git_transfer_progress_callback callback from libgit2. /// This will in turn call the user provided delegate. /// </summary> @@ -70,11 +63,6 @@ namespace LibGit2Sharp callbacks.update_tips = GitUpdateTipsHandler; } - if (Completion != null) - { - callbacks.completion = GitCompletionHandler; - } - if (Credentials != null) { callbacks.acquire_credentials = GitCredentialHandler; @@ -122,36 +110,15 @@ namespace LibGit2Sharp private int GitUpdateTipsHandler(IntPtr str, ref GitOid oldId, ref GitOid newId, IntPtr data) { UpdateTipsHandler onUpdateTips = UpdateTips; - int result = 0; + bool shouldContinue = true; if (onUpdateTips != null) { string refName = LaxUtf8Marshaler.FromNative(str); - result = onUpdateTips(refName, oldId, newId); - } - - return result; - } - - /// <summary> - /// Handler for libgit2 completion callback. Converts values - /// received from libgit2 callback to more suitable types - /// and calls delegate provided by LibGit2Sharp consumer. - /// </summary> - /// <param name="remoteCompletionType">Which operation completed.</param> - /// <param name="data">IntPtr to optional payload passed back to the callback.</param> - /// <returns>0 on success; a negative value to abort the process.</returns> - private int GitCompletionHandler(RemoteCompletionType remoteCompletionType, IntPtr data) - { - CompletionHandler completion = Completion; - int result = 0; - - if (completion != null) - { - result = completion(remoteCompletionType); + shouldContinue = onUpdateTips(refName, oldId, newId); } - return result; + return Proxy.ConvertResultToCancelFlag(shouldContinue); } /// <summary> @@ -162,14 +129,14 @@ namespace LibGit2Sharp /// <returns>the result of the wrapped <see cref="TransferProgressHandler"/></returns> private int GitDownloadTransferProgressHandler(ref GitTransferProgress progress, IntPtr payload) { - int result = 0; + bool shouldContinue = true; if (DownloadTransferProgress != null) { - result = DownloadTransferProgress(new TransferProgress(progress)); + shouldContinue = DownloadTransferProgress(new TransferProgress(progress)); } - return result; + return Proxy.ConvertResultToCancelFlag(shouldContinue); } private int GitCredentialHandler(out IntPtr cred, IntPtr url, IntPtr username_from_url, uint types, IntPtr payload) |