Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Commit cb2beee

Browse files
author
kernel
committed
Perform statistics requests on same background queue as all git operations (crash fixed).
1 parent aa21ab7 commit cb2beee

14 files changed

+125
-76
lines changed

Git Code.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,7 @@
888888
1E969A6118DF03C300D02FED /* GTRepository+Gitty.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "GTRepository+Gitty.h"; sourceTree = "<group>"; };
889889
1E969A6218DF03C300D02FED /* GTRepository+Gitty.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GTRepository+Gitty.m"; sourceTree = "<group>"; };
890890
1E9877F919A0F25300821078 /* DALoginCtrl+Internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DALoginCtrl+Internal.h"; sourceTree = "<group>"; };
891+
1E98780619A1102F00821078 /* DAGitManager+Internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DAGitManager+Internal.h"; sourceTree = "<group>"; };
891892
1EADB752190BF6A100038737 /* AMWaveTransition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AMWaveTransition.h; sourceTree = "<group>"; };
892893
1EADB753190BF6A100038737 /* AMWaveTransition.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AMWaveTransition.m; sourceTree = "<group>"; };
893894
1EADB754190BF6A100038737 /* AMWaveViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AMWaveViewController.h; sourceTree = "<group>"; };
@@ -1871,6 +1872,7 @@
18711872
189016B1175AA38900F19CE4 /* Actions */,
18721873
18D9EA3B17554EB400454F3C /* DAGitManager.h */,
18731874
18D9EA3C17554EB400454F3C /* DAGitManager.m */,
1875+
1E98780619A1102F00821078 /* DAGitManager+Internal.h */,
18741876
189016B9175AA6D700F19CE4 /* DAGitManager+ActionsInterface.h */,
18751877
189016BA175AA6D800F19CE4 /* DAGitManager+ActionsInterface.m */,
18761878
18EADFDF176F05EA005D0F28 /* DAGitUser.h */,

Gitty/DAAppDelegate.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ - (BOOL)processRepoUrl:(NSURL *)inputUrl loginCtrl:(DALoginCtrl *)loginCtrl {
111111

112112
[loginCtrl exploreRepoWithPath:repoPath];
113113

114+
[DAFlurry logWorkflowAction:WorkflowActionRepoCreatedExternallyViaProtocolScheme];
115+
114116
return YES;
115117
}
116118

Gitty/DAFlurry.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ extern NSString *WorkflowActionByBranchRevealed, *WorkflowActionByAuthorRevealed
3434

3535
extern NSString *WorkflowActionSSHKeysAdded, *WorkflowActionBadSSHKeysFound, *WorkflowActionLoginUsingCredentials, *WorkflowActionUnboundSSHKeysFound;
3636

37+
extern NSString *WorkflowActionServerRemoved;
38+
extern NSString *WorkflowActionRepoCreatedExternallyViaProtocolScheme;
39+
3740
@interface DAFlurry (GittyEvents)
3841
+ (void)logSuccessServer:(NSString *)name;
3942
+ (void)logInvalidServer:(NSString *)name;

