From 353d1053b081f882d05e7eef57fc46965265c759 Mon Sep 17 00:00:00 2001 From: Charles O'Rourke Date: Wed, 27 May 2009 21:17:14 -0400 Subject: [PATCH 1/3] Tickets #151 and #155: check for illegal branch names before creating. --- PBGitHistoryView.xib | 58 ++++++++++++++++++++++++++++++++++++++++---- PBRefController.h | 1 + PBRefController.m | 21 +++++++++++----- 3 files changed, 69 insertions(+), 11 deletions(-) diff --git a/PBGitHistoryView.xib b/PBGitHistoryView.xib index 2a02912..0dd3331 100644 --- a/PBGitHistoryView.xib +++ b/PBGitHistoryView.xib @@ -8,7 +8,7 @@ 353.00 YES - + @@ -1117,6 +1117,25 @@ 25 + + + 268 + {{251, 62}, {85, 17}} + + YES + + 68288064 + 272630784 + Invalid name + + + + + 1 + MSAwIDAAA + + + {346, 133} @@ -2075,6 +2094,14 @@ 271 + + + errorMessage + + + + 274 + @@ -2389,6 +2416,7 @@ + @@ -2690,6 +2718,20 @@ + + 272 + + + YES + + + + + + 273 + + + @@ -2767,6 +2809,8 @@ 27.IBViewIntegration.shadowOffsetHeight 27.IBViewIntegration.shadowOffsetWidth 27.ImportedFromIB2 + 272.IBPluginDependency + 273.IBPluginDependency 28.IBPluginDependency 28.IBShouldRemoveOnLegacySave 29.IBPluginDependency @@ -2859,8 +2903,8 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{521, 623}, {346, 133}} - {{521, 623}, {346, 133}} + {{504, 581}, {346, 133}} + {{504, 581}, {346, 133}} {3.40282e+38, 3.40282e+38} com.apple.InterfaceBuilder.CocoaPlugin @@ -2896,6 +2940,8 @@ com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -2929,7 +2975,7 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{312, 79}, {852, 432}} + {{189, 79}, {852, 432}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -2964,7 +3010,7 @@ - 271 + 274 @@ -3120,6 +3166,7 @@ branchPopUp commitController commitList + errorMessage historyController newBranchName newBranchSheet @@ -3129,6 +3176,7 @@ NSPopUpButton NSArrayController PBCommitList + NSTextField PBGitHistoryController NSTextField NSWindow diff --git a/PBRefController.h b/PBRefController.h index 4ec8990..0706fc5 100644 --- a/PBRefController.h +++ b/PBRefController.h @@ -20,6 +20,7 @@ IBOutlet NSWindow *newBranchSheet; IBOutlet NSTextField *newBranchName; + IBOutlet NSTextField *errorMessage; IBOutlet NSPopUpButton *branchPopUp; } diff --git a/PBRefController.m b/PBRefController.m index ccd5abd..b498386 100644 --- a/PBRefController.m +++ b/PBRefController.m @@ -160,6 +160,7 @@ # pragma mark Add ref methods -(void)addRef:(id)sender { + [errorMessage setStringValue:@""]; [NSApp beginSheet:newBranchSheet modalForWindow:[[historyController view] window] modalDelegate:NULL @@ -170,20 +171,28 @@ -(void)saveSheet:(id) sender { NSString *branchName = [@"refs/heads/" stringByAppendingString:[newBranchName stringValue]]; - [self closeSheet:sender]; if ([[commitController selectedObjects] count] == 0) return; - + PBGitCommit *commit = [[commitController selectedObjects] objectAtIndex:0]; + int retValue = 1; - [historyController.repository outputForArguments:[NSArray arrayWithObjects:@"update-ref", @"-mCreate branch from GitX", branchName, [commit realSha], NULL] retValue:&retValue]; - if (retValue) - { - NSLog(@"Creating ref failed!"); + [historyController.repository outputForArguments:[NSArray arrayWithObjects:@"check-ref-format", branchName, nil] retValue:&retValue]; + if (retValue != 0) { + [errorMessage setStringValue:@"Invalid name"]; return; } + retValue = 1; + [historyController.repository outputForArguments:[NSArray arrayWithObjects:@"update-ref", @"-mCreate branch from GitX", branchName, [commit realSha], @"0000000000000000000000000000000000000000", NULL] retValue:&retValue]; + if (retValue) + { + [errorMessage setStringValue:@"Branch exists"]; + return; + } + + [self closeSheet:sender]; [commit addRef:[PBGitRef refFromString:branchName]]; [commitController rearrangeObjects]; } From 1626606579033c0bc6ba155466a6bb66c136c40e Mon Sep 17 00:00:00 2001 From: Pieter de Bie Date: Thu, 28 May 2009 14:12:43 +0100 Subject: [PATCH 2/3] GitRevList: fix crash when loading 0 commits When there were no commits to load, 'git log' would output something like: Final output: 0 done After that, GitX would try to read the sha after the input, which would cause illegal string access and the throwing of a c++ exception. we fix this by just stopping with revision loading if the input isn't at least 40 characters -- the minimum for a sha. --- PBGitRevList.mm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/PBGitRevList.mm b/PBGitRevList.mm index ba39a3a..8ce2082 100644 --- a/PBGitRevList.mm +++ b/PBGitRevList.mm @@ -111,7 +111,11 @@ using namespace std; [self performSelectorOnMainThread:@selector(setCommits:) withObject:revisions waitUntilDone:NO]; g = [[PBGitGrapher alloc] initWithRepository: repository]; revisions = [NSMutableArray array]; - + + // If the length is < 40, then there are no commits.. quit now + if (sha.length() < 40) + break; + sha = sha.substr(sha.length() - 40, 40); } From b7c46c16b86a2c1c1aeaf64d644720fd9a2031bf Mon Sep 17 00:00:00 2001 From: Pieter de Bie Date: Thu, 28 May 2009 15:10:46 +0100 Subject: [PATCH 3/3] GitRevList -- Try to read the encoding of the commit message This tries to read the encoding of the commit message, if it's specified by git (using i18n.commitEncoding at the time of committing). It uses an ugly hack to try to convert the encoding string to an NSStringEncoding, and then uses that for the subject and committer name. I'm not sure how expensive this is. If it's too expensive, we might need to cache this value. --- PBGitRevList.mm | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/PBGitRevList.mm b/PBGitRevList.mm index 8ce2082..61a1b27 100644 --- a/PBGitRevList.mm +++ b/PBGitRevList.mm @@ -76,9 +76,9 @@ using namespace std; BOOL showSign = [rev hasLeftRight]; if (showSign) - arguments = [NSMutableArray arrayWithObjects:@"log", @"-z", @"--early-output", @"--topo-order", @"--pretty=format:%H\01%an\01%s\01%P\01%at\01%m", nil]; + arguments = [NSMutableArray arrayWithObjects:@"log", @"-z", @"--early-output", @"--topo-order", @"--pretty=format:%H\01%e\01%an\01%s\01%P\01%at\01%m", nil]; else - arguments = [NSMutableArray arrayWithObjects:@"log", @"-z", @"--early-output", @"--topo-order", @"--pretty=format:%H\01%an\01%s\01%P\01%at", nil]; + arguments = [NSMutableArray arrayWithObjects:@"log", @"-z", @"--early-output", @"--topo-order", @"--pretty=format:%H\01%e\01%an\01%s\01%P\01%at", nil]; if (!rev) [arguments addObject:@"HEAD"]; @@ -120,6 +120,12 @@ using namespace std; } // From now on, 1.2 seconds + string encoding_str; + getline(stream, encoding_str, '\1'); + NSStringEncoding encoding = NSUTF8StringEncoding; + if (encoding_str.length()) + encoding = CFStringConvertEncodingToNSStringEncoding(CFStringConvertIANACharSetNameToEncoding((CFStringRef)[NSString stringWithUTF8String:encoding_str.c_str()])); + git_oid oid; git_oid_mkstr(&oid, sha.c_str()); PBGitCommit* newCommit = [[PBGitCommit alloc] initWithRepository:repository andSha:oid]; @@ -152,8 +158,8 @@ using namespace std; stream >> time; - [newCommit setSubject:[NSString stringWithUTF8String:subject.c_str()]]; - [newCommit setAuthor:[NSString stringWithUTF8String:author.c_str()]]; + [newCommit setSubject:[NSString stringWithCString:subject.c_str() encoding:encoding]]; + [newCommit setAuthor:[NSString stringWithCString:author.c_str() encoding:encoding]]; [newCommit setTimestamp:time]; if (showSign)