Skip to content

Commit 38198a9

Browse files
committed
Merge branch 'stable'
* stable: GitRevList -- Try to read the encoding of the commit message GitRevList: fix crash when loading 0 commits Tickets #151 and #155: check for illegal branch names before creating.
2 parents fe54a46 + b7c46c1 commit 38198a9

File tree

4 files changed

+82
-14
lines changed

4 files changed

+82
-14
lines changed

PBGitHistoryView.xib

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<string key="IBDocument.HIToolboxVersion">353.00</string>
99
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
1010
<bool key="EncodedWithXMLCoder">YES</bool>
11-
<integer value="236"/>
11+
<integer value="237"/>
1212
<integer value="27"/>
1313
</object>
1414
<object class="NSArray" key="IBDocument.PluginDependencies">
@@ -1119,6 +1119,25 @@
11191119
<int key="NSPeriodicInterval">25</int>
11201120
</object>
11211121
</object>
1122+
<object class="NSTextField" id="27300806">
1123+
<reference key="NSNextResponder" ref="562356688"/>
1124+
<int key="NSvFlags">268</int>
1125+
<string key="NSFrame">{{251, 62}, {85, 17}}</string>
1126+
<reference key="NSSuperview" ref="562356688"/>
1127+
<bool key="NSEnabled">YES</bool>
1128+
<object class="NSTextFieldCell" key="NSCell" id="217429948">
1129+
<int key="NSCellFlags">68288064</int>
1130+
<int key="NSCellFlags2">272630784</int>
1131+
<string key="NSContents">Invalid name</string>
1132+
<reference key="NSSupport" ref="924107556"/>
1133+
<reference key="NSControlView" ref="27300806"/>
1134+
<reference key="NSBackgroundColor" ref="457244339"/>
1135+
<object class="NSColor" key="NSTextColor">
1136+
<int key="NSColorSpace">1</int>
1137+
<bytes key="NSRGB">MSAwIDAAA</bytes>
1138+
</object>
1139+
</object>
1140+
</object>
11221141
</object>
11231142
<string key="NSFrameSize">{346, 133}</string>
11241143
<reference key="NSSuperview"/>
@@ -2077,6 +2096,14 @@
20772096
</object>
20782097
<int key="connectionID">271</int>
20792098
</object>
2099+
<object class="IBConnectionRecord">
2100+
<object class="IBOutletConnection" key="connection">
2101+
<string key="label">errorMessage</string>
2102+
<reference key="source" ref="892732705"/>
2103+
<reference key="destination" ref="27300806"/>
2104+
</object>
2105+
<int key="connectionID">274</int>
2106+
</object>
20802107
</object>
20812108
<object class="IBMutableOrderedSet" key="objectRecords">
20822109
<object class="NSArray" key="orderedObjects">
@@ -2391,6 +2418,7 @@
23912418
<reference ref="383988892"/>
23922419
<reference ref="60467344"/>
23932420
<reference ref="657747237"/>
2421+
<reference ref="27300806"/>
23942422
</object>
23952423
<reference key="parent" ref="296392339"/>
23962424
</object>
@@ -2692,6 +2720,20 @@
26922720
<reference key="object" ref="496187369"/>
26932721
<reference key="parent" ref="604026377"/>
26942722
</object>
2723+
<object class="IBObjectRecord">
2724+
<int key="objectID">272</int>
2725+
<reference key="object" ref="27300806"/>
2726+
<object class="NSMutableArray" key="children">
2727+
<bool key="EncodedWithXMLCoder">YES</bool>
2728+
<reference ref="217429948"/>
2729+
</object>
2730+
<reference key="parent" ref="562356688"/>
2731+
</object>
2732+
<object class="IBObjectRecord">
2733+
<int key="objectID">273</int>
2734+
<reference key="object" ref="217429948"/>
2735+
<reference key="parent" ref="27300806"/>
2736+
</object>
26952737
</object>
26962738
</object>
26972739
<object class="NSMutableDictionary" key="flattenedProperties">
@@ -2769,6 +2811,8 @@
27692811
<string>27.IBViewIntegration.shadowOffsetHeight</string>
27702812
<string>27.IBViewIntegration.shadowOffsetWidth</string>
27712813
<string>27.ImportedFromIB2</string>
2814+
<string>272.IBPluginDependency</string>
2815+
<string>273.IBPluginDependency</string>
27722816
<string>28.IBPluginDependency</string>
27732817
<string>28.IBShouldRemoveOnLegacySave</string>
27742818
<string>29.IBPluginDependency</string>
@@ -2861,8 +2905,8 @@
28612905
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
28622906
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
28632907
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
2864-
<string>{{521, 623}, {346, 133}}</string>
2865-
<string>{{521, 623}, {346, 133}}</string>
2908+
<string>{{504, 581}, {346, 133}}</string>
2909+
<string>{{504, 581}, {346, 133}}</string>
28662910
<reference ref="8"/>
28672911
<string>{3.40282e+38, 3.40282e+38}</string>
28682912
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -2898,6 +2942,8 @@
28982942
<reference ref="8"/>
28992943
<reference ref="9"/>
29002944
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
2945+
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
2946+
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
29012947
<reference ref="9"/>
29022948
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
29032949
<reference ref="9"/>
@@ -2931,7 +2977,7 @@
29312977
</object>
29322978
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
29332979
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
2934-
<string>{{312, 79}, {852, 432}}</string>
2980+
<string>{{189, 79}, {852, 432}}</string>
29352981
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
29362982
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
29372983
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -2966,7 +3012,7 @@
29663012
</object>
29673013
</object>
29683014
<nil key="sourceID"/>
2969-
<int key="maxID">271</int>
3015+
<int key="maxID">274</int>
29703016
</object>
29713017
<object class="IBClassDescriber" key="IBDocument.Classes">
29723018
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -3120,6 +3166,7 @@
31203166
<string>branchPopUp</string>
31213167
<string>commitController</string>
31223168
<string>commitList</string>
3169+
<string>errorMessage</string>
31233170
<string>historyController</string>
31243171
<string>newBranchName</string>
31253172
<string>newBranchSheet</string>
@@ -3129,6 +3176,7 @@
31293176
<string>NSPopUpButton</string>
31303177
<string>NSArrayController</string>
31313178
<string>PBCommitList</string>
3179+
<string>NSTextField</string>
31323180
<string>PBGitHistoryController</string>
31333181
<string>NSTextField</string>
31343182
<string>NSWindow</string>

