-
Notifications
You must be signed in to change notification settings - Fork 603
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add easy pipe handling library. Use it to find real git repository path
This adds a new class, PBEasyPipe, which can do most of the pipe handling in an easy way. We use this to call `git rev-parse --git-dir` to find our current git repository. This means that we can now call GitX within a subdirectory :)
- Loading branch information
Showing
5 changed files
with
117 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// PBEasyPipe.h | ||
// GitX | ||
// | ||
// Created by Pieter de Bie on 16-06-08. | ||
// Copyright 2008 __MyCompanyName__. All rights reserved. | ||
// | ||
|
||
#import <Cocoa/Cocoa.h> | ||
|
||
|
||
@interface PBEasyPipe : NSObject { | ||
|
||
} | ||
|
||
+ (NSFileHandle*) handleForCommand: (NSString*) cmd withArgs: (NSArray*) args; | ||
+ (NSFileHandle*) handleForCommand: (NSString*) cmd withArgs: (NSArray*) args inDir: (NSString*) dir; | ||
|
||
+ (NSString*) outputForCommand: (NSString*) cmd withArgs: (NSArray*) args; | ||
+ (NSString*) outputForCommand: (NSString*) cmd withArgs: (NSArray*) args inDir: (NSString*) dir; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// | ||
// PBEasyPipe.m | ||
// GitX | ||
// | ||
// Created by Pieter de Bie on 16-06-08. | ||
// Copyright 2008 __MyCompanyName__. All rights reserved. | ||
// | ||
|
||
#import "PBEasyPipe.h" | ||
|
||
|
||
@implementation PBEasyPipe | ||
|
||
+ (NSFileHandle*) handleForCommand: (NSString*) cmd withArgs: (NSArray*) args | ||
{ | ||
return [self handleForCommand:cmd withArgs:args inDir:nil]; | ||
} | ||
|
||
+ (NSFileHandle*) handleForCommand: (NSString*) cmd withArgs: (NSArray*) args inDir: (NSString*) dir | ||
{ | ||
NSTask* task = [[NSTask alloc] init]; | ||
task.launchPath = cmd; | ||
task.arguments = args; | ||
if (dir) | ||
task.currentDirectoryPath = dir; | ||
NSLog(@"Starting cmd %@ in dir %@", cmd, dir); | ||
NSPipe* pipe = [NSPipe pipe]; | ||
task.standardOutput = pipe; | ||
|
||
NSFileHandle* handle = [NSFileHandle fileHandleWithStandardOutput]; | ||
handle = [pipe fileHandleForReading]; | ||
|
||
[task launch]; | ||
return handle; | ||
} | ||
|
||
|
||
|
||
+ (NSString*) outputForCommand: (NSString*) cmd withArgs: (NSArray*) args inDir: (NSString*) dir | ||
{ | ||
NSFileHandle* handle = [self handleForCommand:cmd withArgs: args inDir: dir]; | ||
NSData* data = [handle readDataToEndOfFile]; | ||
NSString* string = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; | ||
if ([string hasSuffix:@"\n"]) | ||
string = [string substringToIndex:[string length]-1]; | ||
|
||
return string; | ||
} | ||
+ (NSString*) outputForCommand: (NSString*) cmd withArgs: (NSArray*) args | ||
{ | ||
return [self outputForCommand:cmd withArgs:args inDir:nil]; | ||
} | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters