Skip to content

Commit

Permalink
Make the apply/pop machinery common
Browse files Browse the repository at this point in the history
  • Loading branch information
tiennou committed Sep 8, 2015
1 parent b4d5816 commit fcbcf23
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions ObjectiveGit/GTRepository+Stashing.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static int stashApplyProgressCallback(git_stash_apply_progress_t progress, void
return (stop ? GIT_EUSER : 0);
}

- (BOOL)applyStashAtIndex:(NSUInteger)index flags:(GTRepositoryStashApplyFlag)flags error:(NSError **)error progressBlock:(nullable void (^)(GTRepositoryStashApplyProgress progress, BOOL *stop))progressBlock {
- (BOOL)applyStashAtIndex:(NSUInteger)index popStash:(BOOL)pop flags:(GTRepositoryStashApplyFlag)flags error:(NSError **)error progressBlock:(nullable void (^)(GTRepositoryStashApplyProgress, BOOL * __nonnull))progressBlock {
git_stash_apply_options stash_options = GIT_STASH_APPLY_OPTIONS_INIT;

stash_options.flags = (git_stash_apply_flags)flags;
Expand All @@ -68,29 +68,28 @@ - (BOOL)applyStashAtIndex:(NSUInteger)index flags:(GTRepositoryStashApplyFlag)fl
stash_options.progress_payload = (__bridge void *)progressBlock;
}

int gitError = git_stash_apply(self.git_repository, index, &stash_options);
if (gitError != GIT_OK) {
if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Stash apply failed" failureReason:@"The stash at index %ld couldn't be applied.", (unsigned long)index];
return NO;
if (pop == NO) {
int gitError = git_stash_apply(self.git_repository, index, &stash_options);
if (gitError != GIT_OK) {
if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Stash apply failed" failureReason:@"The stash at index %ld couldn't be applied.", (unsigned long)index];
return NO;
}
} else {
int gitError = git_stash_pop(self.git_repository, index, &stash_options);
if (gitError != GIT_OK) {
if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Stash pop failed" failureReason:@"The stash at index %ld couldn't be applied.", (unsigned long)index];
return NO;
}
}
return YES;
}

- (BOOL)popStashAtIndex:(NSUInteger)index flags:(GTRepositoryStashApplyFlag)flags error:(NSError **)error progressBlock:(nullable void (^)(GTRepositoryStashApplyProgress progress, BOOL *stop))progressBlock {
git_stash_apply_options stash_options = GIT_STASH_APPLY_OPTIONS_INIT;

stash_options.flags = (git_stash_apply_flags)flags;
if (progressBlock != nil) {
stash_options.progress_cb = stashApplyProgressCallback;
stash_options.progress_payload = (__bridge void *)progressBlock;
}
- (BOOL)applyStashAtIndex:(NSUInteger)index flags:(GTRepositoryStashApplyFlag)flags error:(NSError **)error progressBlock:(nullable void (^)(GTRepositoryStashApplyProgress progress, BOOL *stop))progressBlock {
return [self applyStashAtIndex:index popStash:NO flags:flags error:error progressBlock:progressBlock];
}

int gitError = git_stash_pop(self.git_repository, index, &stash_options);
if (gitError != GIT_OK) {
if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Stash pop failed" failureReason:@"The stash at index %ld couldn't be applied.", (unsigned long)index];
return NO;
}
return YES;
- (BOOL)popStashAtIndex:(NSUInteger)index flags:(GTRepositoryStashApplyFlag)flags error:(NSError **)error progressBlock:(nullable void (^)(GTRepositoryStashApplyProgress progress, BOOL *stop))progressBlock {
return [self applyStashAtIndex:index popStash:YES flags:flags error:error progressBlock:progressBlock];
}

- (BOOL)dropStashAtIndex:(NSUInteger)index error:(NSError **)error {
Expand Down

0 comments on commit fcbcf23

Please sign in to comment.