Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 60 lines (52 sloc) 1.641 kB
19f4d94 @pieter Add a Complete SHA service
pieter authored
1 //
2 // PBServicesController.m
3 // GitX
4 //
5 // Created by Pieter de Bie on 10/24/08.
6 // Copyright 2008 __MyCompanyName__. All rights reserved.
7 //
8
9 #import "PBServicesController.h"
10 #import "PBRepositoryDocumentController.h"
11 #import "PBGitRepository.h"
12
13 @implementation PBServicesController
14
15 - (NSString *)completeSHA1For:(NSString *)sha
16 {
17 NSArray *documents = [[NSApplication sharedApplication] orderedDocuments];
18 for (PBGitRepository *repo in documents)
19 {
20 int ret = 1;
21 NSString *s = [repo outputForArguments:[NSArray arrayWithObjects:@"log", @"-1", @"--pretty=format:%h (%s)", sha, nil] retValue:&ret];
22 if (!ret)
23 return s;
24 }
25 return @"Could not find SHA";
26 }
27
28 -(NSString *)runNameRevFor:(NSString *)s
29 {
30 NSArray *repositories = [[NSApplication sharedApplication] orderedDocuments];
31 if ([repositories count] == 0)
32 return s;
33 PBGitRepository *repo = [repositories objectAtIndex:0];
34 int ret = 1;
35 NSString *returnString = [repo outputForArguments:[NSArray arrayWithObjects:@"name-rev", @"--stdin", nil] inputString:s retValue:&ret];
36 if (ret)
37 return s;
38 return returnString;
39 }
40
41 -(void)completeSha:(NSPasteboard *)pboard userData:(NSString *)userData error:(NSString **)error
42 {
43 NSArray *types = [pboard types];
44 if (![types containsObject:NSStringPboardType])
45 {
46 *error = @"Could not get data";
47 return;
48 }
49
50 NSString *s = [pboard stringForType:NSStringPboardType];
51 if ([s rangeOfString:@" "].location == NSNotFound)
52 s = [self completeSHA1For:s];
53 else
54 s = [self runNameRevFor:s];
55
56 [pboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
57 [pboard setString:s forType:NSStringPboardType];
58 }
59 @end
Something went wrong with that request. Please try again.