Skip to content

Commit b1696ce

Browse files
committed
Merge branch 'fix/wire-pbtask' into work
2 parents a007c2d + 943701d commit b1696ce

File tree

7 files changed

+143
-313
lines changed

7 files changed

+143
-313
lines changed

Classes/Util/PBEasyPipe.h

Lines changed: 0 additions & 35 deletions
This file was deleted.

Classes/Util/PBEasyPipe.m

Lines changed: 0 additions & 177 deletions
This file was deleted.

Classes/git/PBGitIndex.m

Lines changed: 58 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,13 @@ - (void)commitWithMessage:(NSString *)commitMessage andVerify:(BOOL) doVerify
289289

290290

291291
[self postCommitUpdate:@"Creating tree"];
292-
NSString *tree = [self.repository outputForCommand:@"write-tree"];
292+
NSError *error = nil;
293+
NSString *tree = [self.repository outputOfTaskWithArguments:@[@"write-tree"] error:&error];
294+
if (!tree) {
295+
PBLogError(error);
296+
return [self postCommitFailure:@"Failed to lookup tree"];
297+
}
298+
tree = [tree stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
293299
if ([tree length] != 40)
294300
return [self postCommitFailure:@"Creating tree failed"];
295301

@@ -302,7 +308,6 @@ - (void)commitWithMessage:(NSString *)commitMessage andVerify:(BOOL) doVerify
302308
}
303309

304310
[self postCommitUpdate:@"Creating commit"];
305-
int ret = 1;
306311

307312
if (doVerify) {
308313
[self postCommitUpdate:@"Running hooks"];
@@ -332,24 +337,28 @@ - (void)commitWithMessage:(NSString *)commitMessage andVerify:(BOOL) doVerify
332337
}
333338

334339
commitMessage = [NSString stringWithContentsOfFile:commitMessageFile encoding:NSUTF8StringEncoding error:nil];
335-
336-
NSString *commit = [self.repository outputForArguments:arguments
337-
inputString:commitMessage
338-
byExtendingEnvironment:self.amendEnvironment
339-
retValue: &ret];
340-
341-
if (ret || [commit length] != 40)
340+
341+
PBTask *task = [self.repository taskWithArguments:arguments];
342+
task.additionalEnvironment = self.amendEnvironment;
343+
task.standardInputData = [commitMessage dataUsingEncoding:NSUTF8StringEncoding];
344+
345+
BOOL success = [task launchTask:&error];
346+
NSString *commit = [[task standardOutputString] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
347+
if (!success || commit.length != 40) {
348+
PBLogError(error);
342349
return [self postCommitFailure:@"Could not create a commit object"];
350+
}
343351

344352
[self postCommitUpdate:@"Updating HEAD"];
345-
[self.repository outputForArguments:[NSArray arrayWithObjects:@"update-ref", @"-m", commitSubject, @"HEAD", commit, nil]
346-
retValue: &ret];
347-
if (ret)
353+
success = [self.repository launchTaskWithArguments:@[@"update-ref", @"-m", commitSubject, @"HEAD", commit] error:&error];
354+
if (!success) {
355+
PBLogError(error);
348356
return [self postCommitFailure:@"Could not update HEAD"];
357+
}
349358

350359
[self postCommitUpdate:@"Running post-commit hook"];
351360

352-
BOOL success = [self.repository executeHook:@"post-commit" error:NULL];
361+
success = [self.repository executeHook:@"post-commit" error:NULL];
353362
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithObject:[NSNumber numberWithBool:success] forKey:@"success"];
354363
NSString *description;
355364
if (success)
@@ -445,19 +454,19 @@ - (BOOL)performStageOrUnstage:(BOOL)stage withFiles:(NSArray *)files
445454
}
446455
}
447456

448-
int ret = 1;
457+
NSArray *arguments = nil;
449458
if (stage) {
450-
[self.repository outputForArguments:[NSArray arrayWithObjects:@"update-index", @"--add", @"--remove", @"-z", @"--stdin", nil]
451-
inputString:input
452-
retValue:&ret];
459+
arguments = @[@"update-index", @"--add", @"--remove", @"-z", @"--stdin"];
453460
} else {
454-
[self.repository outputForArguments:[NSArray arrayWithObjects:@"update-index", @"-z", @"--index-info", nil]
455-
inputString:input
456-
retValue:&ret];
461+
arguments = @[@"update-index", @"-z", @"--index-info"];
457462
}
458463

