2 // PBServicesController.m
5 // Created by Pieter de Bie on 10/24/08.
6 // Copyright 2008 __MyCompanyName__. All rights reserved.
9 #import "PBServicesController.h"
10 #import "PBRepositoryDocumentController.h"
11 #import "PBGitRepository.h"
13 @implementation PBServicesController
15 - (NSString *)completeSHA1For:(NSString *)sha
17 NSArray *documents = [[NSApplication sharedApplication] orderedDocuments];
18 for (PBGitRepository *repo in documents)
21 NSString *s = [repo outputForArguments:[NSArray arrayWithObjects:@"log", @"-1", @"--pretty=format:%h (%s)", sha, nil] retValue:&ret];
25 return @"Could not find SHA";
28 -(NSString *)runNameRevFor:(NSString *)s
30 NSArray *repositories = [[NSApplication sharedApplication] orderedDocuments];
31 if ([repositories count] == 0)
33 PBGitRepository *repo = [repositories objectAtIndex:0];
35 NSString *returnString = [repo outputForArguments:[NSArray arrayWithObjects:@"name-rev", @"--stdin", nil] inputString:s retValue:&ret];
41 -(void)completeSha:(NSPasteboard *)pboard userData:(NSString *)userData error:(NSString **)error
43 NSArray *types = [pboard types];
44 if (![types containsObject:NSStringPboardType])
46 *error = @"Could not get data";
50 NSString *s = [pboard stringForType:NSStringPboardType];
51 if ([s rangeOfString:@" "].location == NSNotFound)
52 s = [self completeSHA1For:s];
54 s = [self runNameRevFor:s];
56 [pboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
57 [pboard setString:s forType:NSStringPboardType];