Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Classes/Controllers/PBGitSidebarController.m
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,15 @@ - (void)addRevSpec:(PBGitRevSpecifier *)rev

NSArray *pathComponents = [[rev simpleRef] componentsSeparatedByString:@"/"];
if ([pathComponents count] < 2)
[branches addChild:[PBSourceViewItem itemWithRevSpec:rev]];
[others addChild:[PBSourceViewItem itemWithRevSpec:rev]];
else if ([[pathComponents objectAtIndex:1] isEqualToString:@"heads"])
[branches addRev:rev toPath:[pathComponents subarrayWithRange:NSMakeRange(2, [pathComponents count] - 2)]];
else if ([[rev simpleRef] hasPrefix:@"refs/tags/"])
[tags addRev:rev toPath:[pathComponents subarrayWithRange:NSMakeRange(2, [pathComponents count] - 2)]];
else if ([[rev simpleRef] hasPrefix:@"refs/remotes/"])
[remotes addRev:rev toPath:[pathComponents subarrayWithRange:NSMakeRange(2, [pathComponents count] - 2)]];
else
[others addChild:[PBSourceViewItem itemWithRevSpec:rev]];
[sourceView reloadData];
}

Expand Down
2 changes: 2 additions & 0 deletions Classes/GitXScriptingConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@
#define kGitXCloneDestinationURLKey @"destinationURL"
#define kGitXCloneIsBareKey @"isBare"

#define kGitXOpenArgumentsStringKey @"openArguments"

#define kGitXFindSearchStringKey @"searchString"
#define kGitXFindInModeKey @"inMode"
9 changes: 6 additions & 3 deletions Classes/git/PBGitHistoryList.m
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,12 @@ - (void) resetGraphing
resetCommits = YES;
self.isUpdating = YES;

[graphQueue cancelAllOperations];
graphQueue = [[NSOperationQueue alloc] init];
[graphQueue setMaxConcurrentOperationCount:1];
if (graphQueue) {
[graphQueue cancelAllOperations];
} else {
graphQueue = [[NSOperationQueue alloc] init];
[graphQueue setMaxConcurrentOperationCount:1];
}

grapher = [self grapher];
}
Expand Down
2 changes: 2 additions & 0 deletions Classes/git/PBGitRepository.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ static NSString * PBStringFromBranchFilterType(PBGitXBranchFilterType type) {
- (BOOL)executeHook:(NSString *)name withArgs:(NSArray*) arguments output:(NSString **)output DEPRECATED;

- (NSString *)workingDirectory;
- (NSURL *) workingDirectoryURL;
- (NSString *) projectName;
- (NSString *)gitIgnoreFilename;
- (BOOL)isBareRepository;
Expand Down Expand Up @@ -139,6 +140,7 @@ static NSString * PBStringFromBranchFilterType(PBGitXBranchFilterType type) {
- (NSURL*) getIndexURL;

// for the scripting bridge
- (void)openWithScriptCommand:(NSScriptCommand *)command;
- (void)findInModeScriptCommand:(NSScriptCommand *)command;

@end
90 changes: 26 additions & 64 deletions Classes/git/PBGitRepository.m
Original file line number Diff line number Diff line change
Expand Up @@ -344,25 +344,11 @@ - (PBGitSHA *)shaForRef:(PBGitRef *)ref


NSError* error = nil;
GTReference* gtRef = [GTReference referenceByLookingUpReferencedNamed:ref.ref
inRepository:self.gtRepo
error:&error];
if (error)
{
NSLog(@"Error looking up ref for %@", ref.ref);
return nil;
}
const git_oid* refOid = gtRef.git_oid;
GTObject *object = [self.gtRepo lookupObjectByRevParse:ref.ref error:&error];
if (object)
return [PBGitSHA shaWithString:object.SHA];

if (refOid)
{
char buffer[41];
buffer[40] = '\0';
git_oid_fmt(buffer, refOid);
NSString* shaForRef = [NSString stringWithUTF8String:buffer];
PBGitSHA* result = [PBGitSHA shaWithString:shaForRef];
return result;
}
NSLog(@"Error looking up ref for %@", ref.ref);
return nil;
}

Expand Down Expand Up @@ -538,6 +524,11 @@ - (NSString *) workingDirectory
}
}

