mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
images on diff
This commit is contained in:
@@ -31,6 +31,8 @@
|
||||
+ (NSString *)parseHTML:(NSString *)txt;
|
||||
+ (NSString *)parseDiff:(NSString *)txt;
|
||||
+ (NSString *)parseDiffTree:(NSString *)txt withStats:(NSMutableDictionary *)stats;
|
||||
+ (NSString *)getFileName:(NSString *)line;
|
||||
|
||||
+(BOOL)isStartDiff:(NSString *)line;
|
||||
+(BOOL)isStartBlock:(NSString *)line;
|
||||
|
||||
|
||||
+43
-2
@@ -225,7 +225,7 @@
|
||||
|
||||
+ (NSString *)parseDiffTree:(NSString *)txt withStats:(NSMutableDictionary *)stats
|
||||
{
|
||||
NSInteger granTotal=0;
|
||||
NSInteger granTotal=1;
|
||||
for(NSArray *stat in [stats allValues]){
|
||||
NSInteger add=[[stat objectAtIndex:0] integerValue];
|
||||
NSInteger rem=[[stat objectAtIndex:1] integerValue];
|
||||
@@ -330,6 +330,20 @@
|
||||
[res appendString:[NSString stringWithFormat:@"<p>%@</p>",line]];
|
||||
}else if(inDiff){
|
||||
[res appendString:[NSString stringWithFormat:@"<p>%@</p>",line]];
|
||||
if([self isBinaryFile:line]){
|
||||
NSLog(@"line='%@'",line);
|
||||
[res appendString:@"</td></tr></thead><tbody>"];
|
||||
NSArray *files=[self getFilesNames:line];
|
||||
NSLog(@"files='%@'",files);
|
||||
if(![[files objectAtIndex:0] isAbsolutePath]){
|
||||
[res appendString:[NSString stringWithFormat:@"<tr><td colspan='3'>%@</td></tr>",[files objectAtIndex:0]]];
|
||||
[res appendString:[NSString stringWithFormat:@"<tr><td colspan='3'><img src='GitX://{SHA}:/prev/%@'/></td></tr>",[files objectAtIndex:0]]];
|
||||
}
|
||||
if(![[files objectAtIndex:1] isAbsolutePath]){
|
||||
[res appendString:[NSString stringWithFormat:@"<tr><td colspan='3'>%@</td></tr>",[files objectAtIndex:1]]];
|
||||
[res appendString:[NSString stringWithFormat:@"<tr><td colspan='3'><img src='GitX://{SHA}/%@'/></td></tr>",[files objectAtIndex:1]]];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(inDiff)
|
||||
@@ -337,12 +351,39 @@
|
||||
return res;
|
||||
}
|
||||
|
||||
+(NSString *)getFileName:(NSString *)line{
|
||||
+(NSString *)getFileName:(NSString *)line
|
||||
{
|
||||
NSRange b = [line rangeOfString:@"b/"];
|
||||
NSString *file=[line substringFromIndex:b.location+2];
|
||||
return file;
|
||||
}
|
||||
|
||||
+(NSArray *)getFilesNames:(NSString *)line
|
||||
{
|
||||
NSString *a;
|
||||
NSString *b;
|
||||
NSLog(@"line='%@'",line);
|
||||
NSScanner *scanner=[NSScanner scannerWithString:line];
|
||||
if([scanner scanString:@"Binary files " intoString:NULL]){
|
||||
[scanner scanUpToString:@" and" intoString:&a];
|
||||
[scanner scanString:@"and" intoString:NULL];
|
||||
[scanner scanUpToString:@" differ" intoString:&b];
|
||||
}
|
||||
if (![a isAbsolutePath]) {
|
||||
a=[a substringFromIndex:2];
|
||||
}
|
||||
if (![b isAbsolutePath]) {
|
||||
b=[b substringFromIndex:2];
|
||||
}
|
||||
|
||||
return [NSArray arrayWithObjects:a,b,nil];
|
||||
}
|
||||
|
||||
+(BOOL)isBinaryFile:(NSString *)line
|
||||
{
|
||||
return (([line length]>12) && [[line substringToIndex:12] isEqualToString:@"Binary files"]);
|
||||
}
|
||||
|
||||
+(BOOL)isStartDiff:(NSString *)line
|
||||
{
|
||||
return (([line length]>10) && [[line substringToIndex:10] isEqualToString:@"diff --git"]);
|
||||
|
||||
+11
-5
@@ -25,22 +25,28 @@
|
||||
{
|
||||
NSURL *url = [[self request] URL];
|
||||
PBGitRepository *repo = [[self request] repository];
|
||||
|
||||
|
||||
if(!repo) {
|
||||
[[self client] URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:0 userInfo:nil]];
|
||||
return;
|
||||
}
|
||||
|
||||
NSString *specifier = [NSString stringWithFormat:@"%@:%@", [url host], [[url path] substringFromIndex:1]];
|
||||
|
||||
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];
|
||||
|
||||
@@ -116,6 +116,8 @@
|
||||
|
||||
NSString *html=[NSString stringWithFormat:@"%@%@<div id='diffs'>%@</div>",header,fileList,diffs];
|
||||
|
||||
html=[html stringByReplacingOccurrencesOfString:@"{SHA}" withString:[currentSha string]];
|
||||
|
||||
[[view windowScriptObject] callWebScriptMethod:@"showCommit" withArguments:[NSArray arrayWithObject:html]];
|
||||
|
||||
#if 1
|
||||
|
||||
Reference in New Issue
Block a user