Skip to content

Commit fd49408

Browse files
committed
Show full commit summary and date in a tooltip when hovering commit number in blame view.
1 parent 754afba commit fd49408

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

GLFileView.m

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,8 @@ - (NSString *) parseBlame:(NSString *)txt
550550
NSMutableDictionary *headers=[NSMutableDictionary dictionary];
551551
NSMutableString *res=[NSMutableString string];
552552

553+
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] initWithDateFormat:@"%Y-%m-%d %H:%M:%S" allowNaturalLanguage:NO];
554+
553555
[res appendString:@"<table class='blocks'>\n"];
554556
int i=0;
555557
while(i<[lines count]){
@@ -561,12 +563,32 @@ - (NSString *) parseBlame:(NSString *)txt
561563
[res appendFormat:@"<tr class='block l%d'>\n",nLines];
562564
line=[lines objectAtIndex:++i];
563565
if([[[line componentsSeparatedByString:@" "] objectAtIndex:0] isEqual:@"author"]){
564-
NSString *author=[line stringByReplacingOccurrencesOfString:@"author" withString:@""];
566+
NSString *author=[line stringByReplacingOccurrencesOfString:@"author " withString:@""];
567+
568+
NSString *timestamp=nil;
569+
while(timestamp==nil){
570+
line=[lines objectAtIndex:i++];
571+
if([[[line componentsSeparatedByString:@" "] objectAtIndex:0] isEqual:@"author-time"]){
572+
timestamp=[line stringByReplacingOccurrencesOfString:@"author-time " withString:@""];
573+
}
574+
}
575+
576+
NSString *timezone=nil;
577+
while(timezone==nil){
578+
line=[lines objectAtIndex:i++];
579+
if([[[line componentsSeparatedByString:@" "] objectAtIndex:0] isEqual:@"author-tz"]){
580+
timezone=[line stringByReplacingOccurrencesOfString:@"author-tz " withString:@""];
581+
}
582+
}
583+
584+
NSDate *date = [NSDate dateWithTimeIntervalSince1970:[timestamp doubleValue]];
585+
NSString *dateString = [NSString stringWithFormat:@"%@ %@",[dateFormatter stringFromDate: date],timezone];
586+
565587
NSString *summary=nil;
566588
while(summary==nil){
567589
line=[lines objectAtIndex:i++];
568590
if([[[line componentsSeparatedByString:@" "] objectAtIndex:0] isEqual:@"summary"]){
569-
summary=[line stringByReplacingOccurrencesOfString:@"summary" withString:@""];
591+
summary=[line stringByReplacingOccurrencesOfString:@"summary " withString:@""];
570592
}
571593
}
572594
NSRange trunc_c={0,7};
@@ -583,7 +605,8 @@ - (NSString *) parseBlame:(NSString *)txt
583605
if([summary length]>30){
584606
truncate_s=[summary substringWithRange:trunc];
585607
}
586-
NSString *block=[NSString stringWithFormat:@"<td><p class='author'><a href='' onclick='selectCommit(\"%@\"); return false;'>%@</a> %@</p><p class='summary'>%@</p></td>\n<td>\n",commitID,truncate_c,truncate_a,truncate_s];
608+
NSString *tooltip = [NSString stringWithFormat:@"%@\nAuthor: %@\nDate: %@\n\n%@",commitID,author,dateString,summary];
609+
NSString *block=[NSString stringWithFormat:@"<td><p class='author'><a title='%@' href='' onclick='selectCommit(\"%@\"); return false;'>%@</a> %@</p><p class='summary'>%@</p></td>\n<td>\n",tooltip,commitID,truncate_c,truncate_a,truncate_s];
587610
[headers setObject:block forKey:[header objectAtIndex:0]];
588611
}
589612
[res appendString:[headers objectForKey:[header objectAtIndex:0]]];

0 commit comments

Comments
 (0)