diff --git a/GLFileView.h b/GLFileView.h
index dfeb15e..7dd9125 100644
--- a/GLFileView.h
+++ b/GLFileView.h
@@ -36,6 +36,11 @@
+(BOOL)isStartDiff:(NSString *)line;
+(BOOL)isStartBlock:(NSString *)line;
++(NSArray *)getFilesNames:(NSString *)line;
++(BOOL)isBinaryFile:(NSString *)line;
++(NSString*)mimeTypeForFileName:(NSString*)file;
++(BOOL)isImage:(NSString*)file;
+
@property(retain) NSMutableArray *groups;
@property(retain) NSString *logFormat;
diff --git a/GLFileView.m b/GLFileView.m
index 3c114f2..a4b6ba0 100644
--- a/GLFileView.m
+++ b/GLFileView.m
@@ -181,7 +181,6 @@
- (void)scopeBar:(MGScopeBar *)theScopeBar selectedStateChanged:(BOOL)selected forItem:(NSString *)identifier inGroup:(int)groupNumber
{
- NSLog(@"startFile=%@ identifier=%@ groupNumber=%d",startFile,identifier,groupNumber);
if((groupNumber==0) && (startFile!=identifier)){
NSString *path = [NSString stringWithFormat:@"html/views/%@", identifier];
NSString *html = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:path];
@@ -238,11 +237,10 @@
NSArray *lines = [txt componentsSeparatedByString:@"\n"];
NSMutableString *res=[NSMutableString string];
[res appendString:@"
"];
- int i;
- for (i=1; i<[lines count]; i++) {
- NSString *line=[lines objectAtIndex:i];
- NSArray *fields=[line componentsSeparatedByString:@" "];
- NSArray *fileStatus=[[fields objectAtIndex:4] componentsSeparatedByString:@"\t"];
+ for (NSString *line in lines) {
+ if([line length]<98) continue;
+ line=[line substringFromIndex:97];
+ NSArray *fileStatus=[line componentsSeparatedByString:@"\t"];
NSString *status=[[fileStatus objectAtIndex:0] substringToIndex:1]; // ignore the score
NSString *file=[fileStatus objectAtIndex:1];
NSString *txt=file;
@@ -331,17 +329,19 @@
}else if(inDiff){
[res appendString:[NSString stringWithFormat:@"%@
",line]];
if([self isBinaryFile:line]){
- NSLog(@"line='%@'",line);
[res appendString:@""];
NSArray *files=[self getFilesNames:line];
- NSLog(@"files='%@'",files);
if(![[files objectAtIndex:0] isAbsolutePath]){
[res appendString:[NSString stringWithFormat:@"| %@ |
",[files objectAtIndex:0]]];
- [res appendString:[NSString stringWithFormat:@" |
",[files objectAtIndex:0]]];
+ if([GLFileView isImage:[files objectAtIndex:0]]){
+ [res appendString:[NSString stringWithFormat:@" |
",[files objectAtIndex:0]]];
+ }
}
if(![[files objectAtIndex:1] isAbsolutePath]){
[res appendString:[NSString stringWithFormat:@"| %@ |
",[files objectAtIndex:1]]];
- [res appendString:[NSString stringWithFormat:@" |
",[files objectAtIndex:1]]];
+ if([GLFileView isImage:[files objectAtIndex:1]]){
+ [res appendString:[NSString stringWithFormat:@" |
",[files objectAtIndex:1]]];
+ }
}
}
}
@@ -362,7 +362,6 @@
{
NSString *a;
NSString *b;
- NSLog(@"line='%@'",line);
NSScanner *scanner=[NSScanner scannerWithString:line];
if([scanner scanString:@"Binary files " intoString:NULL]){
[scanner scanUpToString:@" and" intoString:&a];
@@ -375,10 +374,34 @@
if (![b isAbsolutePath]) {
b=[b substringFromIndex:2];
}
-
+
return [NSArray arrayWithObjects:a,b,nil];
}
++(NSString*)mimeTypeForFileName:(NSString*)name
+{
+ NSString *mimeType = nil;
+ NSInteger i=[name rangeOfString:@"." options:NSBackwardsSearch].location;
+ if(i!=NSNotFound){
+ NSString *ext=[name substringFromIndex:i+1];
+ CFStringRef UTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (CFStringRef)ext, NULL);
+ if(UTI){
+ CFStringRef registeredType = UTTypeCopyPreferredTagWithClass(UTI, kUTTagClassMIMEType);
+ if(registeredType){
+ mimeType = NSMakeCollectable(registeredType);
+ }
+ CFRelease(UTI);
+ }
+ }
+ return mimeType;
+}
+
++(BOOL)isImage:(NSString*)file
+{
+ NSString *mimeType=[GLFileView mimeTypeForFileName:file];
+ return (mimeType!=nil) && ([mimeType rangeOfString:@"image/" options:NSCaseInsensitiveSearch].location!=NSNotFound);
+}
+
+(BOOL)isBinaryFile:(NSString *)line
{
return (([line length]>12) && [[line substringToIndex:12] isEqualToString:@"Binary files"]);
diff --git a/PBGitHistoryList.m b/PBGitHistoryList.m
index 0a4433f..0ab1324 100644
--- a/PBGitHistoryList.m
+++ b/PBGitHistoryList.m
@@ -287,7 +287,7 @@
- (BOOL) haveRefsBeenModified
{
- [repository reloadRefs];
+ //[repository reloadRefs];
NSMutableSet *currentRefSHAs = [NSMutableSet setWithArray:[repository.refs allKeys]];
[currentRefSHAs minusSet:lastRefSHAs];
diff --git a/PBGitRepository.h b/PBGitRepository.h
index a16acc0..9c61a60 100644
--- a/PBGitRepository.h
+++ b/PBGitRepository.h
@@ -129,7 +129,7 @@ static NSString * PBStringFromBranchFilterType(PBGitXBranchFilterType type) {
- (void)findInModeScriptCommand:(NSScriptCommand *)command;
-(NSNumber *)countCommintsOf:(NSString *)branchs;
-+(bool)isLocalBranch:(NSString *)name;
++(bool)isLocalBranch:(NSString *)branch branchNameInto:(NSString **)name;
@property (assign) BOOL hasChanged;
diff --git a/PBGitRepository.m b/PBGitRepository.m
index edec8ec..01992c8 100644
--- a/PBGitRepository.m
+++ b/PBGitRepository.m
@@ -269,9 +269,10 @@ NSString* PBGitRepositoryErrorDomain = @"GitXErrorDomain";
PBGitRef *newRef = [PBGitRef refFromString:[components objectAtIndex:0]];
PBGitRevSpecifier *revSpec = [[PBGitRevSpecifier alloc] initWithRef:newRef];
- if([PBGitRepository isLocalBranch:[components objectAtIndex:0]]){
- [revSpec setAhead:[self countCommintsOf:[NSString stringWithFormat:@"origin..%@",[components objectAtIndex:0]]]];
- [revSpec setBehind:[self countCommintsOf:[NSString stringWithFormat:@"%@..origin",[components objectAtIndex:0]]]];
+ NSString *bName;
+ if([PBGitRepository isLocalBranch:[components objectAtIndex:0] branchNameInto:&bName]){
+ [revSpec setAhead:[self countCommintsOf:[NSString stringWithFormat:@"origin/%@..%@",bName,bName]]];
+ [revSpec setBehind:[self countCommintsOf:[NSString stringWithFormat:@"%@..origin/%@",bName,bName]]];
}
[self addBranch:revSpec];
[self addRef:newRef fromParameters:components];
@@ -288,17 +289,23 @@ NSString* PBGitRepositoryErrorDomain = @"GitXErrorDomain";
[[[self windowController] window] setTitle:[self displayName]];
}
-+(bool)isLocalBranch:(NSString *)name
++(bool)isLocalBranch:(NSString *)branch branchNameInto:(NSString **)name
{
- NSScanner *scanner=[NSScanner scannerWithString:name];
- return [scanner scanString:@"refs/heads/" intoString:NULL];
+ NSScanner *scanner=[NSScanner scannerWithString:branch];
+ bool is=[scanner scanString:@"refs/heads/" intoString:NULL];
+ if(is && (name)){
+ *name=[branch substringFromIndex:[scanner scanLocation]];
+ }
+ return is;
}
-(NSNumber *)countCommintsOf:(NSString *)branchs
{
+ NSLog(@"branchs:'%@'",branchs);
NSArray *args = [NSArray arrayWithObjects:@"rev-list", branchs, nil];
- NSString *o = [self outputForArguments:args];
- if ([o length]==0) {
+ int ret;
+ NSString *o = [self outputForArguments:args retValue:&ret];
+ if ((ret!=0) || ([o length]==0)) {
return NULL;
}
NSArray *commits = [o componentsSeparatedByString:@"\n"];
diff --git a/PBGitSidebarController.m b/PBGitSidebarController.m
index 301bf16..9f33709 100644
--- a/PBGitSidebarController.m
+++ b/PBGitSidebarController.m
@@ -223,8 +223,8 @@
- (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(PBSourceViewCell *)cell forTableColumn:(NSTableColumn *)tableColumn item:(PBSourceViewItem *)item
{
+ cell.isCheckedOut = [item.revSpecifier isEqual:[repository headRef]];
if(item.revSpecifier!=NULL){
- cell.isCheckedOut = [item.revSpecifier isEqual:[repository headRef]];
cell.behind=[item.revSpecifier behind];
cell.ahead=[item.revSpecifier ahead];
}else{