Skip to content

Commit 477926e

Browse files
committed
Merge pull request #470 from libgit2/local-commits
Better unique commit enumeration
2 parents 753d2d4 + fde3159 commit 477926e

File tree

3 files changed

+27
-29
lines changed

3 files changed

+27
-29
lines changed

ObjectiveGit/GTBranch.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ - (GTBranchType)branchType {
146146
}
147147

148148
- (NSArray *)uniqueCommitsRelativeToBranch:(GTBranch *)otherBranch error:(NSError **)error {
149-
GTEnumerator *enumerator = [self.repository enumerateUniqueCommitsUpToOID:self.OID relativeToOID:otherBranch.OID error:error];
149+
GTEnumerator *enumerator = [self.repository enumeratorForUniqueCommitsFromOID:self.OID relativeToOID:otherBranch.OID error:error];
150150
return [enumerator allObjectsWithError:error];
151151
}
152152

ObjectiveGit/GTRepository.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -543,16 +543,6 @@ NS_ASSUME_NONNULL_BEGIN
543543
/// distinguished using the value of `success`.
544544
- (nullable GTFilterList *)filterListWithPath:(NSString *)path blob:(nullable GTBlob *)blob mode:(GTFilterSourceMode)mode options:(GTFilterListOptions)options success:(nullable BOOL *)success error:(NSError **)error;
545545

546-
/// Creates an enumerator for finding all commits in the history of `headOID`
547-
/// that do not exist in the history of `baseOID`.
548-
///
549-
/// headOID - Must not be nil.
550-
/// baseOID - Must not be nil.
551-
/// error - If not NULL, set to any error that occurs.
552-
///
553-
/// Returns the created enumerator upon success, or `nil` if an error occurred.
554-
- (nullable GTEnumerator *)enumerateUniqueCommitsUpToOID:(GTOID *)headOID relativeToOID:(GTOID *)baseOID error:(NSError **)error;
555-
556546
/// Calculates how far ahead/behind the commit represented by `headOID` is,
557547
/// relative to the commit represented by `baseOID`.
558548
///
@@ -565,6 +555,16 @@ NS_ASSUME_NONNULL_BEGIN
565555
/// Returns whether `ahead` and `behind` were successfully calculated.
566556
- (BOOL)calculateAhead:(size_t *)ahead behind:(size_t *)behind ofOID:(GTOID *)headOID relativeToOID:(GTOID *)baseOID error:(NSError **)error;
567557

558+
/// Creates an enumerator for walking the unique commits, as determined by a
559+
/// pushing a starting OID and hiding the relative OID.
560+
///
561+
/// fromOID - The starting OID.
562+
/// relativeOID - The OID to hide.
563+
/// error - The error if one occurred.
564+
///
565+
/// Returns the enumerator or nil if an error occurred.
566+
- (nullable GTEnumerator *)enumeratorForUniqueCommitsFromOID:(GTOID *)fromOID relativeToOID:(GTOID *)relativeOID error:(NSError **)error;
567+
568568
@end
569569

570570
NS_ASSUME_NONNULL_END

ObjectiveGit/GTRepository.m

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -880,24 +880,6 @@ - (GTFilterList *)filterListWithPath:(NSString *)path blob:(GTBlob *)blob mode:(
880880
}
881881
}
882882

883-
- (GTEnumerator *)enumerateUniqueCommitsUpToOID:(GTOID *)headOID relativeToOID:(GTOID *)baseOID error:(NSError **)error {
884-
NSParameterAssert(headOID != nil);
885-
NSParameterAssert(baseOID != nil);
886-
887-
GTCommit *mergeBase = [self mergeBaseBetweenFirstOID:headOID secondOID:baseOID error:error];
888-
if (mergeBase == nil) return nil;
889-
890-
GTEnumerator *enumerator = [[GTEnumerator alloc] initWithRepository:self error:error];
891-
if (enumerator == nil) return nil;
892-
893-
[enumerator resetWithOptions:GTEnumeratorOptionsTimeSort];
894-
895-
if (![enumerator pushSHA:headOID.SHA error:error]) return nil;
896-
if (![enumerator hideSHA:mergeBase.OID.SHA error:error]) return nil;
897-
898-
return enumerator;
899-
}
900-
901883
- (BOOL)calculateAhead:(size_t *)ahead behind:(size_t *)behind ofOID:(GTOID *)headOID relativeToOID:(GTOID *)baseOID error:(NSError **)error {
902884
NSParameterAssert(headOID != nil);
903885
NSParameterAssert(baseOID != nil);
@@ -912,4 +894,20 @@ - (BOOL)calculateAhead:(size_t *)ahead behind:(size_t *)behind ofOID:(GTOID *)he
912894
return YES;
913895
}
914896

897+
- (nullable GTEnumerator *)enumeratorForUniqueCommitsFromOID:(GTOID *)fromOID relativeToOID:(GTOID *)relativeOID error:(NSError **)error {
898+
NSParameterAssert(fromOID != nil);
899+
NSParameterAssert(relativeOID != nil);
900+
901+
GTEnumerator *enumerator = [[GTEnumerator alloc] initWithRepository:self error:error];
902+
if (enumerator == nil) return nil;
903+
904+
BOOL success = [enumerator pushSHA:fromOID.SHA error:error];
905+
if (!success) return nil;
906+
907+
success = [enumerator hideSHA:relativeOID.SHA error:error];
908+
if (!success) return nil;
909+
910+
return enumerator;
911+
}
912+
915913
@end

0 commit comments

Comments
 (0)