PBGitRevList.mm

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ - (void) walkRevisionListWithSpecifier: (PBGitRevSpecifier*) rev
7676
BOOL showSign = [rev hasLeftRight];
7777

7878
if (showSign)
79-
arguments = [NSMutableArray arrayWithObjects:@"log", @"-z", @"--early-output", @"--topo-order", @"--pretty=format:%H\01%an\01%s\01%P\01%at\01%m", nil];
79+
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];
8080
else
81-
arguments = [NSMutableArray arrayWithObjects:@"log", @"-z", @"--early-output", @"--topo-order", @"--pretty=format:%H\01%an\01%s\01%P\01%at", nil];
81+
arguments = [NSMutableArray arrayWithObjects:@"log", @"-z", @"--early-output", @"--topo-order", @"--pretty=format:%H\01%e\01%an\01%s\01%P\01%at", nil];
8282

8383
if (!rev)
8484
[arguments addObject:@"HEAD"];
@@ -111,11 +111,21 @@ - (void) walkRevisionListWithSpecifier: (PBGitRevSpecifier*) rev
111111
[self performSelectorOnMainThread:@selector(setCommits:) withObject:revisions waitUntilDone:NO];
112112
g = [[PBGitGrapher alloc] initWithRepository: repository];
113113
revisions = [NSMutableArray array];
114-
114+
115+
// If the length is < 40, then there are no commits.. quit now
116+
if (sha.length() < 40)
117+
break;
118+
115119
sha = sha.substr(sha.length() - 40, 40);
116120
}
117121

