8000 Tweaks by tiennou · Pull Request #587 · libgit2/objective-git · GitHub
[go: up one dir, main page]

Skip to content

Tweaks #587

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Nov 26, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use the reference's repository instead of asking for one
  • Loading branch information
tiennou committed Nov 26, 2017
commit d07a74732a108f7d13df8136bd05d7697ec1874a
6 changes: 2 additions & 4 deletions ObjectiveGit/GTBranch.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,16 @@ NS_ASSUME_NONNULL_BEGIN
/// Designated initializer.
///
/// ref - The branch reference to wrap. Must not be nil.
/// repo - The repository containing the branch. Must not be nil.
///
/// Returns the initialized receiver.
- (instancetype _Nullable)initWithReference:(GTReference *)ref repository:(GTRepository *)repo NS_DESIGNATED_INITIALIZER;
- (instancetype _Nullable)initWithReference:(GTReference *)ref NS_DESIGNATED_INITIALIZER;

/// Convenience class initializer.
///
/// ref - The branch reference to wrap. Must not be nil.
/// repo - The repository containing the branch. Must not be nil.
///
/// Returns an initialized instance.
+ (instancetype _Nullable)branchWithReference:(GTReference *)ref repository:(GTRepository *)repo;
+ (instancetype _Nullable)branchWithReference:(GTReference *)ref;

/// Get the target commit for this branch
///
Expand Down
16 changes: 9 additions & 7 deletions ObjectiveGit/GTBranch.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,21 @@ + (NSString *)remoteNamePrefix {
return @"refs/remotes/";
}

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

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

- (instancetype)initWithReference:(GTReference *)ref repository:(GTRepository *)repo {
- (instancetype)initWithReference:(GTReference *)ref {
NSParameterAssert(ref != nil);
NSParameterAssert(repo != nil);

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

_repository = repo;
_reference = ref;

return self;
Expand Down Expand Up @@ -142,6 +140,10 @@ - (NSUInteger)numberOfCommitsWithError:(NSError **)error {
return [enumerator countRemainingObjects:error];
}

- (GTRepository *)repository {
return self.reference.repository;
}

- (GTBranchType)branchType {
if (self.reference.remote) {
return GTBranchTypeRemote;
Expand Down Expand Up @@ -194,7 +196,7 @@ - (GTBranch *)trackingBranchWithError:(NSError **)error success:(BOOL *)success

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

return [[self class] branchWithReference:[[GTReference alloc] initWithGitReference:trackingRef repository:self.repository] repository:self.repository];
return [[self class] branchWithReference:[[GTReference alloc] initWithGitReference:trackingRef repository:self.repository]];
}

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

return [[self.class alloc] initWithReference:reloadedRef repository:self.repository];
return [[self.class alloc] initWithReference:reloadedRef];
}

- (BOOL)calculateAhead:(size_t *)ahead behind:(size_t *)behind relativeTo:(GTBranch *)branch error:(NSError **)error {
Expand Down
12 changes: 6 additions & 6 deletions ObjectiveGit/GTRepository.m
< 8000 td id="diff-1991d46123672c6ab03899a64d02623ada5f81cbee471544f6b997f32ff96b1dR330" data-line-number="330" class="blob-num blob-num-context js-linkable-line-number js-blob-rnum">
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ - (id)lookUpObjectByGitOid:(const git_oid *)oid objectType:(GTObjectType)type er
return nil;
}

return [GTObject objectWithObj:obj inRepository:self];
return [GTObject objectWithObj:obj inRepository:self];
}

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

GTReference *gtRef = [[GTReference alloc] initWithGitReference:ref repository:self];
return [[GTBranch alloc] initWithReference:gtRef repository:self];
return [[GTBranch alloc] initWithReference:gtRef];
}

- (GTReference *)headReferenceWithError:(NSError **)error {
Expand Down Expand Up @@ -409,7 +409,7 @@ - (BOOL)enumerateBranchesWithType:(GTBranchType)type error:(NSError **)error usi
git_branch_t branchType;
while ((gitError = git_branch_next(&gitRef, &branchType, iter)) == GIT_OK) {
GTReference *ref = [[GTReference alloc] initWithGitReference:gitRef repository:self];
GTBranch *branch = [GTBranch branchWithReference:ref repository:self];
GTBranch *branch = [GTBranch branchWithReference:ref];
BOOL stop = NO;
block(branch, &stop);
if (stop) break;
Expand Down Expand Up @@ -457,7 +457,7 @@ - (NSArray *)branchesWithPrefix:(NSString *)prefix error:(NSError **)error {
GTReference *ref = [self lookUpReferenceWithName:refName error:error];
if (ref == nil) continue;

GTBranch *branch = [[GTBranch alloc] initWithReference:ref repository:self];
GTBranch *branch = [[GTBranch alloc] initWithReference:ref];
if (branch == nil) continue;

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

return [GTBranch branchWithReference:newRef repository:self];
return [GTBranch branchWithReference:newRef];
}

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

return [GTBranch branchWithReference:head repository:self];
return [GTBranch branchWithReference:head];
}

- (NSArray *)localCommitsRelativeToRemoteBranch:(GTBranch *)remoteBranch error:(NSError **)error {
Expand Down
4 changes: 2 additions & 2 deletions ObjectiveGitTests/GTBranchSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
expect(otherRef).notTo(beNil());
expect(error).to(beNil());

GTBranch *otherBranch = [GTBranch branchWithReference:otherRef repository:repository];
GTBranch *otherBranch = [GTBranch branchWithReference:otherRef];
expect(otherBranch).notTo(beNil());

BOOL success = NO;
Expand All @@ -179,7 +179,7 @@
expect(remoteRef).notTo(beNil());
expect(error).to(beNil());

GTBranch *remoteBranch = [GTBranch branchWithReference:remoteRef repository:repository];
GTBranch *remoteBranch = [GTBranch branchWithReference:remoteRef];
expect(remoteBranch).notTo(beNil());

BOOL success = NO;
Expand Down
2 changes: 1 addition & 1 deletion ObjectiveGitTests/GTUtilityFunctions.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

CreateCommitBlock createCommitInRepository = ^ GTCommit * (NSString *message, NSData *fileData, NSString *fileName, GTRep 4FDE ository *repo) {
GTReference *head = [repo headReferenceWithError:NULL];
GTBranch *branch = [GTBranch branchWithReference:head repository:repo];
GTBranch *branch = [GTBranch branchWithReference:head];
GTCommit *headCommit = [branch targetCommitWithError:NULL];

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