forked from brotherbard/gitx
-
Notifications
You must be signed in to change notification settings - Fork 2
/
PBGitHistoryGrapher.m
75 lines (60 loc) · 2.04 KB
/
PBGitHistoryGrapher.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//
// PBGitHistoryGrapher.m
// GitX
//
// Created by Nathan Kinsinger on 2/20/10.
// Copyright 2010 Nathan Kinsinger. All rights reserved.
//
#import "PBGitHistoryGrapher.h"
#import "PBGitGrapher.h"
#import "PBGitSHA.h"
@implementation PBGitHistoryGrapher
- (id) initWithBaseCommits:(NSSet *)commits viewAllBranches:(BOOL)viewAll queue:(NSOperationQueue *)queue delegate:(id)theDelegate
{
delegate = theDelegate;
currentQueue = queue;
searchSHAs = [NSMutableSet setWithSet:commits];
grapher = [[PBGitGrapher alloc] initWithRepository:nil];
viewAllBranches = viewAll;
return self;
}
- (void)sendCommits:(NSArray *)commits
{
NSDictionary *commitData = [NSDictionary dictionaryWithObjectsAndKeys:currentQueue, kCurrentQueueKey, commits, kNewCommitsKey, nil];
[delegate performSelectorOnMainThread:@selector(updateCommitsFromGrapher:) withObject:commitData waitUntilDone:NO];
}
- (void) graphCommits:(NSArray *)revList
{
if (!revList || [revList count] == 0)
return;
//NSDate *start = [NSDate date];
NSThread *currentThread = [NSThread currentThread];
NSDate *lastUpdate = [NSDate date];
NSMutableArray *commits = [NSMutableArray array];
NSInteger counter = 0;
for (PBGitCommit *commit in revList) {
if ([currentThread isCancelled])
return;
PBGitSHA *commitSHA = [commit sha];
if (viewAllBranches || [searchSHAs containsObject:commitSHA]) {
[grapher decorateCommit:commit];
[commits addObject:commit];
if (!viewAllBranches) {
[searchSHAs removeObject:commitSHA];
[searchSHAs addObjectsFromArray:[commit parents]];
}
}
if (++counter % 100 == 0) {
if ([[NSDate date] timeIntervalSinceDate:lastUpdate] > 0.1) {
[self sendCommits:commits];
commits = [NSMutableArray array];
lastUpdate = [NSDate date];
}
}
}
//NSTimeInterval duration = [[NSDate date] timeIntervalSinceDate:start];
//NSLog(@"Graphed %i commits in %f seconds (%f/sec)", counter, duration, counter/duration);
[self sendCommits:commits];
[delegate performSelectorOnMainThread:@selector(finishedGraphing) withObject:nil waitUntilDone:NO];
}
@end