Skip to content

Commit 78a7388

Browse files
committed
Update last few "trivial" uses to PBTask
1 parent 0913e06 commit 78a7388

File tree

3 files changed

+34
-17
lines changed

3 files changed

+34
-17
lines changed

Classes/Controllers/PBServicesController.m

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,36 @@ - (NSString *)completeSHA1For:(NSString *)sha error:(NSString **)error
1818
NSArray *documents = [[NSApplication sharedApplication] orderedDocuments];
1919
for (PBGitRepositoryDocument *doc in documents)
2020
{
21-
int ret = 1;
22-
NSString *s = [doc.repository outputForArguments:[NSArray arrayWithObjects:@"log", @"-1", @"--pretty=format:%h (%s)", sha, nil] retValue:&ret];
23-
if (!ret)
21+
NSError *error = nil;
22+
NSString *s = [doc.repository outputOfTaskWithArguments:@[@"log", @"-1", @"--pretty=format:%h (%s)", sha] error:&error];
23+
if (s) {
2424
return s;
25+
}
2526
}
2627

2728
if (error) *error = @"Unable to resolve SHA in opened repositories";
2829
return nil;
2930
}
3031

31-
- (NSString *)runNameRevFor:(NSString *)s error:(NSString **)error
32+
- (NSString *)runNameRevFor:(NSString *)s error:(NSString **)errorStr
3233
{
3334
NSArray *repositories = [[NSApplication sharedApplication] orderedDocuments];
3435
if ([repositories count] == 0)
3536
return s;
3637
PBGitRepositoryDocument *doc = [repositories objectAtIndex:0];
37-
int ret = 1;
38-
NSString *returnString = [doc.repository outputForArguments:[NSArray arrayWithObjects:@"name-rev", @"--stdin", nil] inputString:s retValue:&ret];
39-
if (!ret)
40-
return returnString;
4138

42-
if (error) *error = @"Unable to resolve SHA in opened repositories";
39+
NSError *error = nil;
40+
PBTask *task = [doc.repository taskWithArguments:@[]];
41+
task.standardInputData = [s dataUsingEncoding:NSUTF8StringEncoding];
42+
BOOL success = [task launchTask:&error];
43+
44+
if (success) {
45+
return task.standardOutputString;
46+
} else {
47+
PBLogError(error);
48+
}
49+
50+
if (errorStr) *errorStr = @"Unable to resolve SHA in opened repositories";
4351
return nil;
4452
}
4553

Classes/git/PBGitCommit.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,13 @@ - (NSString *) patch
195195
if (self->_patch != nil)
196196
return _patch;
197197

198-
NSString *p = [self.repository outputForArguments:[NSArray arrayWithObjects:@"format-patch", @"-1", @"--stdout", self.SHA, nil]];
198+
NSError *error = nil;
199+
NSString *p = [self.repository outputOfTaskWithArguments:@[@"format-patch", @"-1", @"--stdout", self.SHA] error:&error];
200+
if (!p) {
201+
PBLogError(error);
202+
return nil;
203+
}
204+
199205
// Add a GitX identifier to the patch ;)
200206
self.patch = [[p substringToIndex:[p length] -1] stringByAppendingString:@"+GitX"];
201207
return self->_patch;

Classes/git/PBGitRepository.m

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,10 +1000,10 @@ - (NSString *)performDiff:(PBGitCommit *)startCommit against:(PBGitCommit *)diff
10001000
[arguments addObjectsFromArray:filePaths];
10011001
}
10021002

1003-
int retValue;
1004-
NSString *diff = [startCommit.repository outputInWorkdirForArguments:arguments retValue:&retValue];
1005-
if (retValue) {
1006-
NSLog(@"diff failed with retValue: %d for command: '%@' output: '%@'", retValue, [arguments componentsJoinedByString:@" "], diff);
1003+
NSError *error = nil;
1004+
NSString *diff = [self outputOfTaskWithArguments:arguments error:&error];
1005+
if (!diff) {
1006+
PBLogError(error);
10071007
return @"";
10081008
}
10091009
return diff;
@@ -1036,9 +1036,12 @@ - (BOOL) deleteRef:(PBGitRef *)ref error:(NSError **)error
10361036
}
10371037

10381038
- (BOOL)updateReference:(PBGitRef *)ref toPointAtCommit:(PBGitCommit *)newCommit {
1039-
int retValue = 1;
1040-
[self outputForArguments:@[@"update-ref", @"-mUpdate from GitX", ref.ref, newCommit.SHA] retValue:&retValue];
1041-
return retValue != 0;
1039+
NSError *error = nil;
1040+
BOOL success = [self launchTaskWithArguments:@[@"update-ref", @"-mUpdate from GitX", ref.ref, newCommit.SHA] error:&error];
1041+
if (!success) {
1042+
PBLogError(error);
1043+
}
1044+
return success;
10421045
}
10431046

10441047
- (GTSubmodule *)submoduleAtPath:(NSString *)path error:(NSError **)error;

0 commit comments

Comments
 (0)