diff --git a/PBGitCommit.m b/PBGitCommit.m index 9ebe3b5..3944e4f 100644 --- a/PBGitCommit.m +++ b/PBGitCommit.m @@ -34,11 +34,72 @@ return [NSDate dateWithTimeIntervalSince1970:timestamp]; } +#ifdef NormalDate - (NSString *) dateString { NSDateFormatter* formatter = [[NSDateFormatter alloc] initWithDateFormat:@"%Y-%m-%d %H:%M:%S" allowNaturalLanguage:NO]; return [formatter stringFromDate: self.date]; } +#else + +// Code modified from Gilean ( http://stackoverflow.com/users/6305/gilean ). +// Copied from stackoverflow's accepted answer for Objective C relative dates. +// http://stackoverflow.com/questions/902950/iphone-convert-date-string-to-a-relative-time-stamp +// Modified the seconds constants with compile time math to aid in ease of adjustment of "Majic" numbers. +// +-(NSString *)dateString { + NSDate *todayDate = [NSDate date]; + double ti = [self.date timeIntervalSinceDate:todayDate]; + ti = ti * -1; + if(ti < 1) { + return @"In the future!"; + } else if ( ti < 60 ) { + return @"less than a minute ago"; + } else if ( ti < (60 * 60) ) { + int diff = round(ti / 60); + if ( diff < 2 ) { + return @"1 minute ago"; + } else { + return [NSString stringWithFormat:@"%d minutes ago", diff]; + } + } else if ( ti < ( 60 * 60 * 24 ) ) { + int diff = round(ti / 60 / 60); + if ( diff < 2 ) { + return @"1 hour ago"; + } else { + return[NSString stringWithFormat:@"%d hours ago", diff]; + } + } else if ( ti < ( 60 * 60 * 24 * 7 ) ) { + int diff = round(ti / 60 / 60 / 24); + if ( diff < 2 ) { + return @"1 day ago"; + } else { + return[NSString stringWithFormat:@"%d days ago", diff]; + } + } else if ( ti < ( 60 * 60 * 24 * 31.5 ) ) { + int diff = round(ti / 60 / 60 / 24 / 7); + if ( diff < 2 ) { + return @"1 week ago"; + } else { + return[NSString stringWithFormat:@"%d weeks ago", diff]; + } + } else if ( ti < ( 60 * 60 * 24 * 365 ) ) { + int diff = round(ti / 60 / 60 / 24 / 30); + if ( diff < 2 ) { + return @"1 month ago"; + } else { + return[NSString stringWithFormat:@"%d months ago", diff]; + } + } else { + float diff = round(ti / 60 / 60 / 24 / 365 * 4) / 4.0; + if ( diff < 1.25 ) { + return @"1 year ago"; + } else { + return[NSString stringWithFormat:@"%g years ago", diff]; + } + } +} +#endif - (NSArray*) treeContents { diff --git a/PBGitGrapher.h b/PBGitGrapher.h index d17f3bd..f8945d0 100644 --- a/PBGitGrapher.h +++ b/PBGitGrapher.h @@ -14,7 +14,7 @@ @interface PBGitGrapher : NSObject { PBGraphCellInfo *previous; void *pl; - int curLane; + void *endLane; } - (id) initWithRepository:(PBGitRepository *)repo; diff --git a/PBGitGrapher.mm b/PBGitGrapher.mm index f9daf84..b71b60d 100644 --- a/PBGitGrapher.mm +++ b/PBGitGrapher.mm @@ -53,6 +53,11 @@ void add_line(struct PBGitGraphLine *lines, int *nLines, int upper, int from, in std::list::iterator it = previousLanes->begin(); for (; it != previousLanes->end(); ++it) { i++; + if(*it == (PBGitLane *)endLane) { + delete *it; + endLane = NULL; + continue; + } // This is our commit! We should do a "merge": move the line from // our upperMapping to their lowerMapping if ((*it)->isCommit([commit sha])) { @@ -141,7 +146,8 @@ void add_line(struct PBGitGraphLine *lines, int *nLines, int upper, int from, in if (currentLane && commit.nParents > 0) currentLane->setSha(commit.parentShas[0]); else - currentLanes->remove(currentLane); + endLane = currentLane; + // currentLanes->remove(currentLane); // must be leaked without this changes delete previousLanes; diff --git a/PBGitWindowController.m b/PBGitWindowController.m index 232b76c..ae2f361 100644 --- a/PBGitWindowController.m +++ b/PBGitWindowController.m @@ -9,6 +9,7 @@ #import "PBGitWindowController.h" #import "PBGitHistoryController.h" #import "PBGitCommitController.h" +#import "PBGitDefaults.h" @implementation PBGitWindowController @@ -137,6 +138,12 @@ [[NSAlert alertWithError:error] beginSheetModalForWindow: [self window] modalDelegate:self didEndSelector:nil contextInfo:nil]; } +- (void)windowDidBecomeKey:(NSNotification *)notification +{ + if (self.viewController && [PBGitDefaults refreshAutomatically]) { + [(PBViewController *)self.viewController refresh:nil]; + } +} #pragma mark - #pragma mark Toolbar Delegates diff --git a/PBViewController.h b/PBViewController.h index 4715c61..6055ace 100644 --- a/PBViewController.h +++ b/PBViewController.h @@ -25,4 +25,5 @@ - (void) updateView; - (NSResponder *)firstResponder; +- (IBAction) refresh:(id)sender; @end diff --git a/PBViewController.m b/PBViewController.m index 510b7a7..3368d16 100644 --- a/PBViewController.m +++ b/PBViewController.m @@ -45,4 +45,9 @@ { return nil; } + +- (IBAction) refresh:(id)sender +{ + return; +} @end diff --git a/html/views/history/history.js b/html/views/history/history.js index 6cd7540..ffe74c8 100644 --- a/html/views/history/history.js +++ b/html/views/history/history.js @@ -244,7 +244,7 @@ var showDiff = function() { p.insertBefore(document.createTextNode(name1 + " -> "), link); } - link.appendChild(document.createTextNode(finalFile)); + link.appendChild(document.createTextNode(finalFile.unEscapeHTML())); button.setAttribute("representedFile", finalFile); link.setAttribute("representedFile", finalFile);