Permalink
Browse files

added -calculateAhead:behind:relativeTo:error:

  • Loading branch information...
1 parent 63129f9 commit 5c7ac2908069b86a9255b2f59624b9e3beaef0a8 @joshaber joshaber committed Mar 21, 2013
Showing with 27 additions and 0 deletions.
  1. +11 −0 Classes/GTBranch.h
  2. +16 −0 Classes/GTBranch.m
View
@@ -86,4 +86,15 @@ typedef enum {
// found, returns nil and sets `success` to YES.
- (GTBranch *)trackingBranchWithError:(NSError **)error success:(BOOL *)success;
+// Calculate the ahead/behind count from this branch to the given branch.
+//
+// ahead - The number of commits which are unique to the receiver. Cannot be
+// NULL.
+// behind - The number of commits which are unique to `branch`. Cannot be NULL.
+// branch - The branch to which the receiver should be compared.
+// error - The error if one occurs.
+//
+// Returns whether the calculation was successful.
+- (BOOL)calculateAhead:(size_t *)ahead behind:(size_t *)behind relativeTo:(GTBranch *)branch error:(NSError **)error;
+
@end
View
@@ -274,4 +274,20 @@ - (GTBranch *)trackingBranchWithError:(NSError **)error success:(BOOL *)success
return [[self class] branchWithReference:[[GTReference alloc] initWithGitReference:trackingRef repository:self.repository] repository:self.repository];
}
+- (BOOL)calculateAhead:(size_t *)ahead behind:(size_t *)behind relativeTo:(GTBranch *)branch error:(NSError **)error {
+ if (branch == nil) {
+ *ahead = 0;
+ *behind = 0;
+ return YES;
+ }
+
+ int errorCode = git_graph_ahead_behind(ahead, behind, self.repository.git_repository, self.reference.oid, branch.reference.oid);
+ if (errorCode != GIT_OK && error != NULL) {
+ *error = [NSError git_errorFor:errorCode withAdditionalDescription:[NSString stringWithFormat:@"Calculating ahead/behind with %@ to %@", self, branch]];
+ return NO;
+ }
+
+ return YES;
+}
+
@end

0 comments on commit 5c7ac29

Please sign in to comment.