Skip to content

Commit 8c94e1b

Browse files
committed
Optimize revision walker bindings
This simplifies the procedure used to walk revisions by only loading in commits if the branch selection was changed.
1 parent caf3b92 commit 8c94e1b

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

PBGitRepository.m

+4-2
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ - (BOOL)readFromFileWrapper:(NSFileWrapper *)fileWrapper ofType:(NSString *)type
118118

119119
if (success) {
120120
[self readRefs];
121-
[self readCurrentBranch];
122121
revisionList = [[PBGitRevList alloc] initWithRepository:self];
122+
[self readCurrentBranch];
123123
}
124124
}
125125

@@ -133,8 +133,10 @@ - (id) initWithURL: (NSURL*) path andRevSpecifier:(PBGitRevSpecifier*) rev
133133
[self setFileURL: gitDirURL];
134134

135135
[self readRefs];
136-
[self selectBranch: [self addBranch: rev]];
136+
137137
revisionList = [[PBGitRevList alloc] initWithRepository:self];
138+
[self selectBranch: [self addBranch: rev]];
139+
138140
return self;
139141
}
140142
// The fileURL the document keeps is to the .git dir, but that’s pretty

PBGitRevList.m

+5-4
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ @implementation PBGitRevList
1818
- initWithRepository: (id) repo
1919
{
2020
repository = repo;
21-
22-
[self readCommits];
2321
[repository addObserver:self forKeyPath:@"currentBranch" options:0 context:nil];
2422

2523
return self;
@@ -31,10 +29,13 @@ - (void) readCommits
3129
// we can check if the current branch is the same as the previous one
3230
// and in that case we don't have to reload the revision list.
3331

34-
// If no branch was selected, use the current HEAD
32+
// If no branch is selected, don't do anything
33+
if (![repository currentBranch] || [[repository currentBranch] count] == 0)
34+
return;
35+
3536
NSArray* selectedBranches = [[repository branches] objectsAtIndexes: [repository currentBranch]];
3637

37-
// Apparently, we don't have a current branch yet. Let's skip it.
38+
// Apparently, The selected index does not exist.. don't do anything
3839
if ([selectedBranches count] == 0)
3940
return;
4041

0 commit comments

Comments
 (0)