Skip to content

Commit 2d363d1

Browse files
committed
Merge branch 'master' of https://github.com/laullon/gitx
2 parents 15584e1 + b27378f commit 2d363d1

12 files changed

+113
-16
lines changed

GLFileView.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
+ (NSString *)parseHTML:(NSString *)txt;
3232
+ (NSString *)parseDiff:(NSString *)txt;
3333
+ (NSString *)parseDiffTree:(NSString *)txt withStats:(NSMutableDictionary *)stats;
34+
+ (NSString *)getFileName:(NSString *)line;
35+
3436
+(BOOL)isStartDiff:(NSString *)line;
3537
+(BOOL)isStartBlock:(NSString *)line;
3638

GLFileView.m

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ + (NSString *) parseHTML:(NSString *)txt
225225

226226
+ (NSString *)parseDiffTree:(NSString *)txt withStats:(NSMutableDictionary *)stats
227227
{
228-
NSInteger granTotal=0;
228+
NSInteger granTotal=1;
229229
for(NSArray *stat in [stats allValues]){
230230
NSInteger add=[[stat objectAtIndex:0] integerValue];
231231
NSInteger rem=[[stat objectAtIndex:1] integerValue];
@@ -330,19 +330,60 @@ + (NSString *)parseDiff:(NSString *)txt
330330
[res appendString:[NSString stringWithFormat:@"<p>%@</p>",line]];
331331
}else if(inDiff){
332332
[res appendString:[NSString stringWithFormat:@"<p>%@</p>",line]];
333+
if([self isBinaryFile:line]){
334+
NSLog(@"line='%@'",line);
335+
[res appendString:@"</td></tr></thead><tbody>"];
336+
NSArray *files=[self getFilesNames:line];
337+
NSLog(@"files='%@'",files);
338+
if(![[files objectAtIndex:0] isAbsolutePath]){
339+
[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]]];
341+
}
342+
if(![[files objectAtIndex:1] isAbsolutePath]){
343+
[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]]];
345+
}
346+
}
333347
}
334348
}
335349
if(inDiff)
336350
[res appendString:@"</tbody></table>"];
337351
return res;
338352
}
339353

340-
+(NSString *)getFileName:(NSString *)line{
354+
+(NSString *)getFileName:(NSString *)line
355+
{
341356
NSRange b = [line rangeOfString:@"b/"];
342357
NSString *file=[line substringFromIndex:b.location+2];
343358
return file;
344359
}
345360

361+
+(NSArray *)getFilesNames:(NSString *)line
362+
{
363+
NSString *a;
364+
NSString *b;
365+
NSLog(@"line='%@'",line);
366+
NSScanner *scanner=[NSScanner scannerWithString:line];
367+
if([scanner scanString:@"Binary files " intoString:NULL]){
368+
[scanner scanUpToString:@" and" intoString:&a];
369+
[scanner scanString:@"and" intoString:NULL];
370+
[scanner scanUpToString:@" differ" intoString:&b];
371+
}
372+
if (![a isAbsolutePath]) {
373+
a=[a substringFromIndex:2];
374+
}
375+
if (![b isAbsolutePath]) {
376+
b=[b substringFromIndex:2];
377+
}
378+
379+
return [NSArray arrayWithObjects:a,b,nil];
380+
}
381+
382+
+(BOOL)isBinaryFile:(NSString *)line
383+
{
384+
return (([line length]>12) && [[line substringToIndex:12] isEqualToString:@"Binary files"]);
385+
}
386+
346387
+(BOOL)isStartDiff:(NSString *)line
347388
{
348389
return (([line length]>10) && [[line substringToIndex:10] isEqualToString:@"diff --git"]);

PBGitRepository.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ static NSString * PBStringFromBranchFilterType(PBGitXBranchFilterType type) {
128128
// for the scripting bridge
129129
- (void)findInModeScriptCommand:(NSScriptCommand *)command;
130130

131+
-(NSNumber *)countCommintsOf:(NSString *)branchs;
132+
+(bool)isLocalBranch:(NSString *)name;
133+
131134

132135
@property (assign) BOOL hasChanged;
133136
@property (readonly) PBGitWindowController *windowController;

PBGitRepository.m

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +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]]]];
275+
}
272276
[self addBranch:revSpec];
273277
[self addRef:newRef fromParameters:components];
274278
[oldBranches removeObject:revSpec];
@@ -284,6 +288,23 @@ - (void) reloadRefs
284288
[[[self windowController] window] setTitle:[self displayName]];
285289
}
286290

