Skip to content

Commit d07a747

Browse files
committed
Use the reference's repository instead of asking for one
1 parent 9ffb9a1 commit d07a747

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed

ObjectiveGit/GTBranch.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,16 @@ NS_ASSUME_NONNULL_BEGIN
5959
/// Designated initializer.
6060
///
6161
/// ref - The branch reference to wrap. Must not be nil.
62-
/// repo - The repository containing the branch. Must not be nil.
6362
///
6463
/// Returns the initialized receiver.
65-
- (instancetype _Nullable)initWithReference:(GTReference *)ref repository:(GTRepository *)repo NS_DESIGNATED_INITIALIZER;
64+
- (instancetype _Nullable)initWithReference:(GTReference *)ref NS_DESIGNATED_INITIALIZER;
6665

6766
/// Convenience class initializer.
6867
///
6968
/// ref - The branch reference to wrap. Must not be nil.
70-
/// repo - The repository containing the branch. Must not be nil.
7169
///
7270
/// Returns an initialized instance.
73-
+ (instancetype _Nullable)branchWithReference:(GTReference *)ref repository:(GTRepository *)repo;
71+
+ (instancetype _Nullable)branchWithReference:(GTReference *)ref;
7472

7573
/// Get the target commit for this branch
7674
///

ObjectiveGit/GTBranch.m

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,23 +65,21 @@ + (NSString *)remoteNamePrefix {
6565
return @"refs/remotes/";
6666
}
6767

