Skip to content

Commit 1bad051

Browse files
committed
Bugfix: fix duplicate commits in the history view
1) stop a threading issue with old commits being added after the commits array was reset 2) stop using --early-output (shouldn't there be an incremental output option???)
1 parent 25caa84 commit 1bad051

5 files changed

+31
-31
lines changed

PBGitHistoryGrapher.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,23 @@
99
#import <Cocoa/Cocoa.h>
1010

1111

12+
#define kCurrentQueueKey @"kCurrentQueueKey"
13+
#define kNewCommitsKey @"kNewCommitsKey"
14+
15+
1216
@class PBGitGrapher;
1317

1418

1519
@interface PBGitHistoryGrapher : NSObject {
1620
id delegate;
21+
NSOperationQueue *currentQueue;
1722

1823
NSMutableSet *searchSHAs;
1924
PBGitGrapher *grapher;
2025
BOOL viewAllBranches;
2126
}
2227

23-
- (id) initWithBaseCommits:(NSSet *)commits viewAllBranches:(BOOL)viewAll delegate:(id)theDelegate;
28+
- (id) initWithBaseCommits:(NSSet *)commits viewAllBranches:(BOOL)viewAll queue:(NSOperationQueue *)queue delegate:(id)theDelegate;
2429
- (void) graphCommits:(NSArray *)revList;
2530

2631
@end

PBGitHistoryGrapher.m

+11-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
@implementation PBGitHistoryGrapher
1414

1515

16-
- (id) initWithBaseCommits:(NSSet *)commits viewAllBranches:(BOOL)viewAll delegate:(id)theDelegate
16+
- (id) initWithBaseCommits:(NSSet *)commits viewAllBranches:(BOOL)viewAll queue:(NSOperationQueue *)queue delegate:(id)theDelegate
1717
{
1818
delegate = theDelegate;
19+
currentQueue = queue;
1920
searchSHAs = [NSMutableSet setWithSet:commits];
2021
grapher = [[PBGitGrapher alloc] initWithRepository:nil];
2122
viewAllBranches = viewAll;
@@ -24,6 +25,13 @@ - (id) initWithBaseCommits:(NSSet *)commits viewAllBranches:(BOOL)viewAll delega
2425
}
2526

2627

28+
- (void)sendCommits:(NSArray *)commits
29+
{
30+
NSDictionary *commitData = [NSDictionary dictionaryWithObjectsAndKeys:currentQueue, kCurrentQueueKey, commits, kNewCommitsKey, nil];
31+
[delegate performSelectorOnMainThread:@selector(updateCommitsFromGrapher:) withObject:commitData waitUntilDone:NO];
32+
}
33+
34+
2735
- (void) graphCommits:(NSArray *)revList
2836
{
2937
if (!revList || [revList count] == 0)
@@ -43,12 +51,12 @@ - (void) graphCommits:(NSArray *)revList
4351
}
4452
}
4553
if (++counter % 2000 == 0) {
46-
[delegate performSelectorOnMainThread:@selector(addCommitsFromArray:) withObject:[commits copy] waitUntilDone:NO];
54+
[self sendCommits:commits];
4755
commits = [NSMutableArray array];
4856
}
4957
}
5058

51-
[delegate performSelectorOnMainThread:@selector(addCommitsFromArray:) withObject:commits waitUntilDone:YES];
59+
[self sendCommits:commits];
5260
[delegate performSelectorOnMainThread:@selector(finishedGraphing) withObject:nil waitUntilDone:NO];
5361
}
5462

PBGitHistoryList.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
- (void) forceUpdate;
4141
- (void) updateHistory;
4242

43-
- (void) addCommitsFromArray:(NSArray *)array;
43+
- (void) updateCommitsFromGrapher:(NSDictionary *)commitData;
4444

4545

4646
@property (retain) PBGitRevList *projectRevList;

PBGitHistoryList.m