459-
if (ret) {
460-
[self postOperationFailed:[NSString stringWithFormat:@"Error in %@ files. Return value: %i", (stage ? @"staging" : @"unstaging"), ret]];
464+
NSError *error = nil;
465+
BOOL success = [self.repository launchTaskWithArguments:arguments
466+
input:input
467+
error:&error];
468+
if (!success) {
469+
[self postOperationFailed:[NSString stringWithFormat:@"Error in %@ files. Return value: %@", (stage ? @"staging" : @"unstaging"), error.userInfo[PBTaskTerminationStatusKey]]];
461470
return NO;
462471
}
463472

@@ -523,13 +532,14 @@ - (BOOL)applyPatch:(NSString *)hunk stage:(BOOL)stage reverse:(BOOL)reverse;
523532
if (reverse)
524533
[array addObject:@"--reverse"];
525534

526-
int ret = 1;
527-
NSString *error = [self.repository outputForArguments:array
528-
inputString:hunk
529-
retValue:&ret];
535+
NSError *error = nil;
536+
NSString *output = [self.repository outputOfTaskWithArguments:array
537+
input:hunk
538+
error:&error];
530539

531-
if (ret) {
532-
[self postOperationFailed:[NSString stringWithFormat:@"Applying patch failed with return value %i. Error: %@", ret, error]];
540+
if (!output) {
541+
NSString *message = [NSString stringWithFormat:@"Applying patch failed with return value %@. Error: %@", error.userInfo[PBTaskTerminationStatusKey], error.userInfo[PBTaskTerminationOutputKey]];
542+
[self postOperationFailed:message];
533543
return NO;
534544
}
535545

@@ -543,12 +553,20 @@ - (NSString *)diffForFile:(PBChangedFile *)file staged:(BOOL)staged contextLines
543553
{
544554
NSString *parameter = [NSString stringWithFormat:@"-U%lu", context];
545555
if (staged) {
546-
NSString *indexPath = [@":0:" stringByAppendingString:file.path];
547-
548-
if (file.status == NEW)
549-
return [self.repository outputForArguments:[NSArray arrayWithObjects:@"show", indexPath, nil]];
556+
NSArray *arguments = nil;
557+
if (file.status == NEW) {
558+
NSString *indexPath = [@":0:" stringByAppendingString:file.path];
559+
arguments = @[@"show", indexPath];
560+
} else {
561+
arguments = @[@"diff-index", parameter, @"--cached", self.parentTree, @"--", file.path];
562+
}
550563

551-
return [self.repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff-index", parameter, @"--cached", [self parentTree], @"--", file.path, nil]];
564+
NSError *error = nil;
565+
NSString *output = [self.repository outputOfTaskWithArguments:arguments error:&error];
566+
if (!output) {
567+
PBLogError(error);
568+
}
569+
return output;
552570
}
553571

554572
// unstaged
@@ -562,7 +580,13 @@ - (NSString *)diffForFile:(PBChangedFile *)file staged:(BOOL)staged contextLines
562580
return contents;
563581
}
564582

565-
return [self.repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff-files", parameter, @"--", file.path, nil]];
583+
NSError *error = nil;
584+
NSString *output = [self.repository outputOfTaskWithArguments:@[@"diff-files", parameter, @"--", file.path]
585+
error:&error];
586+
if (!output) {
587+
PBLogError(error);
588+
}
589+
return output;
566590
}
567591

568592
# pragma mark WebKit Accessibility

Classes/git/PBGitRepository_PBGitBinarySupport.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,4 @@ NS_ASSUME_NONNULL_BEGIN
2020
- (nullable NSString *)outputOfTaskWithArguments:(nullable NSArray *)arguments error:(NSError **)error;
2121
@end
2222

23-
@interface PBGitRepository (PBGitBinarySupportDeprecated)
24-
- (NSFileHandle*) handleForArguments:(NSArray*) args GITX_DEPRECATED;
25-
- (NSString*) outputForCommand:(NSString*) cmd GITX_DEPRECATED;
26-
- (NSString *)outputForCommand:(NSString *)str retValue:(int *)ret GITX_DEPRECATED;
27-
- (NSString *)outputForArguments:(NSArray *)arguments inputString:(NSString *)input retValue:(int *)ret GITX_DEPRECATED;
28-
- (NSString *)outputForArguments:(NSArray *)arguments inputString:(NSString *)input byExtendingEnvironment:(NSDictionary *)dict retValue:(int *)ret GITX_DEPRECATED;
29-
30-
31-
- (NSString*) outputForArguments:(NSArray*) args GITX_DEPRECATED;
32-
- (NSString*) outputForArguments:(NSArray*) args retValue:(int *)ret GITX_DEPRECATED;
33-
- (NSString *)outputInWorkdirForArguments:(NSArray*) arguments GITX_DEPRECATED;
34-
- (NSString *)outputInWorkdirForArguments:(NSArray*) arguments retValue:(int *)ret GITX_DEPRECATED;
35-
@end
36-
3723
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)