Skip to content

Commit 43353c2

Browse files
committed
Fix GitX quitting when its history cannot be loaded (issue gitx#645)
The error that ends the load is already in hand, so report it and keep what was read rather than raising on it. * Replace the NSAssert ending -addCommitsFromEnumerator: with the log this class already uses for a failed push. NS_BLOCK_ASSERTIONS is unset in Release, so a repository deleted, moved or unmounted under an open window raised NSInternalInconsistencyException and took the application down with nothing said about the cause. * Let the partial walk flush, so the commits read before the failure reach the history list instead of being lost with the exception. * Add PBGitRevListEnumerationErrorTests, driving the walk with an enumerator that reports failure immediately.
1 parent 583def9 commit 43353c2

3 files changed

Lines changed: 65 additions & 1 deletion

File tree

‎Classes/git/PBGitRevList.m‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,9 @@ - (void)addCommitsFromEnumerator:(GTEnumerator *)enumerator operation:(NSOperati
261261
});
262262
}
263263

264-
NSAssert(!enumError, @"Error enumerating commits");
264+
if (enumError) {
265+
NSLog(@"Failed to enumerate commits: %@", enumError);
266+
}
265267

266268
dispatch_group_wait(loadGroup, DISPATCH_TIME_FOREVER);
267269
dispatch_group_wait(decorateGroup, DISPATCH_TIME_FOREVER);