Gitty/DAFlurry.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ - (void)endTimedEvent:(DAFlurryEvent *)event {
6666

6767
NSString *WorkflowActionSSHKeysAdded = @"SSH keys added", *WorkflowActionBadSSHKeysFound = @"Bad SSH keys found", *WorkflowActionLoginUsingCredentials = @"Login with Credentials", *WorkflowActionUnboundSSHKeysFound = @"SSH not bound to Server found.";
6868

69+
NSString *WorkflowActionServerRemoved = @"Server Removed";
70+
NSString *WorkflowActionRepoCreatedExternallyViaProtocolScheme = @"Repo Created Externally (Scheme)";
71+
6972
@implementation DAFlurry (GittyEvents)
7073

7174
+ (void)logSuccessServer:(NSString *)name {

Gitty/DAGitManager+Internal.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// DAGitManager+Internal.h
3+
// Git Code
4+
//
5+
// Created by Altukhov Anton on 8/17/14.
6+
// Copyright (c) 2014 ReImpl. All rights reserved.
7+
//
8+
9+
#import "DAGitManager.h"
10+
11+
@interface DAGitManager (Internal)
12+
@property (nonatomic, nonatomic, readonly) dispatch_queue_t q;
13+
@end

Gitty/DAGitManager.m

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,19 @@
77
//
88

99
#import "DAGitManager.h"
10+
#import "DAGitManager+Internal.h"
1011
#import "DAGitManager+ActionsInterface.h"
12+
1113
#import "DAGitAction+ManagerAccess.h"
1214

1315
static id sharedInstance = nil;
1416
static NSString *RepoRootFolderName = @"Repos";
1517
static NSString *DeletableFolderSuffix = @"md";
1618

19+
@interface DAGitManager ()
20+
@property (nonatomic, nonatomic, readwrite) dispatch_queue_t q;
21+
@end
22+
1723
@implementation DAGitManager
1824
@dynamic app;
1925

@@ -37,6 +43,9 @@ - (id)init {
3743
if (self) {
3844
_repoRootPath = [self.app.cachesPath stringByAppendingPathComponent:RepoRootFolderName];
3945
[self.app.fs createDirectoryIfNotExists:self.repoRootPath];
46+
47+
// libgit module is not multithreaded.
48+
_q = dispatch_queue_create("gitcode.qit.operations", DISPATCH_QUEUE_SERIAL);
4049
}
4150
return self;
4251
}
@@ -49,8 +58,7 @@ - (void)request:(DAGitAction *)action delegateQueue:(dispatch_queue_t)queue {
4958
action.manager = self;
5059
action.delegateQueue = queue;
5160

52-
dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
53-
dispatch_async(q, ^{
61+
dispatch_async(self.q, ^{
5462
[action exec];
5563
[action finilize];
5664
});

Gitty/DAGitStats.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
@interface DAGitStats : NSObject
1818
+ (instancetype)statsForRepository:(GTRepository *)repo;
1919

20-
- (void)performSyncOperation:(id<DAGitOperation>)operation;
20+
//- (void)performSyncOperation:(id<DAGitOperation>)operation;
2121
- (void)performAsyncOperation:(id<DAGitOperation>)operation completionHandler:(void(^)())handler;
2222
@end

Gitty/DAGitStats.m

Lines changed: 7 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@
88

99
#import "DAGitStats.h"
1010

11+
#import "DAGitManager+Internal.h"
12+
1113
@interface DAGitStats ()
1214
@property (strong, nonatomic, readonly) GTRepository *repo;
13-
14-
@property (strong, nonatomic, readonly) NSOperationQueue *q;
15-
//@property (strong, nonatomic, readonly) GTEnumerator *iter;
16-
//@property (strong, nonatomic, readonly) NSArray *branches, *commits;
1715
@end
1816

1917
@implementation DAGitStats
@@ -25,69 +23,28 @@ + (instancetype)statsForRepository:(GTRepository *)repo {
2523
return stats;
2624
}
2725

28-
- (id)init {
29-
self = [super init];
30-
if (self) {
31-
_q = NSOperationQueue.new;
32-
}
33-
return self;
34-
}
35-
3626
- (void)load:(GTRepository *)repo {
3727
_repo = repo;
3828
}
3929

4030
- (void)performSyncOperation:(id<DAGitOperation>)operation {
41-
[operation perform];
31+
dispatch_sync(DAGitManager.manager.q, ^{
32+
[operation perform];
33+
});
4234
}
4335

4436
- (void)performAsyncOperation:(id<DAGitOperation>)operation completionHandler:(void(^)())handler {
4537
NSOperationQueue *callee = NSOperationQueue.currentQueue;
4638

47-
[self.q addOperationWithBlock:^{
39+
dispatch_async(DAGitManager.manager.q, ^{
4840
[operation perform];
4941

5042
if (handler) {
5143
[callee addOperationWithBlock:^{
5244
handler();
5345
}];
5446
}
55-
}];
56-
}
57-
58-
/*
59-
60-
- (void)loadAllCommits {
61-
NSError *err = nil;
62-
_iter = [GTEnumerator.alloc initWithRepository:self.repo error:&err];
63-
64-
[self.iter resetWithOptions:GTEnumeratorOptionsTimeSort];
65-
66-
[self.iter pushGlob:@"refs/remotes/origin/" error:&err];
67-
"refs/remotes/origin / *"
68-
69-
NSArray *commits = [self.iter allObjectsWithError:&err];
70-
71-
[Logger info:@"\nCommits (%d): ", commits.count];
72-
for (GTCommit *ci in commits) {
73-
[Logger info:@"0x%X %@ : %@ : %@", ci, ci.shortSHA, ci.SHA, ci.messageSummary];
74-
}
75-
[Logger info:@"-----"];
76-
77-
_commits = commits;
47+
});
7848
}
7949

80-
- (void)performWalkOnBranch:(GTBranch *)branch {
81-
NSError *err = nil;
82-
[self.iter pushSHA:branch.SHA error:&err];
83-
84-
NSArray *commits = [self.iter allObjectsWithError:&err];
85-
86-
[Logger info:@"\n %@ br_commits (%d): ", branch.name, commits.count];
87-
for (GTCommit *ci in commits) {
88-
[Logger info:@"0x%X %@ : %@ : %@", ci, ci.shortSHA, ci.SHA, ci.messageSummary];
89-
}
90-
[Logger info:@"-----"];
91-
}
92-
*/
9350
@end

Gitty/DALoginCtrl.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ - (void)deleteCurrentServer {
185185
});
186186

187187
self.serverDotsControl.numberOfPages = self.servers.list.count + 1;
188+
189+
[DAFlurry logWorkflowAction:WorkflowActionServerRemoved];
188190
}
189191

190192
- (DAGitServer *)createNewServerWithDictionary:(NSDictionary *)info {
@@ -364,9 +366,8 @@ - (void)cloneRemoteRepoWithName:(NSString *)repoName fromServer:(DAGitServer *)s
364366

365367
[self.currentServer addOrUpdateRecentRepoWithRelativePath:repoName];
366368
self.currentServer.recentRepoPath = repoName;
367-
[self.servers save];
368369

369-
// [self.currentCtrl resetCredentials];
370+
[self.servers save];
370371
};
371372

372373
DAGitClone *clone = [DAGitClone cloneRepoWithName:repoName fromServer:server];

Gitty/DARepoCtrl+GitFetcher.m

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@ - (void)pull {
3939
BOOL hasZeroReceivedObjects = thisDelegate.receivedObjects == 0;
4040

4141
if (err && hasZeroReceivedObjects) {
42-
// Load stats anyway if nothing was updated.
43-
[ctrl loadStats];
44-
4542
if (GIT_EEXISTS == err.code) {
4643
// Repo is up to date. No updates fetched.
44+
45+
// Load stats anyway if nothing was updated.
46+
[ctrl loadStats];
47+
48+
[DAFlurry logGitAction:GitActionPullSuccess];
4749
} else {
4850
Alert *alert = [Alert errorAlertWithMessage:err.localizedDescription];
4951
[AlertQueue.queue enqueueAlert:alert];
@@ -54,8 +56,10 @@ - (void)pull {
5456
return;
5557
}
5658

57-
[ctrl reloadFilters];
58-
[ctrl reloadCommitsAndOptionallyTable:YES];
59+
if (!hasZeroReceivedObjects) {
60+
[ctrl reloadFilters];
61+
[ctrl reloadCommitsTable];
62+
}
5963

6064
[ctrl loadStats];
6165

Gitty/DARepoCtrl+Private.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
- (void)reloadFilters;
2929
- (void)addBranchesButton;
3030
- (void)presentRevealStatsHint;
31-
- (BOOL)reloadCommitsAndOptionallyTable:(BOOL)shoudReloadTable;
31+
- (BOOL)reloadCommitsTable;
3232
@end
3333

3434
#endif

Gitty/DARepoCtrl.m

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,29 @@
2525
static NSString *StatsSegue = @"StatsSegue";
2626

2727
static const CGFloat StatsContainerMinDraggingOffsetToSwitchState = 100.;
28-
//static const CGFloat BranchOverlyMinDraggingOffsetToSwitchState = 100.;
2928

3029
@interface DARepoCtrl ()
3130
@property (strong, nonatomic, readonly) DAStatsCtrl *statsCtrl;
3231
@property (strong, nonatomic, readonly) DAReposListCtrl *recentReposCtrl;
3332

3433
@property (strong, nonatomic, readonly) UIButton *statsSelectedModeButton;
34+
35+
@property (weak, nonatomic) IBOutlet UIView *branchStatsLoadingContainer;
36+
@property (weak, nonatomic) IBOutlet UILabel *branchStatsInfoLabel;
37+
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *branchStatsLoadingIndicator;
3538
@end
3639

3740
@implementation DARepoCtrl {
41+
NSArray *_remoteBranches, *_tags;
42+
3843
CGFloat statsContainerOffsetBeforeDragging;
3944
CGFloat branchContainerOffsetBeforeDragging;
40-
NSArray *_remoteBranches, *_tags;
4145
}
4246
@synthesize branches = _branches;
43-
@synthesize currentBranch = _currentBranch, currentTag = _currentTag;
47+
@synthesize currentBranch = _currentBranch;
48+
@synthesize currentTag = _currentTag;
4449
@synthesize statsCtrl = _statsCtrl;
50+
4551
// Category-defined ivars synthesized explicitly.
4652
@synthesize remoteBranches = _remoteBranches;
4753
@synthesize namedBranches;
@@ -149,7 +155,7 @@ - (BOOL)loadInitialData {
149155

150156
[self reloadFilters];
151157

152-
if (![self reloadCommitsAndOptionallyTable:NO]) {
158+
if (![self reloadCommitsTable]) {
153159
return NO;
154160
}
155161

@@ -293,24 +299,41 @@ - (BOOL)selectBranch:(GTBranch *)branch {
293299
return YES;
294300
}
295301

296-
- (BOOL)reloadCommitsAndOptionallyTable:(BOOL)shoudReloadTable {
302+
- (BOOL)reloadCommitsTable {
303+
NSString *message = nil;
297304
DABranchWalk *walk = nil;
298305

299306
if (self.currentBranch) {
307+
message = NSLocalizedString(@"Loading '%@' branch ...", nil);
308+
message = [NSString stringWithFormat:message, self.currentBranch.shortName];
309+
300310
walk = [DABranchWalk walkForBranch:self.currentBranch];
301311
} else if (self.currentTag) {
312+
message = NSLocalizedString(@"Loading '%@' tag ...", nil);
313+
message = [NSString stringWithFormat:message, self.currentTag.name];
314+
302315
walk = [DABranchWalk walkForTag:self.currentTag];
303316
} else {
304317
return NO;
305318
}
306319

307-
[self.stats performSyncOperation:walk];
320+
self.branchStatsInfoLabel.text = message;
308321

309-
_currentStats = walk;
322+
self.commitsTable.hidden = YES;
310323

311-
if (shoudReloadTable) {
324+
[self.branchStatsLoadingIndicator startAnimating];
325+
self.branchStatsLoadingContainer.hidden = NO;
326+
327+
328+
[self.stats performAsyncOperation:walk completionHandler:^{
329+
self.commitsTable.hidden = NO;
312330
[self.commitsTable reloadData];
313-
}
331+
332+
[self.branchStatsLoadingIndicator stopAnimating];
333+
self.branchStatsLoadingContainer.hidden = YES;
334+
}];
335+
336+
_currentStats = walk;
314337

315338
return YES;
316339
}
@@ -378,7 +401,7 @@ - (IBAction)rightOptionPressed:(UIButton *)button {
378401

379402
BOOL changed = [ref selectTag:selectedTag];
380403
if (changed) {
381-
[ref reloadCommitsAndOptionallyTable:YES];
404+
[ref reloadCommitsTable];
382405

383406
[DAFlurry logWorkflowAction:WorkflowActionTagSwitched];
384407
}
@@ -388,7 +411,7 @@ - (IBAction)rightOptionPressed:(UIButton *)button {
388411

389412
BOOL changed = [ref selectBranch:selectedBranch];
390413
if (changed) {
391-
[ref reloadCommitsAndOptionallyTable:YES];
414+
[ref reloadCommitsTable];
392415

393416
[DAFlurry logWorkflowAction:WorkflowActionBranchSwitched];
394417
}

Gitty/Git Code-Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<key>CFBundlePackageType</key>
1818
<string>APPL</string>
1919
<key>CFBundleShortVersionString</key>
20-
<string>1.3.3</string>
20+
<string>1.4</string>
2121
<key>CFBundleSignature</key>
2222
<string>????</string>
2323
<key>CFBundleURLTypes</key>
@@ -33,7 +33,7 @@
3333
</dict>
3434
</array>
3535
<key>CFBundleVersion</key>
36-
<string>1.3.205</string>
36+
<string>1.4.209</string>
3737
<key>LSRequiresIPhoneOS</key>
3838
<true/>
3939
<key>UIFileSharingEnabled</key>

0 commit comments

Comments
 (0)