- (NSURL *) workingDirectoryURL
{
return [NSURL fileURLWithPath:[self workingDirectory]];
}

#pragma mark Remotes

- (NSArray *) remotes
Expand Down Expand Up @@ -912,7 +903,7 @@ - (BOOL) deleteRef:(PBGitRef *)ref

#pragma mark GitX Scripting

- (void)handleRevListArguments:(NSArray *)arguments inWorkingDirectory:(NSURL *)workingDirectory
- (void)handleRevListArguments:(NSArray *)arguments
{
if (![arguments count])
return;
Expand All @@ -924,45 +915,36 @@ - (void)handleRevListArguments:(NSArray *)arguments inWorkingDirectory:(NSURL *)
PBGitRef *refArgument = [self refForName:[arguments lastObject]];
if (refArgument) {
revListSpecifier = [[PBGitRevSpecifier alloc] initWithRef:refArgument];
revListSpecifier.workingDirectory = workingDirectory;
revListSpecifier.workingDirectory = [self workingDirectoryURL];
}
}

if (!revListSpecifier) {
revListSpecifier = [[PBGitRevSpecifier alloc] initWithParameters:arguments];
revListSpecifier.workingDirectory = workingDirectory;
revListSpecifier.workingDirectory = [self workingDirectoryURL];
}

self.currentBranch = [self addBranch:revListSpecifier];
[PBGitDefaults setShowStageView:NO];
[self.windowController showHistoryView:self];
}

- (void)handleBranchFilterEventForFilter:(PBGitXBranchFilterType)filter additionalArguments:(NSMutableArray *)arguments inWorkingDirectory:(NSURL *)workingDirectory
- (void)handleBranchFilterEventForFilter:(PBGitXBranchFilterType)filter additionalArguments:(NSArray *)arguments
{
self.currentBranchFilter = filter;
[PBGitDefaults setShowStageView:NO];
[self.windowController showHistoryView:self];

// treat any additional arguments as a rev-list specifier
if ([arguments count] > 1) {
[arguments removeObjectAtIndex:0];
[self handleRevListArguments:arguments inWorkingDirectory:workingDirectory];
NSMutableArray *argumentsButFirst = [arguments mutableCopy];
[argumentsButFirst removeObjectAtIndex:0];
[self handleRevListArguments:argumentsButFirst];
}
}

- (void)handleGitXScriptingArguments:(NSAppleEventDescriptor *)argumentsList inWorkingDirectory:(NSURL *)workingDirectory
- (void)handleGitXScriptingArguments:(NSArray *)arguments
{
NSMutableArray *arguments = [NSMutableArray array];
uint argumentsIndex = 1; // AppleEvent list descriptor's are one based
while(1) {
NSAppleEventDescriptor *arg = [argumentsList descriptorAtIndex:argumentsIndex++];
if (arg)
[arguments addObject:[arg stringValue]];
else
break;
}

if (![arguments count])
return;

Expand All @@ -975,50 +957,30 @@ - (void)handleGitXScriptingArguments:(NSAppleEventDescriptor *)argumentsList inW
}

if ([firstArgument isEqualToString:@"--all"]) {
[self handleBranchFilterEventForFilter:kGitXAllBranchesFilter additionalArguments:arguments inWorkingDirectory:workingDirectory];
[self handleBranchFilterEventForFilter:kGitXAllBranchesFilter additionalArguments:arguments];
return;
}

if ([firstArgument isEqualToString:@"--local"]) {
[self handleBranchFilterEventForFilter:kGitXLocalRemoteBranchesFilter additionalArguments:arguments inWorkingDirectory:workingDirectory];
[self handleBranchFilterEventForFilter:kGitXLocalRemoteBranchesFilter additionalArguments:arguments];
return;
}