+12-1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ - (void) addCommitsFromArray:(NSArray *)array
9595
{
9696
if (!array || [array count] == 0)
9797
return;
98+
9899
if (resetCommits) {
99100
self.commits = [NSMutableArray array];
100101
resetCommits = NO;
@@ -109,6 +110,14 @@ - (void) addCommitsFromArray:(NSArray *)array
109110
}
110111

111112

113+
- (void) updateCommitsFromGrapher:(NSDictionary *)commitData
114+
{
115+
if ([commitData objectForKey:kCurrentQueueKey] != graphQueue)
116+
return;
117+
118+
[self addCommitsFromArray:[commitData objectForKey:kNewCommitsKey]];
119+
}
120+
112121
- (void) finishedGraphing
113122
{
114123
if (!currentRevList.isParsing && ([[graphQueue operations] count] == 0)) {
@@ -204,7 +213,7 @@ - (PBGitHistoryGrapher *) grapher
204213
{
205214
BOOL viewAllBranches = (repository.currentBranchFilter == kGitXAllBranchesFilter);
206215

207-
return [[PBGitHistoryGrapher alloc] initWithBaseCommits:[self baseCommits] viewAllBranches:viewAllBranches delegate:self];
216+
return [[PBGitHistoryGrapher alloc] initWithBaseCommits:[self baseCommits] viewAllBranches:viewAllBranches queue:graphQueue delegate:self];
208217
}
209218

210219

@@ -301,6 +310,7 @@ - (void) updateProjectHistoryForRev:(PBGitRevSpecifier *)rev
301310
lastBranchFilter = -1;
302311
lastRemoteRef = nil;
303312
lastSHA = nil;
313+
self.commits = [NSMutableArray array];
304314
[projectRevList loadRevisons];
305315
return;
306316
}
@@ -318,6 +328,7 @@ - (void) updateHistoryForRev:(PBGitRevSpecifier *)rev
318328
lastBranchFilter = -1;
319329
lastRemoteRef = nil;
320330
lastSHA = nil;
331+
self.commits = [NSMutableArray array];
321332

322333
[otherRevListParser loadRevisons];
323334
}

PBGitRevList.mm

+1-25
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ - (void) walkRevisionListWithSpecifier:(PBGitRevSpecifier*)rev
102102
if (showSign)
103103
formatString = [formatString stringByAppendingString:@"\01%m"];
104104

105-
NSMutableArray *arguments = [NSMutableArray arrayWithObjects:@"log", @"-z", @"--early-output", @"--topo-order", @"--children", formatString, nil];
105+
NSMutableArray *arguments = [NSMutableArray arrayWithObjects:@"log", @"-z", @"--topo-order", @"--children", formatString, nil];
106106

107107
if (!rev)
108108
[arguments addObject:@"HEAD"];
@@ -124,30 +124,6 @@ - (void) walkRevisionListWithSpecifier:(PBGitRevSpecifier*)rev
124124
if (!getline(stream, sha, '\1'))
125125
break;
126126

127-
// We reached the end of some temporary output. Show what we have
128-
// until now, and then start again. The sha of the next thing is still
129-
// in this buffer. So, we use a substring of current input.
130-
if (sha[1] == 'i') // Matches 'Final output'
131-
{
132-
num = 0;
133-
if ([currentThread isCancelled])
134-
break;
135-
136-
NSDictionary *update = [NSDictionary dictionaryWithObjectsAndKeys:currentThread, kRevListThreadKey, revisions, kRevListRevisionsKey, nil];
137-
[self performSelectorOnMainThread:@selector(updateCommits:) withObject:update waitUntilDone:NO];
138-
revisions = [NSMutableArray array];
139-
140-
if (isGraphing)
141-
g = [[PBGitGrapher alloc] initWithRepository:repository];
142-
revisions = [NSMutableArray array];
143-
144-
// If the length is < 40, then there are no commits.. quit now
145-
if (sha.length() < 40)
146-
break;
147-
148-
sha = sha.substr(sha.length() - 40, 40);
149-
}
150-
151127
// From now on, 1.2 seconds
152128
string encoding_str;
153129
getline(stream, encoding_str, '\1');

0 commit comments

Comments
 (0)