Skip to content

Commit 20d04e0

Browse files
committed
Merge branch 'master' of https://github.com/laullon/gitx
2 parents 2d363d1 + 9057911 commit 20d04e0

File tree

6 files changed

+58
-23
lines changed

6 files changed

+58
-23
lines changed

GLFileView.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
+(BOOL)isStartDiff:(NSString *)line;
3737
+(BOOL)isStartBlock:(NSString *)line;
3838

39+
+(NSArray *)getFilesNames:(NSString *)line;
40+
+(BOOL)isBinaryFile:(NSString *)line;
41+
+(NSString*)mimeTypeForFileName:(NSString*)file;
42+
+(BOOL)isImage:(NSString*)file;
43+
3944
@property(retain) NSMutableArray *groups;
4045
@property(retain) NSString *logFormat;
4146

GLFileView.m

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ - (MGScopeBarGroupSelectionMode)scopeBar:(MGScopeBar *)theScopeBar selectionMode
181181

182182
- (void)scopeBar:(MGScopeBar *)theScopeBar selectedStateChanged:(BOOL)selected forItem:(NSString *)identifier inGroup:(int)groupNumber
183183
{
184-
NSLog(@"startFile=%@ identifier=%@ groupNumber=%d",startFile,identifier,groupNumber);
185184
if((groupNumber==0) && (startFile!=identifier)){
186185
NSString *path = [NSString stringWithFormat:@"html/views/%@", identifier];
187186
NSString *html = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:path];
@@ -238,11 +237,10 @@ + (NSString *)parseDiffTree:(NSString *)txt withStats:(NSMutableDictionary *)sta
238237
NSArray *lines = [txt componentsSeparatedByString:@"\n"];
239238
NSMutableString *res=[NSMutableString string];
240239
[res appendString:@"<table id='filelist'>"];
241-
int i;
242-
for (i=1; i<[lines count]; i++) {
243-
NSString *line=[lines objectAtIndex:i];
244-
NSArray *fields=[line componentsSeparatedByString:@" "];
245-
NSArray *fileStatus=[[fields objectAtIndex:4] componentsSeparatedByString:@"\t"];
240+
for (NSString *line in lines) {
241+
if([line length]<98) continue;
242+
line=[line substringFromIndex:97];
243+
NSArray *fileStatus=[line componentsSeparatedByString:@"\t"];
246244
NSString *status=[[fileStatus objectAtIndex:0] substringToIndex:1]; // ignore the score
247245
NSString *file=[fileStatus objectAtIndex:1];
248246
NSString *txt=file;
@@ -331,17 +329,19 @@ + (NSString *)parseDiff:(NSString *)txt
331329
}else if(inDiff){
332330
[res appendString:[NSString stringWithFormat:@"<p>%@</p>",line]];
333331
if([self isBinaryFile:line]){
334-
NSLog(@"line='%@'",line);
335332
[res appendString:@"</td></tr></thead><tbody>"];
336333
NSArray *files=[self getFilesNames:line];
337-
NSLog(@"files='%@'",files);
338334
if(![[files objectAtIndex:0] isAbsolutePath]){
339335
[res appendString:[NSString stringWithFormat:@"<tr><td colspan='3'>%@</td></tr>",[files objectAtIndex:0]]];
340-
[res appendString:[NSString stringWithFormat:@"<tr><td colspan='3'><img src='GitX://{SHA}:/prev/%@'/></td></tr>",[files objectAtIndex:0]]];
336+
if([GLFileView isImage:[files objectAtIndex:0]]){
337+
[res appendString:[NSString stringWithFormat:@"<tr><td colspan='3'><img src='GitX://{SHA}:/prev/%@'/></td></tr>",[files objectAtIndex:0]]];
338+
}
341339
}
342340
if(![[files objectAtIndex:1] isAbsolutePath]){
343341
[res appendString:[NSString stringWithFormat:@"<tr><td colspan='3'>%@</td></tr>",[files objectAtIndex:1]]];
344-
[res appendString:[NSString stringWithFormat:@"<tr><td colspan='3'><img src='GitX://{SHA}/%@'/></td></tr>",[files objectAtIndex:1]]];
342+
if([GLFileView isImage:[files objectAtIndex:1]]){
343+
[res appendString:[NSString stringWithFormat:@"<tr><td colspan='3'><img src='GitX://{SHA}/%@'/></td></tr>",[files objectAtIndex:1]]];
344+
}
345345
}
346346
}
347347
}
@@ -362,7 +362,6 @@ +(NSArray *)getFilesNames:(NSString *)line
362362
{
363363
NSString *a;
364364
NSString *b;
365-
NSLog(@"line='%@'",line);
366365
NSScanner *scanner=[NSScanner scannerWithString:line];
367366
if([scanner scanString:@"Binary files " intoString:NULL]){
368367
[scanner scanUpToString:@" and" intoString:&a];
@@ -375,10 +374,34 @@ +(NSArray *)getFilesNames:(NSString *)line
375374
if (![b isAbsolutePath]) {
376375
b=[b substringFromIndex:2];
377376
}
378-
377+
379378
return [NSArray arrayWithObjects:a,b,nil];
380379
}
381380

381+
+(NSString*)mimeTypeForFileName:(NSString*)name
382+
{
383+
NSString *mimeType = nil;
384+
NSInteger i=[name rangeOfString:@"." options:NSBackwardsSearch].location;
385+
if(i!=NSNotFound){
386+
NSString *ext=[name substringFromIndex:i+1];
387+
CFStringRef UTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (CFStringRef)ext, NULL);
388+
if(UTI){
389+
CFStringRef registeredType = UTTypeCopyPreferredTagWithClass(UTI, kUTTagClassMIMEType);
390+
if(registeredType){
391+
mimeType = NSMakeCollectable(registeredType);
392+
}
393+
CFRelease(UTI);
394+
}
395+
}
396+
return mimeType;
397+
}
398+
399+
+(BOOL)isImage:(NSString*)file
400+
{
401+
NSString *mimeType=[GLFileView mimeTypeForFileName:file];
402+
return (mimeType!=nil) && ([mimeType rangeOfString:@"image/" options:NSCaseInsensitiveSearch].location!=NSNotFound);
403+
}
404+
382405
+(BOOL)isBinaryFile:(NSString *)line
383406
{
384407
return (([line length]>12) && [[line substringToIndex:12] isEqualToString:@"Binary files"]);

PBGitHistoryList.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ - (BOOL) selectedBranchNeedsNewGraph:(PBGitRevSpecifier *)rev
287287

288288
- (BOOL) haveRefsBeenModified
289289
{
290-
[repository reloadRefs];
290+
//[repository reloadRefs];
291291

292292
NSMutableSet *currentRefSHAs = [NSMutableSet setWithArray:[repository.refs allKeys]];
293293
[currentRefSHAs minusSet:lastRefSHAs];

PBGitRepository.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ static NSString * PBStringFromBranchFilterType(PBGitXBranchFilterType type) {
129129
- (void)findInModeScriptCommand:(NSScriptCommand *)command;
130130

131131
-(NSNumber *)countCommintsOf:(NSString *)branchs;
132-
+(bool)isLocalBranch:(NSString *)name;
132+
+(bool)isLocalBranch:(NSString *)branch branchNameInto:(NSString **)name;
133133

134134

135135
@property (assign) BOOL hasChanged;

PBGitRepository.m

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,10 @@ - (void) reloadRefs
269269
PBGitRef *newRef = [PBGitRef refFromString:[components objectAtIndex:0]];
270270
PBGitRevSpecifier *revSpec = [[PBGitRevSpecifier alloc] initWithRef:newRef];
271271

272-
if([PBGitRepository isLocalBranch:[components objectAtIndex:0]]){
273-
[revSpec setAhead:[self countCommintsOf:[NSString stringWithFormat:@"origin..%@",[components objectAtIndex:0]]]];
274-
[revSpec setBehind:[self countCommintsOf:[NSString stringWithFormat:@"%@..origin",[components objectAtIndex:0]]]];
272+
NSString *bName;
273+
if([PBGitRepository isLocalBranch:[components objectAtIndex:0] branchNameInto:&bName]){
274+
[revSpec setAhead:[self countCommintsOf:[NSString stringWithFormat:@"origin/%@..%@",bName,bName]]];
275+
[revSpec setBehind:[self countCommintsOf:[NSString stringWithFormat:@"%@..origin/%@",bName,bName]]];
275276
}
276277
[self addBranch:revSpec];
277278
[self addRef:newRef fromParameters:components];
@@ -288,17 +289,23 @@ - (void) reloadRefs
288289
[[[self windowController] window] setTitle:[self displayName]];
289290
}
290291

291-
+(bool)isLocalBranch:(NSString *)name
292+
+(bool)isLocalBranch:(NSString *)branch branchNameInto:(NSString **)name
292293
{
293-
NSScanner *scanner=[NSScanner scannerWithString:name];
294-
return [scanner scanString:@"refs/heads/" intoString:NULL];
294+
NSScanner *scanner=[NSScanner scannerWithString:branch];
295+
bool is=[scanner scanString:@"refs/heads/" intoString:NULL];
296+
if(is && (name)){
297+
*name=[branch substringFromIndex:[scanner scanLocation]];
298+
}
299+
return is;
295300
}
296301

297302
-(NSNumber *)countCommintsOf:(NSString *)branchs
298303
{
304+
NSLog(@"branchs:'%@'",branchs);
299305
NSArray *args = [NSArray arrayWithObjects:@"rev-list", branchs, nil];
300-
NSString *o = [self outputForArguments:args];
301-
if ([o length]==0) {
306+
int ret;
307+
NSString *o = [self outputForArguments:args retValue:&ret];
308+
if ((ret!=0) || ([o length]==0)) {
302309
return NULL;
303310
}
304311
NSArray *commits = [o componentsSeparatedByString:@"\n"];

PBGitSidebarController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,8 @@ - (BOOL)outlineView:(NSOutlineView *)outlineView isGroupItem:(id)item
223223

224224
- (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(PBSourceViewCell *)cell forTableColumn:(NSTableColumn *)tableColumn item:(PBSourceViewItem *)item
225225
{
226+
cell.isCheckedOut = [item.revSpecifier isEqual:[repository headRef]];
226227
if(item.revSpecifier!=NULL){
227-
cell.isCheckedOut = [item.revSpecifier isEqual:[repository headRef]];
228228
cell.behind=[item.revSpecifier behind];
229229
cell.ahead=[item.revSpecifier ahead];
230230
}else{

0 commit comments

Comments
 (0)