if ([firstArgument isEqualToString:@"--branch"]) {
[self handleBranchFilterEventForFilter:kGitXSelectedBranchFilter additionalArguments:arguments inWorkingDirectory:workingDirectory];
[self handleBranchFilterEventForFilter:kGitXSelectedBranchFilter additionalArguments:arguments];
return;
}

// if the argument is not a known command then treat it as a rev-list specifier
[self handleRevListArguments:arguments inWorkingDirectory:workingDirectory];
[self handleRevListArguments:arguments];
}

// see if the current appleEvent has the command line arguments from the gitx cli
// this could be from an openApplication or an openDocument apple event
// when opening a repository this is called before the sidebar controller gets it's awakeFromNib: message
// if the repository is already open then this is also a good place to catch the event as the window is about to be brought forward
- (void)showWindows
// for the scripting bridge
- (void)openWithScriptCommand:(NSScriptCommand *)command
{
NSAppleEventDescriptor *currentAppleEvent = [[NSAppleEventManager sharedAppleEventManager] currentAppleEvent];

if (currentAppleEvent) {
NSAppleEventDescriptor *eventRecord = [currentAppleEvent paramDescriptorForKeyword:keyAEPropData];

// on app launch there may be many repositories opening, so double check that this is the right repo
NSString *path = [[eventRecord paramDescriptorForKeyword:typeFileURL] stringValue];
if (path) {
NSURL *workingDirectory = [NSURL URLWithString:path];
if ([[GitRepoFinder gitDirForURL:workingDirectory] isEqual:[self fileURL]]) {
NSAppleEventDescriptor *argumentsList = [eventRecord paramDescriptorForKeyword:kGitXAEKeyArgumentsList];
[self handleGitXScriptingArguments:argumentsList inWorkingDirectory:workingDirectory];

// showWindows may be called more than once during app launch so remove the CLI data after we handle the event
[currentAppleEvent removeDescriptorWithKeyword:keyAEPropData];
}
}
}

[super showWindows];
NSDictionary *commandArguments = [command arguments];
NSArray *arguments = [commandArguments objectForKey:kGitXOpenArgumentsStringKey];
[self handleGitXScriptingArguments:arguments];
}

// for the scripting bridge
Expand Down
6 changes: 5 additions & 1 deletion Classes/git/PBGitRevList.mm
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@ - (void) setupEnumerator:(GTEnumerator*)enumerator
} else if ([param hasPrefix:@"--glob="]) {
[enumerator pushGlob:[param substringFromIndex:@"--glob=".length] error:&error];
} else {
[enumerator pushGlob:param error:&error];
GTObject *obj = [repo lookupObjectByRevParse:param error:&error];
GTCommit *commit = [obj objectByPeelingToType:GTObjectTypeCommit error:&error];
if (commit) {
[enumerator pushSHA:commit.SHA error:&error];
}
}
}
}
Expand Down
42 changes: 9 additions & 33 deletions Classes/gitx.m
Original file line number Diff line number Diff line change
Expand Up @@ -145,39 +145,6 @@ void handleDiffWithArguments(NSURL *repositoryURL, NSArray *arguments)
exit(0);
}

