-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CheckoutOptions: Support progress callbacks
- Loading branch information
Showing
17 changed files
with
229 additions
and
97 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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,9 @@ | ||
internal extension CheckoutOptions { | ||
/** | ||
Returns a C struct initialized with this options instance's values. | ||
Used by libgit2 functions. | ||
*/ | ||
internal var cOptions: git_checkout_options { | ||
return gift_checkoutOptions(UInt32(strategy.rawValue), progressCallback) | ||
} | ||
} |
This file contains 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
File renamed without changes.
This file contains 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,38 @@ | ||
#import <Foundation/Foundation.h> | ||
|
||
typedef struct git_checkout_options git_checkout_options; | ||
|
||
/** | ||
A callback function that is executed during a checkout. | ||
@param checkedOutFilePath A path to the file that is being checked out. | ||
@param fileIndex The index of the file whose checkout triggered this | ||
callback. For example, when the first file has been | ||
checked out, this is '0'. The second file is '1', the | ||
third is '2', and so on. | ||
@param fileCount The total number of files to be checked out. When the | ||
file index is equal to this file count, it can be | ||
inferred that this callback will no longer be called | ||
for the current checkout. | ||
*/ | ||
typedef void (^GIFTCheckoutProgressCallback)(NSString *checkedOutFilePath, | ||
NSUInteger fileIndex, | ||
NSUInteger fileCount); | ||
|
||
/** | ||
Returns a set of checkout options with the given paramters. | ||
@warning This function is necessary in order to allow a Swift closure | ||
to be used as a progress callback. It is impossible to | ||
obtain a reference to a C function from Swift that we may | ||
then use to configure a git_checkout_options struct. | ||
@param strategyValue The raw value of a CheckoutStrategy options set | ||
used to control how a checkout should be performed. | ||
@param progressCallback An optional progress callback block to be invoked | ||
as remote files are checked out. Note that this | ||
callback will not be invoked for local checkouts. | ||
@return A set of checkout options initialized with the given values. | ||
*/ | ||
extern git_checkout_options gift_checkoutOptions(unsigned int strategyValue, | ||
GIFTCheckoutProgressCallback progressCallback); |
This file contains 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,34 @@ | ||
#import "GIFTCheckoutOptions.h" | ||
#import <git2/checkout.h> | ||
|
||
#pragma mark - Internal Functions | ||
|
||
static void gift_checkoutProgressCallback(const char *cPath, | ||
size_t completedSteps, | ||
size_t totalSteps, | ||
void *payload) { | ||
if (payload == NULL) { | ||
return; | ||
} | ||
|
||
NSString *path = nil; | ||
if (cPath != NULL) { | ||
path = @(cPath); | ||
} | ||
|
||
GIFTCheckoutProgressCallback block = (__bridge GIFTCheckoutProgressCallback)payload; | ||
block(path, completedSteps, totalSteps); | ||
} | ||
|
||
#pragma mark - Public Interface | ||
|
||
extern git_checkout_options gift_checkoutOptions(unsigned int strategyValue, | ||
GIFTCheckoutProgressCallback progressCallback) { | ||
git_checkout_options options = GIT_CHECKOUT_OPTIONS_INIT; | ||
options.checkout_strategy = strategyValue; | ||
if (progressCallback != nil) { | ||
options.progress_cb = gift_checkoutProgressCallback; | ||
options.progress_payload = (__bridge void *)[progressCallback copy]; | ||
} | ||
return options; | ||
} |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains 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