Skip to content

Commit d02caf4

Browse files
committed
Merge branch 'master' into experimental
Conflicts: PBGitRepository.h PBGitSidebarController.m PBSourceViewCell.h PBSourceViewCell.m
2 parents e28ed65 + c221c64 commit d02caf4

15 files changed

+171
-97
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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,7 @@ static NSString * PBStringFromBranchFilterType(PBGitXBranchFilterType type) {
146146
- (void)findInModeScriptCommand:(NSScriptCommand *)command;
147147

148148
-(NSNumber *)countCommintsOf:(NSString *)branchs;
149-
+(bool)isLocalBranch:(NSString *)name;
150-
- (NSMenu *) menu;
149+
+(bool)isLocalBranch:(NSString *)branch branchNameInto:(NSString **)name;
151150

152151
@property (assign) BOOL hasChanged;
153152
@property (readonly) PBGitWindowController *windowController;

PBGitRepository.m

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,6 @@ - (void) reloadRefs
300300
PBGitRef *newRef = [PBGitRef refFromString:[components objectAtIndex:0]];
301301
PBGitRevSpecifier *revSpec = [[PBGitRevSpecifier alloc] initWithRef:newRef];
302302

303-
if([PBGitRepository isLocalBranch:[components objectAtIndex:0]]){
304-
[revSpec setAhead:[self countCommintsOf:[NSString stringWithFormat:@"origin..%@",[components objectAtIndex:0]]]];
305-
[revSpec setBehind:[self countCommintsOf:[NSString stringWithFormat:@"%@..origin",[components objectAtIndex:0]]]];
306-
}
307303
[self addBranch:revSpec];
308304
[self addRef:newRef fromParameters:components];
309305
[oldBranches removeObject:revSpec];
@@ -322,21 +318,14 @@ - (void) reloadRefs
322318
[[[self windowController] window] setTitle:[self displayName]];
323319
}
324320

325-
+(bool)isLocalBranch:(NSString *)name
321+
+(bool)isLocalBranch:(NSString *)branch branchNameInto:(NSString **)name
326322
{
327-
NSScanner *scanner=[NSScanner scannerWithString:name];
328-
return [scanner scanString:@"refs/heads/" intoString:NULL];
329-
}
330-
331-
-(NSNumber *)countCommintsOf:(NSString *)branchs
332-
{
333-
NSArray *args = [NSArray arrayWithObjects:@"rev-list", branchs, nil];
334-
NSString *o = [self outputForArguments:args];
335-
if ([o length]==0) {
336-
return NULL;
323+
NSScanner *scanner=[NSScanner scannerWithString:branch];
324+
bool is=[scanner scanString:@"refs/heads/" intoString:NULL];
325+
if(is && (name)){
326+
*name=[branch substringFromIndex:[scanner scanLocation]];
337327
}
338-
NSArray *commits = [o componentsSeparatedByString:@"\n"];
339-
return [NSNumber numberWithInt:[commits count]];
328+
return is;
340329
}
341330

342331
- (void) lazyReload

PBGitSVBranchItem.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,15 @@
1111

1212

1313
@interface PBGitSVBranchItem : PBSourceViewItem {
14-
14+
BOOL isCheckedOut;
15+
NSNumber *behind;
16+
NSNumber *ahead;
1517
}
1618

1719
+ (id)branchItemWithRevSpec:(PBGitRevSpecifier *)revSpecifier;
1820

21+
@property (assign) BOOL isCheckedOut;
22+
@property (assign) NSNumber *behind;
23+
@property (assign) NSNumber *ahead;
24+
1925
@end

PBGitSVBranchItem.m

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
@implementation PBGitSVBranchItem
1313

14+
@synthesize isCheckedOut;
15+
@synthesize behind,ahead;
1416

1517
+ (id)branchItemWithRevSpec:(PBGitRevSpecifier *)revSpecifier
1618
{
@@ -30,4 +32,17 @@ - (NSImage *) icon
3032
return branchImage;
3133
}
3234

35+
36+
- (NSString *) badge{
37+
NSMutableString *badge=nil;
38+
if(isCheckedOut || ahead || behind){
39+
badge=[NSMutableString string];
40+
if(isCheckedOut) [badge appendString:@""];
41+
if(ahead) [badge appendFormat:@"+%@",ahead];
42+
if(behind) [badge appendFormat:@"-%@",behind];
43+
}
44+
return badge;
45+
}
46+
47+
3348
@end

PBGitSVRemoteItem.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111

1212

1313
@interface PBGitSVRemoteItem : PBSourceViewItem {
14-
14+
BOOL alert;
1515
}
1616

17+
@property (assign) BOOL alert;
18+
1719
+ (id)remoteItemWithTitle:(NSString *)title;
1820

1921
@end

PBGitSVRemoteItem.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
@implementation PBGitSVRemoteItem
1414

15+
@synthesize alert;
1516

1617
+ (id)remoteItemWithTitle:(NSString *)title
1718
{
@@ -38,4 +39,8 @@ - (PBGitRef *) ref
3839
return [PBGitRef refFromString:[kGitXRemoteRefPrefix stringByAppendingString:self.title]];
3940
}
4041

42+
- (NSString *)badge
43+
{
44+
return (alert ? @"!" : nil);
45+
}
4146
@end

PBGitSidebarController.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747

4848
- (void)setHistorySearch:(NSString *)searchString mode:(NSInteger)mode;
4949

50+
-(NSNumber *)countCommintsOf:(NSString *)range;
51+
-(bool)remoteNeedFetch:(NSString *)remote;
52+
5053
@property(readonly) NSMutableArray *items;
5154
@property(readonly) NSView *sourceListControlsView;
5255
@property(readonly) PBGitHistoryController *historyViewController;

0 commit comments

Comments
 (0)