118122
// From now on, 1.2 seconds
123+
string encoding_str;
124+
getline(stream, encoding_str, '\1');
125+
NSStringEncoding encoding = NSUTF8StringEncoding;
126+
if (encoding_str.length())
127+
encoding = CFStringConvertEncodingToNSStringEncoding(CFStringConvertIANACharSetNameToEncoding((CFStringRef)[NSString stringWithUTF8String:encoding_str.c_str()]));
128+
119129
git_oid oid;
120130
git_oid_mkstr(&oid, sha.c_str());
121131
PBGitCommit* newCommit = [[PBGitCommit alloc] initWithRepository:repository andSha:oid];
@@ -148,8 +158,8 @@ - (void) walkRevisionListWithSpecifier: (PBGitRevSpecifier*) rev
148158
stream >> time;
149159

150160

151-
[newCommit setSubject:[NSString stringWithUTF8String:subject.c_str()]];
152-
[newCommit setAuthor:[NSString stringWithUTF8String:author.c_str()]];
161+
[newCommit setSubject:[NSString stringWithCString:subject.c_str() encoding:encoding]];
162+
[newCommit setAuthor:[NSString stringWithCString:author.c_str() encoding:encoding]];
153163
[newCommit setTimestamp:time];
154164

155165
if (showSign)

PBRefController.h

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

2121
IBOutlet NSWindow *newBranchSheet;
2222
IBOutlet NSTextField *newBranchName;
23+
IBOutlet NSTextField *errorMessage;
2324

2425
IBOutlet NSPopUpButton *branchPopUp;
2526
}

PBRefController.m

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ - (BOOL)tableView:(NSTableView *)aTableView
177177
# pragma mark Add ref methods
178178
-(void)addRef:(id)sender
179179
{
180+
[errorMessage setStringValue:@""];
180181
[NSApp beginSheet:newBranchSheet
181182
modalForWindow:[[historyController view] window]
182183
modalDelegate:NULL
@@ -187,20 +188,28 @@ -(void)addRef:(id)sender
187188
-(void)saveSheet:(id) sender
188189
{
189190
NSString *branchName = [@"refs/heads/" stringByAppendingString:[newBranchName stringValue]];
190-
[self closeSheet:sender];
191191

192192
if ([[commitController selectedObjects] count] == 0)
193193
return;
194-
194+
195195
PBGitCommit *commit = [[commitController selectedObjects] objectAtIndex:0];
196+
196197
int retValue = 1;
197-
[historyController.repository outputForArguments:[NSArray arrayWithObjects:@"update-ref", @"-mCreate branch from GitX", branchName, [commit realSha], NULL] retValue:&retValue];
198+
[historyController.repository outputForArguments:[NSArray arrayWithObjects:@"check-ref-format", branchName, nil] retValue:&retValue];
199+
if (retValue != 0) {
200+
[errorMessage setStringValue:@"Invalid name"];
201+
return;
202+
}
203+
204+
retValue = 1;
205+
[historyController.repository outputForArguments:[NSArray arrayWithObjects:@"update-ref", @"-mCreate branch from GitX", branchName, [commit realSha], @"0000000000000000000000000000000000000000", NULL] retValue:&retValue];
198206
if (retValue)
199207
{
200-
NSLog(@"Creating ref failed!");
208+
[errorMessage setStringValue:@"Branch exists"];
201209
return;
202210
}
203211

212+
[self closeSheet:sender];
204213
[commit addRef:[PBGitRef refFromString:branchName]];
205214
[commitController rearrangeObjects];
206215
}

0 commit comments

Comments
 (0)