void handleOpenRepository(NSURL *repositoryURL, NSMutableArray *arguments)
{
// if there are command line arguments send them to GitX through an Apple Event
// the recordDescriptor will be stored in keyAEPropData inside the openDocument or openApplication event
NSAppleEventDescriptor *recordDescriptor = nil;
if ([arguments count]) {
recordDescriptor = [NSAppleEventDescriptor recordDescriptor];

NSAppleEventDescriptor *listDescriptor = [NSAppleEventDescriptor listDescriptor];
uint listIndex = 1; // AppleEvent list descriptor's are one based
for (NSString *argument in arguments)
[listDescriptor insertDescriptor:[NSAppleEventDescriptor descriptorWithString:argument] atIndex:listIndex++];

[recordDescriptor setParamDescriptor:listDescriptor forKeyword:kGitXAEKeyArgumentsList];

// this is used as a double check in GitX
NSAppleEventDescriptor *url = [NSAppleEventDescriptor descriptorWithString:[repositoryURL absoluteString]];
[recordDescriptor setParamDescriptor:url forKeyword:typeFileURL];
}

// use NSWorkspace to open GitX and send the arguments
// this allows the repository document to modify itself before it shows it's GUI
BOOL didOpenURLs = [[NSWorkspace sharedWorkspace] openURLs:[NSArray arrayWithObject:repositoryURL]
withAppBundleIdentifier:kGitXBundleIdentifier
options:0
additionalEventParamDescriptor:recordDescriptor
launchIdentifiers:NULL];
if (!didOpenURLs) {
printf("Unable to open GitX.app\n");
exit(2);
}
}

void handleInit(NSURL *repositoryURL)
{
GitXApplication *gitXApp = [SBApplication applicationWithBundleIdentifier:kGitXBundleIdentifier];
Expand Down Expand Up @@ -253,6 +220,15 @@ PBHistorySearchMode searchModeForCommandLineArgument(NSString *argument)
return nil;
}

void handleOpenRepository(NSURL *repositoryURL, NSMutableArray *arguments)
{
GitXApplication *gitXApp = [SBApplication applicationWithBundleIdentifier:kGitXBundleIdentifier];
[gitXApp open:[NSArray arrayWithObject:repositoryURL]];

GitXDocument *repositoryDocument = documentForURL([gitXApp documents], repositoryURL);
[repositoryDocument openArguments:arguments];
}

void handleGitXSearch(NSURL *repositoryURL, NSMutableArray *arguments)
{
NSString *searchString = [arguments componentsJoinedByString:@" "];
Expand Down
2 changes: 2 additions & 0 deletions GitX.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
- (void) delete; // Delete an object.
- (void) duplicateTo:(SBObject *)to withProperties:(NSDictionary *)withProperties; // Copy an object.
- (void) moveTo:(SBObject *)to; // Move an object to a new location.
- (void) openArguments:(NSArray *)arguments; // Open a repository and optionally select given refs.
- (void) searchString:(NSString *)string inMode:(NSInteger)inMode; // Highlight commits that match the given search string.

@end
Expand All @@ -67,6 +68,7 @@
- (void) delete; // Delete an object.
- (void) duplicateTo:(SBObject *)to withProperties:(NSDictionary *)withProperties; // Copy an object.
- (void) moveTo:(SBObject *)to; // Move an object to a new location.
- (void) openArguments:(NSArray *)arguments; // Open a repository and optionally select given refs.
- (void) searchString:(NSString *)string inMode:(NSInteger)inMode; // Highlight commits that match the given search string.

@end
Expand Down
11 changes: 11 additions & 0 deletions GitX.sdef
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@
</parameter>
</command>

<command name="open" code="GitXOpen" description="Open a repository and optionally select given refs.">
<direct-parameter type="specifier" description="The repository document to open."/>
<parameter name="arguments" code="ARGS" description="The arguments">
<type type="text" list="yes"/>
<cocoa key="openArguments"/>
</parameter>
</command>

<command name="search" code="GitXSrch" description="Highlight commits that match the given search string.">
<direct-parameter type="specifier" description="The repository document to search."/>
<parameter name="string" code="SRCH" type="text" optional="yes" description="The string to search for.">
Expand All @@ -197,6 +205,9 @@

<class-extension extends="document" code="docu" description="A document.">
<cocoa class="PBGitRepository"/>
<responds-to name="open">
<cocoa method="openWithScriptCommand:"/>
</responds-to>
<responds-to name="search">
<cocoa method="findInModeScriptCommand:"/>
</responds-to>
Expand Down