mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
Merge branch 'refs/heads/FileMerge_on_diffs'
This commit is contained in:
@@ -40,6 +40,7 @@
|
||||
+(BOOL)isBinaryFile:(NSString *)line;
|
||||
+(NSString*)mimeTypeForFileName:(NSString*)file;
|
||||
+(BOOL)isImage:(NSString*)file;
|
||||
+(BOOL)isDiffHeader:(NSString*)line;
|
||||
|
||||
@property(retain) NSMutableArray *groups;
|
||||
@property(retain) NSString *logFormat;
|
||||
|
||||
+64
-53
@@ -274,61 +274,27 @@
|
||||
NSArray *lines = [txt componentsSeparatedByString:@"\n"];
|
||||
NSString *line;
|
||||
NSMutableString *res=[NSMutableString string];
|
||||
BOOL inDiff=FALSE;
|
||||
BOOL inBlock=FALSE;
|
||||
|
||||
|
||||
int l_line,l_end;
|
||||
int r_line,r_end;
|
||||
int i;
|
||||
for (i=0; i<[lines count]; i++) {
|
||||
|
||||
int i=0;
|
||||
do {
|
||||
line=[lines objectAtIndex:i];
|
||||
|
||||
if([GLFileView isStartBlock:line]){
|
||||
[res appendString:@"</td></tr></thead><tbody>"];
|
||||
inDiff=FALSE;
|
||||
NSString *header=[line substringFromIndex:3];
|
||||
NSRange hr = NSMakeRange(0, [header rangeOfString:@" @@"].location);
|
||||
header=[header substringWithRange:hr];
|
||||
|
||||
NSArray *pos=[header componentsSeparatedByString:@" "];
|
||||
NSArray *pos_l=[[pos objectAtIndex:0] componentsSeparatedByString:@","];
|
||||
NSArray *pos_r=[[pos objectAtIndex:1] componentsSeparatedByString:@","];
|
||||
|
||||
l_end=l_line=abs([[pos_l objectAtIndex:0]integerValue]);
|
||||
if ([pos_l count]>1) {
|
||||
l_end=l_line+[[pos_l objectAtIndex:1]integerValue];
|
||||
}
|
||||
|
||||
r_end=r_line=[[pos_r objectAtIndex:0]integerValue];
|
||||
if ([pos_r count]>1) {
|
||||
r_end=r_line+[[pos_r objectAtIndex:1]integerValue];
|
||||
}
|
||||
|
||||
[res appendString:[NSString stringWithFormat:@"<tr class='header'><td colspan='3'>%@</td></tr>",line]];
|
||||
inBlock=TRUE;
|
||||
}else if(inBlock){
|
||||
NSString *s=[line substringToIndex:1];
|
||||
if([s isEqualToString:@" "]){
|
||||
[res appendString:[NSString stringWithFormat:@"<tr><td class='l'>%d</td><td class='r'>%d</td>",l_line++,r_line++]];
|
||||
}else if([s isEqualToString:@"-"]){
|
||||
[res appendString:[NSString stringWithFormat:@"<tr class='l'><td class='l'>%d</td><td class='r'></td>",l_line++]];
|
||||
}else if([s isEqualToString:@"+"]){
|
||||
[res appendString:[NSString stringWithFormat:@"<tr class='r'><td class='l'></td><td class='r'>%d</td>",r_line++]];
|
||||
}
|
||||
[res appendString:[NSString stringWithFormat:@"<td class='code'>%@</td></tr>",[line substringFromIndex:1]]];
|
||||
if(!(l_line<l_end) && !(r_line<r_end))
|
||||
inBlock=FALSE;
|
||||
}else if([GLFileView isStartDiff:line]){
|
||||
if(inDiff)
|
||||
[res appendString:@"</tbody></table>"];
|
||||
inDiff=TRUE;
|
||||
if([GLFileView isStartDiff:line]){
|
||||
NSString *fileName=[self getFileName:line];
|
||||
[res appendString:[NSString stringWithFormat:@"<table id='%@' class='diff'><thead><tr><td colspan='3'>",fileName]];
|
||||
[res appendString:[NSString stringWithFormat:@"<p>%@</p>",line]];
|
||||
}else if(inDiff){
|
||||
[res appendString:[NSString stringWithFormat:@"<p>%@</p>",line]];
|
||||
[res appendString:[NSString stringWithFormat:@"<table id='%@' class='diff'><thead><tr><td colspan='3'><div style='float:left;'>",fileName]];
|
||||
do{
|
||||
[res appendString:[NSString stringWithFormat:@"<p>%@</p>",line]];
|
||||
line=[lines objectAtIndex:++i];
|
||||
}while([GLFileView isDiffHeader:line]);
|
||||
[res appendString:@"</div>"];
|
||||
if(![self isBinaryFile:line]){
|
||||
[res appendString:[NSString stringWithFormat:@"<div class='filemerge'><a href='' onclick='openFileMerge(\"%@\",\"{SHA}\"); return false;'><img src='GitX://app:/filemerge' width='32' height='32'/><br/>open in<br/>FileMerge</a></div>",fileName]];
|
||||
}
|
||||
[res appendString:@"</td></tr></thead><tbody>"];
|
||||
|
||||
if([self isBinaryFile:line]){
|
||||
[res appendString:@"</td></tr></thead><tbody>"];
|
||||
NSArray *files=[self getFilesNames:line];
|
||||
if(![[files objectAtIndex:0] isAbsolutePath]){
|
||||
[res appendString:[NSString stringWithFormat:@"<tr><td colspan='3'>%@</td></tr>",[files objectAtIndex:0]]];
|
||||
@@ -342,11 +308,50 @@
|
||||
[res appendString:[NSString stringWithFormat:@"<tr><td colspan='3'><img src='GitX://{SHA}/%@'/></td></tr>",[files objectAtIndex:1]]];
|
||||
}
|
||||
}
|
||||
}else{
|
||||
do{
|
||||
NSString *header=[line substringFromIndex:3];
|
||||
NSRange hr = NSMakeRange(0, [header rangeOfString:@" @@"].location);
|
||||
header=[header substringWithRange:hr];
|
||||
|
||||
NSArray *pos=[header componentsSeparatedByString:@" "];
|
||||
NSArray *pos_l=[[pos objectAtIndex:0] componentsSeparatedByString:@","];
|
||||
NSArray *pos_r=[[pos objectAtIndex:1] componentsSeparatedByString:@","];
|
||||
|
||||
l_end=l_line=abs([[pos_l objectAtIndex:0]integerValue]);
|
||||
if ([pos_l count]>1) {
|
||||
l_end=l_line+[[pos_l objectAtIndex:1]integerValue];
|
||||
}
|
||||
|
||||
r_end=r_line=[[pos_r objectAtIndex:0]integerValue];
|
||||
if ([pos_r count]>1) {
|
||||
r_end=r_line+[[pos_r objectAtIndex:1]integerValue];
|
||||
}
|
||||
|
||||
[res appendString:[NSString stringWithFormat:@"<tr class='header'><td colspan='3'>%@</td></tr>",line]];
|
||||
do{
|
||||
line=[lines objectAtIndex:++i];
|
||||
NSString *s=[line substringToIndex:1];
|
||||
if([s isEqualToString:@" "]){
|
||||
[res appendString:[NSString stringWithFormat:@"<tr><td class='l'>%d</td><td class='r'>%d</td>",l_line++,r_line++]];
|
||||
}else if([s isEqualToString:@"-"]){
|
||||
[res appendString:[NSString stringWithFormat:@"<tr class='l'><td class='l'>%d</td><td class='r'></td>",l_line++]];
|
||||
}else if([s isEqualToString:@"+"]){
|
||||
[res appendString:[NSString stringWithFormat:@"<tr class='r'><td class='l'></td><td class='r'>%d</td>",r_line++]];
|
||||
}
|
||||
[res appendString:[NSString stringWithFormat:@"<td class='code'>%@</td></tr>",[line substringFromIndex:1]]];
|
||||
}while((l_line<l_end) || (r_line<r_end));
|
||||
if(i<([lines count]-1)){
|
||||
line=[lines objectAtIndex:++i];
|
||||
}
|
||||
}while([GLFileView isStartBlock:line]);
|
||||
}
|
||||
[res appendString:@"</tbody></table>"];
|
||||
}else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
if(inDiff)
|
||||
[res appendString:@"</tbody></table>"];
|
||||
}while(i<[lines count]);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -395,6 +400,12 @@
|
||||
return mimeType;
|
||||
}
|
||||
|
||||
+(BOOL)isDiffHeader:(NSString*)line
|
||||
{
|
||||
unichar c=[line characterAtIndex:0];
|
||||
return (c=='i') || (c=='m') || (c=='n') || (c=='d') || (c=='-') || (c=='+');
|
||||
}
|
||||
|
||||
+(BOOL)isImage:(NSString*)file
|
||||
{
|
||||
NSString *mimeType=[GLFileView mimeTypeForFileName:file];
|
||||
|
||||
+46
-18
@@ -11,6 +11,19 @@
|
||||
|
||||
@implementation PBGitXProtocol
|
||||
|
||||
- (id)initWithRequest:(NSURLRequest *)request cachedResponse:(NSCachedURLResponse *)cachedResponse client:(id <NSURLProtocolClient>)client
|
||||
{
|
||||
// work around for NSURLProtocol bug
|
||||
// note that this leaks!
|
||||
CFRetain(client);
|
||||
|
||||
if (self = [super initWithRequest:request cachedResponse:cachedResponse client:client])
|
||||
{
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
+ (BOOL) canInitWithRequest:(NSURLRequest *)request
|
||||
{
|
||||
return [[[request URL] scheme] isEqualToString:@"GitX"];
|
||||
@@ -31,25 +44,40 @@
|
||||
return;
|
||||
}
|
||||
|
||||
NSString *path=[[url path] substringFromIndex:1];
|
||||
NSString *v=@"";
|
||||
if ([[path substringToIndex:5] isEqualToString:@"prev/"]) {
|
||||
path=[path substringFromIndex:5];
|
||||
v=@"^";
|
||||
if ([[url host] isEqualToString:@"app"]) {
|
||||
NSString *app=[[url path] substringFromIndex:1];
|
||||
NSString *appPath=[[NSWorkspace sharedWorkspace] fullPathForApplication:app];
|
||||
NSLog(@"app=%@ appPath=%@",app,appPath);
|
||||
if(appPath){
|
||||
NSImage *icon = [[NSWorkspace sharedWorkspace] iconForFile:appPath];
|
||||
NSLog(@"icon=%@",icon);
|
||||
[[self client] URLProtocol:self didLoadData:[icon TIFFRepresentation]];
|
||||
[[self client] URLProtocolDidFinishLoading:self];
|
||||
}else{
|
||||
[[self client] URLProtocol:self didFailWithError:[NSError errorWithDomain:@"gitx" code:404 userInfo:nil]];
|
||||
}
|
||||
}else {
|
||||
|
||||
NSString *path=[[url path] substringFromIndex:1];
|
||||
NSString *v=@"";
|
||||
if ([[path substringToIndex:5] isEqualToString:@"prev/"]) {
|
||||
path=[path substringFromIndex:5];
|
||||
v=@"^";
|
||||
}
|
||||
NSString *specifier = [NSString stringWithFormat:@"%@%@:%@", [url host], v,path];
|
||||
handle = [repo handleInWorkDirForArguments:[NSArray arrayWithObjects:@"cat-file", @"blob", specifier, nil]];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFinishFileLoad:) name:NSFileHandleReadToEndOfFileCompletionNotification object:handle];
|
||||
[handle readToEndOfFileInBackgroundAndNotify];
|
||||
|
||||
NSURLResponse *response = [[NSURLResponse alloc] initWithURL:[[self request] URL]
|
||||
MIMEType:nil
|
||||
expectedContentLength:-1
|
||||
textEncodingName:nil];
|
||||
|
||||
[[self client] URLProtocol:self
|
||||
didReceiveResponse:response
|
||||
cacheStoragePolicy:NSURLCacheStorageNotAllowed];
|
||||
}
|
||||
NSString *specifier = [NSString stringWithFormat:@"%@%@:%@", [url host], v,path];
|
||||
handle = [repo handleInWorkDirForArguments:[NSArray arrayWithObjects:@"cat-file", @"blob", specifier, nil]];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFinishFileLoad:) name:NSFileHandleReadToEndOfFileCompletionNotification object:handle];
|
||||
[handle readToEndOfFileInBackgroundAndNotify];
|
||||
|
||||
NSURLResponse *response = [[NSURLResponse alloc] initWithURL:[[self request] URL]
|
||||
MIMEType:nil
|
||||
expectedContentLength:-1
|
||||
textEncodingName:nil];
|
||||
|
||||
[[self client] URLProtocol:self
|
||||
didReceiveResponse:response
|
||||
cacheStoragePolicy:NSURLCacheStorageNotAllowed];
|
||||
}
|
||||
|
||||
- (void) didFinishFileLoad:(NSNotification *)notification
|
||||
|
||||
@@ -76,6 +76,11 @@
|
||||
NSLog(@"Error from webkit: %@", dictionary);
|
||||
}
|
||||
|
||||
- (void)webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame
|
||||
{
|
||||
NSLog(@"Message from webkit: %@", message);
|
||||
}
|
||||
|
||||
- (NSURLRequest *)webView:(WebView *)sender
|
||||
resource:(id)identifier
|
||||
willSendRequest:(NSURLRequest *)request
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
- (NSString *)parseHeader:(NSString *)txt withRefs:(NSString *)badges;
|
||||
- (NSMutableDictionary *)parseStats:(NSString *)txt;
|
||||
- (NSString *) someMethodThatReturnsSomeHashForSomeString:(NSString*)concat;
|
||||
- (void) openFileMerge:(NSString*)file sha:(NSString *)sha;
|
||||
|
||||
@property (readonly) NSString* diff;
|
||||
@end
|
||||
|
||||
@@ -224,6 +224,13 @@
|
||||
[historyController selectCommit:[PBGitSHA shaWithString:sha]];
|
||||
}
|
||||
|
||||
- (void) openFileMerge:(NSString*)file sha:(NSString *)sha
|
||||
{
|
||||
NSArray *args=[NSArray arrayWithObjects:@"difftool",@"--no-prompt",@"--tool=opendiff",[NSString stringWithFormat:@"%@^",sha],sha,file,nil];
|
||||
[historyController.repository handleForArguments:args];
|
||||
}
|
||||
|
||||
|
||||
- (void) sendKey: (NSString*) key
|
||||
{
|
||||
id script = [view windowScriptObject];
|
||||
|
||||
@@ -317,4 +317,9 @@ a.showdiff {
|
||||
-webkit-box-shadow: 5px 5px 5px #ccc;
|
||||
width: 98%;
|
||||
margin: auto auto 20px 1%;
|
||||
}
|
||||
|
||||
.filemerge {
|
||||
float: right;
|
||||
text-align: center;
|
||||
}
|
||||
@@ -2,6 +2,12 @@ var selectCommit = function(a) {
|
||||
Controller.selectCommit_(a);
|
||||
}
|
||||
|
||||
var openFileMerge = function(file,sha) {
|
||||
alert(file);
|
||||
alert(sha);
|
||||
Controller.openFileMerge_sha_(file,sha);
|
||||
}
|
||||
|
||||
var showImage = function(element, filename)
|
||||
{
|
||||
element.outerHTML = '<img src="GitX://' + commit.sha + '/' + filename + '">';
|
||||
|
||||
Reference in New Issue
Block a user