Skip to content

Commit

Permalink
Bugfix: fix duplicate commits in the history view
Browse files Browse the repository at this point in the history
    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???)
  • Loading branch information
brotherbard committed Jul 4, 2010
1 parent 25caa84 commit 1bad051
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 31 deletions.
7 changes: 6 additions & 1 deletion PBGitHistoryGrapher.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,18 +9,23 @@
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>




#define kCurrentQueueKey @"kCurrentQueueKey"
#define kNewCommitsKey @"kNewCommitsKey"


@class PBGitGrapher; @class PBGitGrapher;




@interface PBGitHistoryGrapher : NSObject { @interface PBGitHistoryGrapher : NSObject {
id delegate; id delegate;
NSOperationQueue *currentQueue;


NSMutableSet *searchSHAs; NSMutableSet *searchSHAs;
PBGitGrapher *grapher; PBGitGrapher *grapher;
BOOL viewAllBranches; BOOL viewAllBranches;
} }


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


@end @end
14 changes: 11 additions & 3 deletions PBGitHistoryGrapher.m
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
@implementation PBGitHistoryGrapher @implementation PBGitHistoryGrapher




- (id) initWithBaseCommits:(NSSet *)commits viewAllBranches:(BOOL)viewAll delegate:(id)theDelegate - (id) initWithBaseCommits:(NSSet *)commits viewAllBranches:(BOOL)viewAll queue:(NSOperationQueue *)queue delegate:(id)theDelegate
{ {
delegate = theDelegate; delegate = theDelegate;
currentQueue = queue;
searchSHAs = [NSMutableSet setWithSet:commits]; searchSHAs = [NSMutableSet setWithSet:commits];
grapher = [[PBGitGrapher alloc] initWithRepository:nil]; grapher = [[PBGitGrapher alloc] initWithRepository:nil];
viewAllBranches = viewAll; viewAllBranches = viewAll;
Expand All @@ -24,6 +25,13 @@ - (id) initWithBaseCommits:(NSSet *)commits viewAllBranches:(BOOL)viewAll delega
} }




- (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 - (void) graphCommits:(NSArray *)revList
{ {
if (!revList || [revList count] == 0) if (!revList || [revList count] == 0)
Expand All @@ -43,12 +51,12 @@ - (void) graphCommits:(NSArray *)revList
} }
} }
if (++counter % 2000 == 0) { if (++counter % 2000 == 0) {
[delegate performSelectorOnMainThread:@selector(addCommitsFromArray:) withObject:[commits copy] waitUntilDone:NO]; [self sendCommits:commits];
commits = [NSMutableArray array]; commits = [NSMutableArray array];
} }
} }


[delegate performSelectorOnMainThread:@selector(addCommitsFromArray:) withObject:commits waitUntilDone:YES]; [self sendCommits:commits];
[delegate performSelectorOnMainThread:@selector(finishedGraphing) withObject:nil waitUntilDone:NO]; [delegate performSelectorOnMainThread:@selector(finishedGraphing) withObject:nil waitUntilDone:NO];
} }


Expand Down
2 changes: 1 addition & 1 deletion PBGitHistoryList.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
- (void) forceUpdate; - (void) forceUpdate;
- (void) updateHistory; - (void) updateHistory;


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




@property (retain) PBGitRevList *projectRevList; @property (retain) PBGitRevList *projectRevList;
Expand Down
13 changes: 12 additions & 1 deletion PBGitHistoryList.m
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ - (void) addCommitsFromArray:(NSArray *)array
{ {
if (!array || [array count] == 0) if (!array || [array count] == 0)
return; return;

if (resetCommits) { if (resetCommits) {
self.commits = [NSMutableArray array]; self.commits = [NSMutableArray array];
resetCommits = NO; resetCommits = NO;
Expand All @@ -109,6 +110,14 @@ - (void) addCommitsFromArray:(NSArray *)array
} }




- (void) updateCommitsFromGrapher:(NSDictionary *)commitData
{
if ([commitData objectForKey:kCurrentQueueKey] != graphQueue)
return;

[self addCommitsFromArray:[commitData objectForKey:kNewCommitsKey]];
}

- (void) finishedGraphing - (void) finishedGraphing
{ {
if (!currentRevList.isParsing && ([[graphQueue operations] count] == 0)) { if (!currentRevList.isParsing && ([[graphQueue operations] count] == 0)) {
Expand Down Expand Up @@ -204,7 +213,7 @@ - (PBGitHistoryGrapher *) grapher
{ {
BOOL viewAllBranches = (repository.currentBranchFilter == kGitXAllBranchesFilter); BOOL viewAllBranches = (repository.currentBranchFilter == kGitXAllBranchesFilter);


return [[PBGitHistoryGrapher alloc] initWithBaseCommits:[self baseCommits] viewAllBranches:viewAllBranches delegate:self]; return [[PBGitHistoryGrapher alloc] initWithBaseCommits:[self baseCommits] viewAllBranches:viewAllBranches queue:graphQueue delegate:self];
} }




Expand Down Expand Up @@ -301,6 +310,7 @@ - (void) updateProjectHistoryForRev:(PBGitRevSpecifier *)rev
lastBranchFilter = -1; lastBranchFilter = -1;
lastRemoteRef = nil; lastRemoteRef = nil;
lastSHA = nil; lastSHA = nil;
self.commits = [NSMutableArray array];
[projectRevList loadRevisons]; [projectRevList loadRevisons];
return; return;
} }
Expand All @@ -318,6 +328,7 @@ - (void) updateHistoryForRev:(PBGitRevSpecifier *)rev
lastBranchFilter = -1; lastBranchFilter = -1;
lastRemoteRef = nil; lastRemoteRef = nil;
lastSHA = nil; lastSHA = nil;
self.commits = [NSMutableArray array];


[otherRevListParser loadRevisons]; [otherRevListParser loadRevisons];
} }
Expand Down
26 changes: 1 addition & 25 deletions PBGitRevList.mm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ - (void) walkRevisionListWithSpecifier:(PBGitRevSpecifier*)rev
if (showSign) if (showSign)
formatString = [formatString stringByAppendingString:@"\01%m"]; formatString = [formatString stringByAppendingString:@"\01%m"];


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


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


// We reached the end of some temporary output. Show what we have
// until now, and then start again. The sha of the next thing is still
// in this buffer. So, we use a substring of current input.
if (sha[1] == 'i') // Matches 'Final output'
{
num = 0;
if ([currentThread isCancelled])
break;

NSDictionary *update = [NSDictionary dictionaryWithObjectsAndKeys:currentThread, kRevListThreadKey, revisions, kRevListRevisionsKey, nil];
[self performSelectorOnMainThread:@selector(updateCommits:) withObject:update waitUntilDone:NO];
revisions = [NSMutableArray array];

if (isGraphing)
g = [[PBGitGrapher alloc] initWithRepository:repository];
revisions = [NSMutableArray array];

// If the length is < 40, then there are no commits.. quit now
if (sha.length() < 40)
break;

sha = sha.substr(sha.length() - 40, 40);
}

// From now on, 1.2 seconds // From now on, 1.2 seconds
string encoding_str; string encoding_str;
getline(stream, encoding_str, '\1'); getline(stream, encoding_str, '\1');
Expand Down

0 comments on commit 1bad051

Please sign in to comment.