‎GitX.xcodeproj/project.pbxproj‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@
154154
50DCC65A20111E4000999D3D /* PBGitRevisionRow.m in Sources */ = {isa = PBXBuildFile; fileRef = 50DCC65920111E4000999D3D /* PBGitRevisionRow.m */; };
155155
551BF176112F3F4B00265053 /* gitx_askpasswd in Resources */ = {isa = PBXBuildFile; fileRef = 551BF111112F371800265053 /* gitx_askpasswd */; };
156156
63E155858B2CC783EE10F1D7 /* PBGitRevListRaceConditionTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 689D57B4A78CEF3B32EB0044 /* PBGitRevListRaceConditionTests.m */; };
157+
4C2D8E3FA01B52C4D6E7F801 /* PBGitRevListEnumerationErrorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C2D8E3FA01B52C4D6E7F802 /* PBGitRevListEnumerationErrorTests.m */; };
157158
7A1C4E2B90D3F5A6C1B80011 /* PBGitRepositoryFetchArgumentsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7A1C4E2B90D3F5A6C1B80012 /* PBGitRepositoryFetchArgumentsTests.m */; };
158159
2F9D30A7C15B4E68B4720A50 /* PBGitBinarySearchTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2F9D30A7C15B4E68B4720A51 /* PBGitBinarySearchTests.m */; };
159160
8A1C64D2B3E7492FA0561D40 /* OpenRecentControllerErrorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8A1C64D2B3E7492FA0561D41 /* OpenRecentControllerErrorTests.m */; };
@@ -714,6 +715,7 @@
714715
643952751603EF9B00BB7AFF /* PBSourceViewGitSubmoduleItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBSourceViewGitSubmoduleItem.h; sourceTree = "<group>"; };
715716
643952761603EF9B00BB7AFF /* PBSourceViewGitSubmoduleItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBSourceViewGitSubmoduleItem.m; sourceTree = "<group>"; };
716717
689D57B4A78CEF3B32EB0044 /* PBGitRevListRaceConditionTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = PBGitRevListRaceConditionTests.m; path = GitXTests/PBGitRevListRaceConditionTests.m; sourceTree = "<group>"; };
718+
4C2D8E3FA01B52C4D6E7F802 /* PBGitRevListEnumerationErrorTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = PBGitRevListEnumerationErrorTests.m; path = GitXTests/PBGitRevListEnumerationErrorTests.m; sourceTree = "<group>"; };
717719
7A1C4E2B90D3F5A6C1B80012 /* PBGitRepositoryFetchArgumentsTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = PBGitRepositoryFetchArgumentsTests.m; path = GitXTests/PBGitRepositoryFetchArgumentsTests.m; sourceTree = "<group>"; };
718720
2F9D30A7C15B4E68B4720A51 /* PBGitBinarySearchTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = PBGitBinarySearchTests.m; path = GitXTests/PBGitBinarySearchTests.m; sourceTree = "<group>"; };
719721
8A1C64D2B3E7492FA0561D41 /* OpenRecentControllerErrorTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = OpenRecentControllerErrorTests.m; path = GitXTests/OpenRecentControllerErrorTests.m; sourceTree = "<group>"; };
@@ -858,6 +860,7 @@
858860
isa = PBXGroup;
859861
children = (
860862
689D57B4A78CEF3B32EB0044 /* PBGitRevListRaceConditionTests.m */,
863+
4C2D8E3FA01B52C4D6E7F802 /* PBGitRevListEnumerationErrorTests.m */,
861864
7A1C4E2B90D3F5A6C1B80012 /* PBGitRepositoryFetchArgumentsTests.m */,
862865
2F9D30A7C15B4E68B4720A51 /* PBGitBinarySearchTests.m */,
863866
8A1C64D2B3E7492FA0561D41 /* OpenRecentControllerErrorTests.m */,
@@ -1819,6 +1822,7 @@
18191822
buildActionMask = 2147483647;
18201823
files = (
18211824
63E155858B2CC783EE10F1D7 /* PBGitRevListRaceConditionTests.m in Sources */,
1825+
4C2D8E3FA01B52C4D6E7F801 /* PBGitRevListEnumerationErrorTests.m in Sources */,
18221826
7A1C4E2B90D3F5A6C1B80011 /* PBGitRepositoryFetchArgumentsTests.m in Sources */,
18231827
2F9D30A7C15B4E68B4720A50 /* PBGitBinarySearchTests.m in Sources */,
18241828
8A1C64D2B3E7492FA0561D40 /* OpenRecentControllerErrorTests.m in Sources */,
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//
2+
// PBGitRevListEnumerationErrorTests.m
3+
// GitXTests
4+
//
5+
6+
#import <XCTest/XCTest.h>
7+
#import <ObjectiveGit/ObjectiveGit.h>
8+
#import "PBGitRevList.h"
9+
10+
// Exposes the walk itself, so the failure can be driven directly rather than by
11+
// arranging for a real repository to break under a running load.
12+
@interface PBGitRevList (EnumerationErrorTesting)
13+
- (void)addCommitsFromEnumerator:(GTEnumerator *)enumerator operation:(NSOperation *)operation generation:(NSUInteger)generation;
14+
@end
15+
16+
// Stands in for an enumerator whose walk cannot continue, which is what a
17+
// repository being deleted, moved or unmounted produces. The walk only ever asks
18+
// it for the next OID, so none of the rest of GTEnumerator is needed here.
19+
@interface PBFailingEnumerator : NSObject
20+
@end
21+
22+
@implementation PBFailingEnumerator
23+
24+
- (GTOID *)nextOIDWithSuccess:(BOOL *)success error:(NSError **)error
25+
{
26+
if (success) {
27+
*success = NO;
28+
}
29+
if (error) {
30+
*error = [NSError errorWithDomain:GTGitErrorDomain
31+
code:-1
32+
userInfo:@{NSLocalizedDescriptionKey : @"the walk could not be continued"}];
33+
}
34+
return nil;
35+
}
36+
37+
@end
38+
39+
@interface PBGitRevListEnumerationErrorTests : XCTestCase
40+
@end
41+
42+
@implementation PBGitRevListEnumerationErrorTests
43+
44+
// A walk that fails part-way used to end on NSAssert(!enumError, ...), raising
45+
// NSInternalInconsistencyException. Assertions are live in Release too, so the
46+
// repository changing under an open window took the application down with no
47+
// sheet and nothing said about the error that was already in hand.
48+
- (void)testAFailedWalkDoesNotRaise
49+
{
50+
PBGitRevList *revList = [[PBGitRevList alloc] initWithRepository:nil rev:nil shouldGraph:NO];
51+
PBFailingEnumerator *enumerator = [[PBFailingEnumerator alloc] init];
52+
53+
XCTAssertNoThrow([revList addCommitsFromEnumerator:(GTEnumerator *)enumerator
54+
operation:[[NSOperation alloc] init]
55+
generation:1]);
56+
}
57+
58+
@end

0 commit comments

Comments
 (0)