diff --git a/Classes/Controllers/PBRefController.m b/Classes/Controllers/PBRefController.m index 3913851ea..f667c851e 100644 --- a/Classes/Controllers/PBRefController.m +++ b/Classes/Controllers/PBRefController.m @@ -430,13 +430,12 @@ - (BOOL)tableView:(NSTableView *)aTableView NSString *subject = [dropCommit subject]; if ([subject length] > 99) subject = [[subject substringToIndex:99] stringByAppendingString:@"…"]; - NSString *infoText = [NSString stringWithFormat:@"Move the %@ to point to the commit: %@", [ref refishType], subject]; NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:@"Move %@: %@", [ref refishType], [ref shortName]] defaultButton:@"Move" alternateButton:@"Cancel" otherButton:nil - informativeTextWithFormat:infoText]; + informativeTextWithFormat:@"Move the %@ to point to the commit: %@", [ref refishType], subject]; [alert setShowsSuppressionButton:YES]; [alert beginSheetModalForWindow:[historyController.repository.windowController window] diff --git a/Classes/Util/NSString_RegEx.h b/Classes/Util/NSString_RegEx.h deleted file mode 100644 index 784e9ff8c..000000000 --- a/Classes/Util/NSString_RegEx.h +++ /dev/null @@ -1,34 +0,0 @@ -// -// NSString_RegEx.h -// -// Created by John R Chang on 2005-11-08. -// This code is Creative Commons Public Domain. You may use it for any purpose whatsoever. -// http://creativecommons.org/licenses/publicdomain/ -// - -#import - -/* - For regular expression help, see re_format(7) man page. -*/ - -@interface NSString (RegEx) - -/* - Common are REG_ICASE and REG_NEWLINE. For other possible option flags, - see regex(3) man page. You don't need to specify REG_EXTENDED. - - is the number of subexpressions to match. - Returns an array of strings. The first string is the matching substring, - the remaining are the matching subexpressions, up to nmatch+1 number. - - If nmatch is -1, works like grep. Returns an array containing self if matching. - - Returns nil if regular expression does not match or if an error has occurred. -*/ -- (NSArray *) substringsMatchingRegularExpression:(NSString *)pattern count:(int)nmatch - options:(int)options ranges:(NSArray **)ranges error:(NSError **)error; - -- (BOOL) grep:(NSString *)pattern options:(int)options; - -@end diff --git a/Classes/Util/NSString_RegEx.m b/Classes/Util/NSString_RegEx.m deleted file mode 100644 index f136612a8..000000000 --- a/Classes/Util/NSString_RegEx.m +++ /dev/null @@ -1,97 +0,0 @@ -// -// NSString_RegEx.m -// -// Created by John R Chang on 2005-11-08. -// This code is Creative Commons Public Domain. You may use it for any purpose whatsoever. -// http://creativecommons.org/licenses/publicdomain/ -// - -#import "NSString_RegEx.h" -#include - - -@implementation NSString (RegEx) - -- (NSArray *) substringsMatchingRegularExpression:(NSString *)pattern count:(int)nmatch options:(int)options ranges:(NSArray **)ranges error:(NSError **)error -{ - options |= REG_EXTENDED; - if (error) - *error = nil; - - int errcode = 0; - regex_t preg; - regmatch_t * pmatch = NULL; - NSMutableArray * outMatches = nil; - - // Compile the regular expression - errcode = regcomp(&preg, [pattern UTF8String], options); - if (errcode != 0) - goto catch_error; // regcomp error - - // Match the regular expression against substring self - pmatch = calloc(sizeof(regmatch_t), nmatch+1); - errcode = regexec(&preg, [self UTF8String], (nmatch<0 ? 0 : nmatch+1), pmatch, 0); - - /*if (errcode == REG_NOMATCH) - { - outMatches = [NSMutableArray array]; - goto catch_exit; // no match - }*/ - if (errcode != 0) - goto catch_error; // regexec error - - if (nmatch == -1) - { - outMatches = [NSArray arrayWithObject:self]; - goto catch_exit; // simple match - } - - // Iterate through pmatch - outMatches = [NSMutableArray array]; - if (ranges) - *ranges = [NSMutableArray array]; - int i; - for (i=0; i 0) - [userInfo setObject:[NSString stringWithUTF8String:errbuf] forKey:NSLocalizedDescriptionKey]; - *error = [NSError errorWithDomain:@"regerror" code:errcode userInfo:userInfo]; - } - -catch_exit: - if (pmatch) - free(pmatch); - regfree(&preg); - return outMatches; -} - -- (BOOL) grep:(NSString *)pattern options:(int)options -{ - NSArray * substrings = [self substringsMatchingRegularExpression:pattern count:-1 options:options ranges:NULL error:NULL]; - return (substrings && [substrings count] > 0); -} - -@end diff --git a/Classes/git/PBGitIndex.m b/Classes/git/PBGitIndex.m index 70726946e..4474fd3e2 100644 --- a/Classes/git/PBGitIndex.m +++ b/Classes/git/PBGitIndex.m @@ -10,7 +10,6 @@ #import "PBGitRepository.h" #import "PBGitBinary.h" #import "PBEasyPipe.h" -#import "NSString_RegEx.h" #import "PBChangedFile.h" NSString *PBGitIndexIndexRefreshStatus = @"PBGitIndexIndexRefreshStatus"; @@ -96,12 +95,16 @@ - (void)setAmend:(BOOL)newAmend // We do this by reading in the previous commit, and storing the information // in a dictionary. This dictionary will then later be read by [self commit:] NSString *message = [repository outputForCommand:@"cat-file commit HEAD"]; - NSArray *match = [message substringsMatchingRegularExpression:@"\nauthor ([^\n]*) <([^\n>]*)> ([0-9]+[^\n]*)\n" count:3 options:0 ranges:nil error:nil]; - if (match) - amendEnvironment = [NSDictionary dictionaryWithObjectsAndKeys:[match objectAtIndex:1], @"GIT_AUTHOR_NAME", - [match objectAtIndex:2], @"GIT_AUTHOR_EMAIL", - [match objectAtIndex:3], @"GIT_AUTHOR_DATE", - nil]; + + NSRegularExpression *regex = [[NSRegularExpression alloc] initWithPattern: @"\nauthor ([^\n]*) <([^\n>]*)> ([0-9]+[^\n]*)\n" options:0 error: NULL]; + NSTextCheckingResult *result = [regex firstMatchInString: message options: 0 range: NSMakeRange( 0, message.length )]; + if (result.numberOfRanges == 4) { + amendEnvironment = @{ + @"GIT_AUTHOR_NAME": [message substringWithRange: [result rangeAtIndex: 1]], + @"GIT_AUTHOR_EMAIL": [message substringWithRange: [result rangeAtIndex: 2]], + @"GIT_AUTHOR_DATE": [message substringWithRange: [result rangeAtIndex: 3]] + }; + } // Find the commit message NSRange r = [message rangeOfString:@"\n\n"]; diff --git a/Classes/git/PBGitLane.h b/Classes/git/PBGitLane.h index ba722a03a..decc7d19d 100644 --- a/Classes/git/PBGitLane.h +++ b/Classes/git/PBGitLane.h @@ -22,17 +22,6 @@ class PBGitLane { d_sha = *sha; } - PBGitLane(NSString *sha) - { - git_oid_fromstr(&d_sha, [sha UTF8String]); - d_index = s_colorIndex++; - } - - PBGitLane() - { - d_index = s_colorIndex++; - } - bool isCommit(git_oid sha) const { return !git_oid_cmp(&d_sha, &sha); diff --git a/Classes/git/PBGitLane.mm b/Classes/git/PBGitLane.mm index 2ae767f27..d04b29da4 100644 --- a/Classes/git/PBGitLane.mm +++ b/Classes/git/PBGitLane.mm @@ -7,20 +7,6 @@ // #import "PBGitLane.h" -//class PBGitLane { -// static int s_colorIndex; -// -// char d_sha[20]; -// int d_index; -// -//public: -// PBGitLane(NSString *sha); -// -// bool isCommit(NSString *sha) const; -// int index(); const; -// -// static resetColors(); -//}; int PBGitLane::s_colorIndex = 0; diff --git a/Classes/git/PBGitRepository.m b/Classes/git/PBGitRepository.m index f0e1d07df..343616f54 100644 --- a/Classes/git/PBGitRepository.m +++ b/Classes/git/PBGitRepository.m @@ -224,28 +224,18 @@ - (void) addRef:(GTReference*)gtRef [refs setObject:[NSMutableArray arrayWithObject:ref] forKey:sha]; } -int addSubmoduleName(git_submodule *module, const char* name, void * context) +- (void) loadSubmodules { - PBGitRepository *me = (__bridge PBGitRepository *)context; - PBGitSubmodule *sub = [[PBGitSubmodule alloc] init]; - [sub setWorkingDirectory:me.workingDirectory]; - [sub setSubmodule:module]; + NSMutableArray *newSubmodules = [NSMutableArray array]; - - [me.submodules addObject:sub]; + [self.gtRepo enumerateSubmodulesRecursively: NO usingBlock:^(GTSubmodule *submodule, BOOL *stop) { + PBGitSubmodule *sub = [[PBGitSubmodule alloc] init]; + sub.workingDirectory = self.workingDirectory; + sub.submodule = submodule.git_submodule; + [newSubmodules addObject: sub]; + }]; - return 0; -} - -- (void) loadSubmodules -{ - self.submodules = [NSMutableArray array]; - git_repository* theRepo = self.gtRepo.git_repository; - if (!theRepo) - { - return; - } - git_submodule_foreach(theRepo, addSubmoduleName, (__bridge void *)self); + self.submodules = newSubmodules; } - (void) reloadRefs diff --git a/Classes/git/PBGitRevList.mm b/Classes/git/PBGitRevList.mm index 3fa734b00..cae778348 100644 --- a/Classes/git/PBGitRevList.mm +++ b/Classes/git/PBGitRevList.mm @@ -267,14 +267,16 @@ - (void) walkRevisionListWithSpecifier:(PBGitRevSpecifier*)rev } if (![currentThread isCancelled]) { +#if DEBUG NSTimeInterval duration = [[NSDate date] timeIntervalSinceDate:start]; - //NSLog(@"Loaded %i commits in %f seconds (%f/sec)", num, duration, num/duration); - + NSLog(@"Loaded %i commits in %f seconds (%f/sec)", num, duration, num/duration); +#endif // Make sure the commits are stored before exiting. NSDictionary *update = [NSDictionary dictionaryWithObjectsAndKeys:currentThread, kRevListThreadKey, revisions, kRevListRevisionsKey, nil]; - [self performSelectorOnMainThread:@selector(updateCommits:) withObject:update waitUntilDone:YES]; - - [self performSelectorOnMainThread:@selector(finishedParsing) withObject:nil waitUntilDone:NO]; + dispatch_async(dispatch_get_main_queue(), ^{ + [self updateCommits:update]; + [self finishedParsing]; + }); } else { NSLog(@"[%@ %@] thread has been canceled", [self class], NSStringFromSelector(_cmd)); diff --git a/GitX.xcodeproj/project.pbxproj b/GitX.xcodeproj/project.pbxproj index 99f706056..6b2372fe8 100644 --- a/GitX.xcodeproj/project.pbxproj +++ b/GitX.xcodeproj/project.pbxproj @@ -132,7 +132,6 @@ 4A5D771D14A9A9CC00DF6C68 /* NSApplication+GitXScripting.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A5D76A614A9A9CC00DF6C68 /* NSApplication+GitXScripting.m */; }; 4A5D771E14A9A9CC00DF6C68 /* NSFileHandleExt.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A5D76A814A9A9CC00DF6C68 /* NSFileHandleExt.m */; }; 4A5D771F14A9A9CC00DF6C68 /* NSOutlineViewExt.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A5D76AA14A9A9CC00DF6C68 /* NSOutlineViewExt.m */; }; - 4A5D772014A9A9CC00DF6C68 /* NSString_RegEx.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A5D76AC14A9A9CC00DF6C68 /* NSString_RegEx.m */; }; 4A5D772114A9A9CC00DF6C68 /* NSString_Truncate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A5D76AE14A9A9CC00DF6C68 /* NSString_Truncate.m */; }; 4A5D772214A9A9CC00DF6C68 /* PBEasyFS.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A5D76B014A9A9CC00DF6C68 /* PBEasyFS.m */; }; 4A5D772314A9A9CC00DF6C68 /* PBEasyPipe.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A5D76B214A9A9CC00DF6C68 /* PBEasyPipe.m */; }; @@ -563,8 +562,6 @@ 4A5D76A814A9A9CC00DF6C68 /* NSFileHandleExt.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSFileHandleExt.m; sourceTree = ""; }; 4A5D76A914A9A9CC00DF6C68 /* NSOutlineViewExt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSOutlineViewExt.h; sourceTree = ""; }; 4A5D76AA14A9A9CC00DF6C68 /* NSOutlineViewExt.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSOutlineViewExt.m; sourceTree = ""; }; - 4A5D76AB14A9A9CC00DF6C68 /* NSString_RegEx.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSString_RegEx.h; sourceTree = ""; }; - 4A5D76AC14A9A9CC00DF6C68 /* NSString_RegEx.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSString_RegEx.m; sourceTree = ""; }; 4A5D76AD14A9A9CC00DF6C68 /* NSString_Truncate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSString_Truncate.h; sourceTree = ""; }; 4A5D76AE14A9A9CC00DF6C68 /* NSString_Truncate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSString_Truncate.m; sourceTree = ""; }; 4A5D76AF14A9A9CC00DF6C68 /* PBEasyFS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBEasyFS.h; sourceTree = ""; }; @@ -1110,8 +1107,6 @@ 4A5D76A814A9A9CC00DF6C68 /* NSFileHandleExt.m */, 4A5D76A914A9A9CC00DF6C68 /* NSOutlineViewExt.h */, 4A5D76AA14A9A9CC00DF6C68 /* NSOutlineViewExt.m */, - 4A5D76AB14A9A9CC00DF6C68 /* NSString_RegEx.h */, - 4A5D76AC14A9A9CC00DF6C68 /* NSString_RegEx.m */, 4A5D76AD14A9A9CC00DF6C68 /* NSString_Truncate.h */, 4A5D76AE14A9A9CC00DF6C68 /* NSString_Truncate.m */, 4A5D76AF14A9A9CC00DF6C68 /* PBEasyFS.h */, @@ -1610,7 +1605,6 @@ 4A5D771D14A9A9CC00DF6C68 /* NSApplication+GitXScripting.m in Sources */, 4A5D771E14A9A9CC00DF6C68 /* NSFileHandleExt.m in Sources */, 4A5D771F14A9A9CC00DF6C68 /* NSOutlineViewExt.m in Sources */, - 4A5D772014A9A9CC00DF6C68 /* NSString_RegEx.m in Sources */, 4A5D772114A9A9CC00DF6C68 /* NSString_Truncate.m in Sources */, 4A5D772214A9A9CC00DF6C68 /* PBEasyFS.m in Sources */, 4A5D772314A9A9CC00DF6C68 /* PBEasyPipe.m in Sources */,