Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 59 lines (52 sloc) 1.641 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
//
// PBServicesController.m
// GitX
//
// Created by Pieter de Bie on 10/24/08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//

#import "PBServicesController.h"
#import "PBRepositoryDocumentController.h"
#import "PBGitRepository.h"

@implementation PBServicesController

- (NSString *)completeSHA1For:(NSString *)sha
{
NSArray *documents = [[NSApplication sharedApplication] orderedDocuments];
for (PBGitRepository *repo in documents)
{
int ret = 1;
NSString *s = [repo outputForArguments:[NSArray arrayWithObjects:@"log", @"-1", @"--pretty=format:%h (%s)", sha, nil] retValue:&ret];
if (!ret)
return s;
}
return @"Could not find SHA";
}

-(NSString *)runNameRevFor:(NSString *)s
{
NSArray *repositories = [[NSApplication sharedApplication] orderedDocuments];
if ([repositories count] == 0)
return s;
PBGitRepository *repo = [repositories objectAtIndex:0];
int ret = 1;
NSString *returnString = [repo outputForArguments:[NSArray arrayWithObjects:@"name-rev", @"--stdin", nil] inputString:s retValue:&ret];
if (ret)
return s;
return returnString;
}

-(void)completeSha:(NSPasteboard *)pboard userData:(NSString *)userData error:(NSString **)error
{
NSArray *types = [pboard types];
if (![types containsObject:NSStringPboardType])
{
*error = @"Could not get data";
return;
}

NSString *s = [pboard stringForType:NSStringPboardType];
if ([s rangeOfString:@" "].location == NSNotFound)
s = [self completeSHA1For:s];
else
s = [self runNameRevFor:s];

[pboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
[pboard setString:s forType:NSStringPboardType];
}
@end
Something went wrong with that request. Please try again.