291+
+(bool)isLocalBranch:(NSString *)name
292+
{
293+
NSScanner *scanner=[NSScanner scannerWithString:name];
294+
return [scanner scanString:@"refs/heads/" intoString:NULL];
295+
}
296+
297+
-(NSNumber *)countCommintsOf:(NSString *)branchs
298+
{
299+
NSArray *args = [NSArray arrayWithObjects:@"rev-list", branchs, nil];
300+
NSString *o = [self outputForArguments:args];
301+
if ([o length]==0) {
302+
return NULL;
303+
}
304+
NSArray *commits = [o componentsSeparatedByString:@"\n"];
305+
return [NSNumber numberWithInt:[commits count]];
306+
}
307+
287308
- (void) lazyReload
288309
{
289310
if (!hasChanged)

PBGitRevSpecifier.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
NSArray *parameters;
1515
NSURL *workingDirectory;
1616
BOOL isSimpleRef;
17+
NSNumber *behind;
18+
NSNumber *ahead;
1719
}
1820

1921
- (id) initWithParameters:(NSArray *)params description:(NSString *)descrip;
@@ -37,5 +39,7 @@
3739
@property(readonly) NSArray *parameters;
3840
@property(retain) NSURL *workingDirectory;
3941
@property(readonly) BOOL isSimpleRef;
42+
@property(assign) NSNumber *behind;
43+
@property(assign) NSNumber *ahead;
4044

4145
@end

PBGitRevSpecifier.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ @implementation PBGitRevSpecifier
1313

1414
@synthesize parameters, description, workingDirectory;
1515
@synthesize isSimpleRef;
16+
@synthesize behind,ahead;
1617

1718

1819
// internal designated init

PBGitSidebarController.m

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,14 @@ - (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]];
227-
226+
if(item.revSpecifier!=NULL){
227+
cell.isCheckedOut = [item.revSpecifier isEqual:[repository headRef]];
228+
cell.behind=[item.revSpecifier behind];
229+
cell.ahead=[item.revSpecifier ahead];
230+
}else{
231+
cell.behind=nil;
232+
cell.ahead=nil;
233+
}
228234
[cell setImage:[item icon]];
229235
}
230236

PBGitXProtocol.m

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,28 @@ -(void)startLoading
2525
{
2626
NSURL *url = [[self request] URL];
2727
PBGitRepository *repo = [[self request] repository];
28-
28+
2929
if(!repo) {
3030
[[self client] URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:0 userInfo:nil]];
3131
return;
3232
}
33-
34-
NSString *specifier = [NSString stringWithFormat:@"%@:%@", [url host], [[url path] substringFromIndex:1]];
33+
34+
NSString *path=[[url path] substringFromIndex:1];
35+
NSString *v=@"";
36+
if ([[path substringToIndex:5] isEqualToString:@"prev/"]) {
37+
path=[path substringFromIndex:5];
38+
v=@"^";
39+
}
40+
NSString *specifier = [NSString stringWithFormat:@"%@%@:%@", [url host], v,path];
3541
handle = [repo handleInWorkDirForArguments:[NSArray arrayWithObjects:@"cat-file", @"blob", specifier, nil]];
3642
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFinishFileLoad:) name:NSFileHandleReadToEndOfFileCompletionNotification object:handle];
3743
[handle readToEndOfFileInBackgroundAndNotify];
38-
44+
3945
NSURLResponse *response = [[NSURLResponse alloc] initWithURL:[[self request] URL]
4046
MIMEType:nil
4147
expectedContentLength:-1
4248
textEncodingName:nil];
43-
49+
4450
[[self client] URLProtocol:self
4551
didReceiveResponse:response
4652
cacheStoragePolicy:NSURLCacheStorageNotAllowed];

PBSourceViewBadge.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
}
1515

16+
+ (NSImage *) badge:(NSString *)badge forCell:(NSTextFieldCell *)cell;
1617
+ (NSImage *) checkedOutBadgeForCell:(NSTextFieldCell *)cell;
1718
+ (NSImage *) numericBadge:(NSInteger)number forCell:(NSTextFieldCell *)cell;
1819

PBSourceViewCell.h

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

1313
@interface PBSourceViewCell : PBIconAndTextCell {
1414
BOOL isCheckedOut;
15+
NSNumber *behind;
16+
NSNumber *ahead;
1517
}
1618

1719
@property (assign) BOOL isCheckedOut;
20+
@property (assign) NSNumber *behind;
21+
@property (assign) NSNumber *ahead;
22+
1823

1924
@end

0 commit comments

Comments
 (0)