-
Notifications
You must be signed in to change notification settings - Fork 899
Fetch should report progress through callbacks. #238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace LibGit2Sharp.Core | ||
{ | ||
/// <summary> | ||
/// Managed structure corresponding to git_transfer_progress native structure. | ||
/// </summary> | ||
[StructLayout(LayoutKind.Sequential)] | ||
internal struct GitTransferProgress | ||
{ | ||
public uint total_objects; | ||
public uint indexed_objects; | ||
public uint received_objects; | ||
public UIntPtr received_bytes; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System; | ||
using LibGit2Sharp.Core; | ||
using LibGit2Sharp.Handlers; | ||
|
||
namespace LibGit2Sharp | ||
{ | ||
/// <summary> | ||
/// Class to handle the mapping between libgit2 git_transfer_progress_callback function and | ||
/// a corresponding <see cref = "TransferProgressHandler" />. Generates a delegate that | ||
/// wraps the <see cref = "TransferProgressHandler" /> delegate with a delegate that matches | ||
/// the git_transfer_progress_callback signature. | ||
/// </summary> | ||
internal class TransferCallbacks | ||
{ | ||
/// <summary> | ||
/// Managed delegate to be called in response to a git_transfer_progress_callback callback from libgit2. | ||
/// </summary> | ||
private TransferProgressHandler onTransferProgress; | ||
|
||
/// <summary> | ||
/// Constructor to set up the native callback given managed delegate. | ||
/// </summary> | ||
/// <param name="onTransferProgress">The <see cref="TransferProgressHandler"/> delegate that the git_transfer_progress_callback will call.</param> | ||
private TransferCallbacks(TransferProgressHandler onTransferProgress) | ||
{ | ||
this.onTransferProgress = onTransferProgress; | ||
} | ||
|
||
/// <summary> | ||
/// Generates a delegate that matches the native git_transfer_progress_callback function's signature and wraps the <see cref = "TransferProgressHandler" /> delegate. | ||
/// </summary> | ||
/// <param name="onTransferProgress">The <see cref = "TransferProgressHandler" /> delegate to call in responde to a the native git_transfer_progress_callback callback.</param> | ||
/// <returns>A delegate method with a signature that matches git_transfer_progress_callback.</returns> | ||
internal static NativeMethods.git_transfer_progress_callback GenerateCallback(TransferProgressHandler onTransferProgress) | ||
{ | ||
if (onTransferProgress == null) | ||
{ | ||
return null; | ||
} | ||
|
||
return new TransferCallbacks(onTransferProgress).OnGitTransferProgress; | ||
} | ||
|
||
/// <summary> | ||
/// The delegate with the signature that matches the native git_transfer_progress_callback function's signature. | ||
/// </summary> | ||
/// <param name="progress"><see cref = "GitTransferProgress" /> structure containing progress information.</param> | ||
/// <param name="payload">Payload data.</param> | ||
private void OnGitTransferProgress(ref GitTransferProgress progress, IntPtr payload) | ||
{ | ||
onTransferProgress(new TransferProgress(progress)); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System; | ||
using LibGit2Sharp.Core; | ||
|
||
namespace LibGit2Sharp | ||
{ | ||
/// <summary> | ||
/// Expose progress values from a fetch operation. | ||
/// </summary> | ||
public class TransferProgress | ||
{ | ||
private GitTransferProgress gitTransferProgress; | ||
|
||
/// <summary> | ||
/// Empty constructor. | ||
/// </summary> | ||
protected TransferProgress() | ||
{ } | ||
|
||
/// <summary> | ||
/// Constructor. | ||
/// </summary> | ||
internal TransferProgress(GitTransferProgress gitTransferProgress) | ||
{ | ||
this.gitTransferProgress = gitTransferProgress; | ||
} | ||
|
||
/// <summary> | ||
/// Total number of objects. | ||
/// </summary> | ||
public virtual int TotalObjects | ||
{ | ||
get | ||
{ | ||
return (int) gitTransferProgress.total_objects; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Number of objects indexed. | ||
/// </summary> | ||
public virtual int IndexedObjects | ||
{ | ||
get | ||
{ | ||
return (int) gitTransferProgress.indexed_objects; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Number of objects received. | ||
/// </summary> | ||
public virtual int ReceivedObjects | ||
{ | ||
get | ||
{ | ||
return (int) gitTransferProgress.received_objects; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Number of bytes received. | ||
/// </summary> | ||
public virtual long ReceivedBytes | ||
{ | ||
get | ||
{ | ||
return (long) gitTransferProgress.received_bytes; | ||
} | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer not decorating this with a
[CLSCompliant(false)]
What's the maximum object numbers that could be reached? Wouldn't
int
be enough? Should we have to deal with more than 2,147,483,647 objects, we could still make this along
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I imagine int would be enough. I was reflecting the types that these values are as in libgit2. I will change the
uint
s to beint
s, and theulong
to be along
.