77//
88
99#import " PBServicesController.h"
10+ #import " PBGitRepositoryDocument.h"
1011#import " PBGitRepository.h"
1112
1213@implementation PBServicesController
1314
14- - (NSString *)completeSHA1For : (NSString *)sha
15+ - (NSString *)completeSHA1For : (NSString *)sha error : ( NSString **) error
1516{
1617 NSArray *documents = [[NSApplication sharedApplication ] orderedDocuments ];
17- for (PBGitRepository *repo in documents)
18+ for (PBGitRepositoryDocument *doc in documents)
1819 {
1920 int ret = 1 ;
20- NSString *s = [repo outputForArguments: [NSArray arrayWithObjects: @" log" , @" -1" , @" --pretty=format:%h (%s )" , sha, nil ] retValue: &ret];
21+ NSString *s = [doc.repository outputForArguments: [NSArray arrayWithObjects: @" log" , @" -1" , @" --pretty=format:%h (%s )" , sha, nil ] retValue: &ret];
2122 if (!ret)
2223 return s;
2324 }
24- return @" Could not find SHA" ;
25+
26+ if (error) *error = @" Unable to resolve SHA in opened repositories" ;
27+ return nil ;
2528}
2629
27- -(NSString *)runNameRevFor : (NSString *)s
30+ - (NSString *)runNameRevFor : (NSString *)s error : ( NSString **) error
2831{
2932 NSArray *repositories = [[NSApplication sharedApplication ] orderedDocuments ];
3033 if ([repositories count ] == 0 )
3134 return s;
32- PBGitRepository *repo = [repositories objectAtIndex: 0 ];
35+ PBGitRepositoryDocument *doc = [repositories objectAtIndex: 0 ];
3336 int ret = 1 ;
34- NSString *returnString = [repo outputForArguments: [NSArray arrayWithObjects: @" name-rev" , @" --stdin" , nil ] inputString: s retValue: &ret];
35- if (ret)
36- return s;
37- return returnString;
37+ NSString *returnString = [doc.repository outputForArguments: [NSArray arrayWithObjects: @" name-rev" , @" --stdin" , nil ] inputString: s retValue: &ret];
38+ if (!ret)
39+ return returnString;
40+
41+ if (error) *error = @" Unable to resolve SHA in opened repositories" ;
42+ return nil ;
3843}
3944
40- -(void )completeSha : (NSPasteboard *)pboard userData : (NSString *)userData error : (NSString **)error
45+ - (void )completeSha : (NSPasteboard *)pboard userData : (NSString *)userData error : (NSString **)error
4146{
4247 NSArray *types = [pboard types ];
4348 if (![types containsObject: NSStringPboardType ])
@@ -48,9 +53,11 @@ -(void)completeSha:(NSPasteboard *)pboard userData:(NSString *)userData error:(N
4853
4954 NSString *s = [pboard stringForType: NSStringPboardType ];
5055 if ([s rangeOfString: @" " ].location == NSNotFound )
51- s = [self completeSHA1For: s];
56+ s = [self completeSHA1For: s error: error ];
5257 else
53- s = [self runNameRevFor: s];
58+ s = [self runNameRevFor: s error: error];
59+
60+ if (!s) return ;
5461
5562 [pboard declareTypes: [NSArray arrayWithObject: NSStringPboardType ] owner: nil ];
5663 [pboard setString: s forType: NSStringPboardType ];
0 commit comments