68-
+ (instancetype)branchWithReference:(GTReference *)ref repository:(GTRepository *)repo {
69-
return [[self alloc] initWithReference:ref repository:repo];
68+
+ (instancetype)branchWithReference:(GTReference *)ref {
69+
return [[self alloc] initWithReference:ref];
7070
}
7171

7272
- (instancetype)init {
7373
NSAssert(NO, @"Call to an unavailable initializer.");
7474
return nil;
7575
}
7676

77-
- (instancetype)initWithReference:(GTReference *)ref repository:(GTRepository *)repo {
77+
- (instancetype)initWithReference:(GTReference *)ref {
7878
NSParameterAssert(ref != nil);
79-
NSParameterAssert(repo != nil);
8079

8180
self = [super init];
8281
if (self == nil) return nil;
8382

84-
_repository = repo;
8583
_reference = ref;
8684

8785
return self;
@@ -142,6 +140,10 @@ - (NSUInteger)numberOfCommitsWithError:(NSError **)error {
142140
return [enumerator countRemainingObjects:error];
143141
}
144142

143+
- (GTRepository *)repository {
144+
return self.reference.repository;
145+
}
146+
145147
- (GTBranchType)branchType {
146148
if (self.reference.remote) {
147149
return GTBranchTypeRemote;
@@ -194,7 +196,7 @@ - (GTBranch *)trackingBranchWithError:(NSError **)error success:(BOOL *)success
194196

195197
if (success != NULL) *success = YES;
196198

197-
return [[self class] branchWithReference:[[GTReference alloc] initWithGitReference:trackingRef repository:self.repository] repository:self.repository];
199+
return [[self class] branchWithReference:[[GTReference alloc] initWithGitReference:trackingRef repository:self.repository]];
198200
}
199201

200202
- (BOOL)updateTrackingBranch:(GTBranch *)trackingBranch error:(NSError **)error {
@@ -216,7 +218,7 @@ - (GTBranch *)reloadedBranchWithError:(NSError **)error {
216218
GTReference *reloadedRef = [self.reference reloadedReferenceWithError:error];
217219
if (reloadedRef == nil) return nil;
218220

219-
return [[self.class alloc] initWithReference:reloadedRef repository:self.repository];
221+
return [[self.class alloc] initWithReference:reloadedRef];
220222
}
221223

222224
- (BOOL)calculateAhead:(size_t *)ahead behind:(size_t *)behind relativeTo:(GTBranch *)branch error:(NSError **)error {

ObjectiveGit/GTRepository.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ - (id)lookUpObjectByGitOid:(const git_oid *)oid objectType:(GTObjectType)type er
325325
return nil;
326326
}
327327

328-
return [GTObject objectWithObj:obj inRepository:self];
328+
return [GTObject objectWithObj:obj inRepository:self];
329329
}
330330

331331
- (id)lookUpObjectByGitOid:(const git_oid *)oid error:(NSError **)error {
@@ -377,7 +377,7 @@ - (GTBranch *)lookUpBranchWithName:(NSString *)branchName type:(GTBranchType)bra
377377
if (ref == NULL) return nil;
378378

379379
GTReference *gtRef = [[GTReference alloc] initWithGitReference:ref repository:self];
380-
return [[GTBranch alloc] initWithReference:gtRef repository:self];
380+
return [[GTBranch alloc] initWithReference:gtRef];
381381
}
382382

383383
- (GTReference *)headReferenceWithError:(NSError **)error {
@@ -409,7 +409,7 @@ - (BOOL)enumerateBranchesWithType:(GTBranchType)type error:(NSError **)error usi
409409
git_branch_t branchType;
410410
while ((gitError = git_branch_next(&gitRef, &branchType, iter)) == GIT_OK) {
411411
GTReference *ref = [[GTReference alloc] initWithGitReference:gitRef repository:self];
412-
GTBranch *branch = [GTBranch branchWithReference:ref repository:self];
412+
GTBranch *branch = [GTBranch branchWithReference:ref];
413413
BOOL stop = NO;
414414
block(branch, &stop);
415415
if (stop) break;
@@ -457,7 +457,7 @@ - (NSArray *)branchesWithPrefix:(NSString *)prefix error:(NSError **)error {
457457
GTReference *ref = [self lookUpReferenceWithName:refName error:error];
458458
if (ref == nil) continue;
459459

460-
GTBranch *branch = [[GTBranch alloc] initWithReference:ref repository:self];
460+
GTBranch *branch = [[GTBranch alloc] initWithReference:ref];
461461
if (branch == nil) continue;
462462

463463
[branches addObject:branch];
@@ -594,7 +594,7 @@ - (GTBranch *)createBranchNamed:(NSString *)name fromOID:(GTOID *)targetOID mess
594594
GTReference *newRef = [self createReferenceNamed:[GTBranch.localNamePrefix stringByAppendingString:name] fromOID:targetOID message:message error:error];
595595
if (newRef == nil) return nil;
596596

597-
return [GTBranch branchWithReference:newRef repository:self];
597+
return [GTBranch branchWithReference:newRef];
598598
}
599599

600600
- (BOOL)isEmpty {
@@ -605,7 +605,7 @@ - (GTBranch *)currentBranchWithError:(NSError **)error {
605605
GTReference *head = [self headReferenceWithError:error];
606606
if (head == nil) return nil;
607607

608-
return [GTBranch branchWithReference:head repository:self];
608+
return [GTBranch branchWithReference:head];
609609
}
610610

611611
- (NSArray *)localCommitsRelativeToRemoteBranch:(GTBranch *)remoteBranch error:(NSError **)error {

ObjectiveGitTests/GTBranchSpec.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@
163163
expect(otherRef).notTo(beNil());
164164
expect(error).to(beNil());
165165

166-
GTBranch *otherBranch = [GTBranch branchWithReference:otherRef repository:repository];
166+
GTBranch *otherBranch = [GTBranch branchWithReference:otherRef];
167167
expect(otherBranch).notTo(beNil());
168168

169169
BOOL success = NO;
@@ -179,7 +179,7 @@
179179
expect(remoteRef).notTo(beNil());
180180
expect(error).to(beNil());
181181

182-
GTBranch *remoteBranch = [GTBranch branchWithReference:remoteRef repository:repository];
182+
GTBranch *remoteBranch = [GTBranch branchWithReference:remoteRef];
183183
expect(remoteBranch).notTo(beNil());
184184

185185
BOOL success = NO;

ObjectiveGitTests/GTUtilityFunctions.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
CreateCommitBlock createCommitInRepository = ^ GTCommit * (NSString *message, NSData *fileData, NSString *fileName, GTRepository *repo) {
1818
GTReference *head = [repo headReferenceWithError:NULL];
19-
GTBranch *branch = [GTBranch branchWithReference:head repository:repo];
19+
GTBranch *branch = [GTBranch branchWithReference:head];
2020
GTCommit *headCommit = [branch targetCommitWithError:NULL];
2121

2222
GTTreeBuilder *treeBuilder = [[GTTreeBuilder alloc] initWithTree:headCommit.tree repository:repo error:nil];

0 commit comments

Comments
 (0)