Skip to content

Commit c3188a4

Browse files
committed
Merge pull request #460 from sagmor/api_consistency
API consistency sugestions
2 parents 757e19c + bfe8367 commit c3188a4

File tree

6 files changed

+55
-33
lines changed

6 files changed

+55
-33
lines changed

ObjectiveGit/GTBranch.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ NS_ASSUME_NONNULL_BEGIN
7575
/// error(out) - will be filled if an error occurs
7676
///
7777
/// returns a GTCommit object or nil if an error occurred
78-
- (nullable GTCommit *)targetCommitAndReturnError:(NSError **)error;
78+
- (nullable GTCommit *)targetCommitWithError:(NSError **)error;
7979

8080
/// Count all commits in this branch
8181
///
@@ -130,6 +130,9 @@ NS_ASSUME_NONNULL_BEGIN
130130
/// Returns whether the calculation was successful.
131131
- (BOOL)calculateAhead:(size_t *)ahead behind:(size_t *)behind relativeTo:(GTBranch *)branch error:(NSError **)error;
132132

133+
#pragma mark Deprecations
134+
- (nullable GTCommit *)targetCommitAndReturnError:(NSError **)error __deprecated_msg("use targetCommitWithError: instead.");
135+
133136
@end
134137

135138
NS_ASSUME_NONNULL_END

ObjectiveGit/GTBranch.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ - (NSString *)remoteName {
120120
return [[NSString alloc] initWithBytes:name length:end - name encoding:NSUTF8StringEncoding];
121121
}
122122

123-
- (GTCommit *)targetCommitAndReturnError:(NSError **)error {
123+
- (GTCommit *)targetCommitWithError:(NSError **)error {
124124
if (self.OID == nil) {
125125
if (error != NULL) *error = GTReference.invalidReferenceError;
126126
return nil;
@@ -218,4 +218,9 @@ - (BOOL)calculateAhead:(size_t *)ahead behind:(size_t *)behind relativeTo:(GTBra
218218
return [self.repository calculateAhead:ahead behind:behind ofOID:self.OID relativeToOID:branch.OID error:error];
219219
}
220220

221+
#pragma mark Deprecations
222+
- (GTCommit *)targetCommitAndReturnError:(NSError **)error {
223+
return [self targetCommitWithError:error];
224+
}
225+
221226
@end

ObjectiveGit/GTIndex.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,16 @@ NS_ASSUME_NONNULL_BEGIN
105105
/// Returns a new GTIndexEntry, or nil if an error occurred.
106106
- (nullable GTIndexEntry *)entryAtIndex:(NSUInteger)index;
107107

108-
/// Get the entry with the given name.
109-
- (GTIndexEntry *)entryWithName:(NSString *)name;
108+
/// Get the entry with the given path.
109+
- (GTIndexEntry *)entryWithPath:(NSString *)path;
110110

111111
/// Get the entry with the given name.
112112
///
113-
/// name - The name of the entry to get. Cannot be nil.
113+
/// path - The path of the entry to get. Cannot be nil.
114114
/// error - The error if one occurred.
115115
///
116116
/// Returns a new GTIndexEntry, or nil if an error occurred.
117-
- (nullable GTIndexEntry *)entryWithName:(NSString *)name error:(NSError **)error;
117+
- (nullable GTIndexEntry *)entryWithPath:(NSString *)path error:(NSError **)error;
118118

119119
/// Add an entry to the index.
120120
///
@@ -141,9 +141,9 @@ NS_ASSUME_NONNULL_BEGIN
141141
/// Will fail if the receiver's repository is nil.
142142
///
143143
/// data - The content of the entry to add. Cannot be nil.
144-
/// name - The name of the entry to add. Cannot be nil.
144+
/// path - The path of the entry to add. Cannot be nil.
145145
/// error - The error if one occurred.
146-
- (BOOL)addData:(NSData *)data withName:(NSString *)name error:(NSError **)error;
146+
- (BOOL)addData:(NSData *)data withPath:(NSString *)path error:(NSError **)error;
147147

148148
/// Reads the contents of the given tree into the index.
149149
///
@@ -220,6 +220,11 @@ NS_ASSUME_NONNULL_BEGIN
220220
/// Returns `YES` in the event that everything has gone smoothly. Otherwise, `NO`.
221221
- (BOOL)updatePathspecs:(nullable NSArray *)pathspecs error:(NSError **)error passingTest:(nullable BOOL (^)(NSString *matchedPathspec, NSString *path, BOOL *stop))block;
222222

223+
#pragma mark Deprecations
224+
- (nullable GTIndexEntry *)entryWithName:(NSString *)name __deprecated_msg("use entryWithPath: instead.");
225+
- (nullable GTIndexEntry *)entryWithName:(NSString *)name error:(NSError **)error __deprecated_msg("use entryWithPath:error: instead.");
226+
227+
223228
@end
224229

225230
NS_ASSUME_NONNULL_END

ObjectiveGit/GTIndex.m

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,15 @@ - (GTIndexEntry *)entryAtIndex:(NSUInteger)index {
146146
return [[GTIndexEntry alloc] initWithGitIndexEntry:entry index:self error:NULL];
147147
}
148148

149-
- (GTIndexEntry *)entryWithName:(NSString *)name {
150-
return [self entryWithName:name error:NULL];
149+
- (GTIndexEntry *)entryWithPath:(NSString *)path {
150+
return [self entryWithPath:path error:NULL];
151151
}
152152

153-
- (GTIndexEntry *)entryWithName:(NSString *)name error:(NSError **)error {
153+
- (GTIndexEntry *)entryWithPath:(NSString *)path error:(NSError **)error {
154154
size_t pos = 0;
155-
int gitError = git_index_find(&pos, self.git_index, name.UTF8String);
155+
int gitError = git_index_find(&pos, self.git_index, path.UTF8String);
156156
if (gitError != GIT_OK) {
157-
if (error != NULL) *error = [NSError git_errorFor:gitError description:@"%@ not found in index", name];
157+
if (error != NULL) *error = [NSError git_errorFor:gitError description:@"%@ not found in index", path];
158158
return NULL;
159159
}
160160
return [self entryAtIndex:pos];
@@ -182,19 +182,19 @@ - (BOOL)addFile:(NSString *)file error:(NSError **)error {
182182
return YES;
183183
}
184184

185-
- (BOOL)addData:(NSData *)data withName:(NSString *)name error:(NSError **)error {
185+
- (BOOL)addData:(NSData *)data withPath:(NSString *)path error:(NSError **)error {
186186
NSParameterAssert(data != nil);
187-
NSParameterAssert(name != nil);
187+
NSParameterAssert(path != nil);
188188

189189
git_index_entry entry;
190190
memset(&entry, 0x0, sizeof(git_index_entry));
191-
entry.path = [name cStringUsingEncoding:NSUTF8StringEncoding];
191+
entry.path = [path cStringUsingEncoding:NSUTF8StringEncoding];
192192
entry.mode = GIT_FILEMODE_BLOB;
193193

194194
int status = git_index_add_frombuffer(self.git_index, &entry, [data bytes], [data length]);
195195

196196
if (status != GIT_OK) {
197-
if (error != NULL) *error = [NSError git_errorFor:status description:@"Failed to add data with name %@ into index.", name];
197+
if (error != NULL) *error = [NSError git_errorFor:status description:@"Failed to add data with name %@ into index.", path];
198198
return NO;
199199
}
200200

@@ -380,4 +380,13 @@ - (NSString *)composedUnicodeStringWithString:(NSString *)string {
380380
return (shouldPrecompose ? [string precomposedStringWithCanonicalMapping] : [string decomposedStringWithCanonicalMapping]);
381381
}
382382

383+
#pragma mark Deprecations
384+
385+
- (GTIndexEntry *)entryWithName:(NSString *)name {
386+
return [self entryWithPath:name];
387+
}
388+
389+
- (GTIndexEntry *)entryWithName:(NSString *)name error:(NSError **)error {
390+
return [self entryWithPath:name error:error];
391+
}
383392
@end

ObjectiveGitTests/GTBranchSpec.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,13 @@
121121
it(@"should reload the branch from disk", ^{
122122
static NSString * const originalSHA = @"a4bca6b67a5483169963572ee3da563da33712f7";
123123
static NSString * const updatedSHA = @"6b0c1c8b8816416089c534e474f4c692a76ac14f";
124-
expect([masterBranch targetCommitAndReturnError:NULL].SHA).to(equal(originalSHA));
124+
expect([masterBranch targetCommitWithError:NULL].SHA).to(equal(originalSHA));
125125
[masterBranch.reference referenceByUpdatingTarget:updatedSHA message:nil error:NULL];
126126

127127
GTBranch *reloadedBranch = [masterBranch reloadedBranchWithError:NULL];
128128
expect(reloadedBranch).notTo(beNil());
129-
expect([reloadedBranch targetCommitAndReturnError:NULL].SHA).to(equal(updatedSHA));
130-
expect([masterBranch targetCommitAndReturnError:NULL].SHA).to(equal(originalSHA));
129+
expect([reloadedBranch targetCommitWithError:NULL].SHA).to(equal(updatedSHA));
130+
expect([masterBranch targetCommitWithError:NULL].SHA).to(equal(originalSHA));
131131
});
132132
});
133133

ObjectiveGitTests/GTIndexSpec.m

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@
5353
it(@"should write to a specific repository and return a tree", ^{
5454
GTRepository *repository = self.bareFixtureRepository;
5555
NSArray *branches = [repository branches:NULL];
56-
GTCommit *masterCommit = [branches[0] targetCommitAndReturnError:NULL];
57-
GTCommit *packedCommit = [branches[1] targetCommitAndReturnError:NULL];
56+
GTCommit *masterCommit = [branches[0] targetCommitWithError:NULL];
57+
GTCommit *packedCommit = [branches[1] targetCommitWithError:NULL];
5858

5959
expect(masterCommit).notTo(beNil());
6060
expect(packedCommit).notTo(beNil());
@@ -92,7 +92,7 @@
9292
if (treeEntry.type == GTObjectTypeBlob) {
9393
NSString *path = [root stringByAppendingString:treeEntry.name];
9494

95-
GTIndexEntry *indexEntry = [memoryIndex entryWithName:path];
95+
GTIndexEntry *indexEntry = [memoryIndex entryWithPath:path];
9696
expect(indexEntry).notTo(beNil());
9797
}
9898

@@ -229,48 +229,48 @@
229229

230230
it(@"it preserves decomposed Unicode in index paths with precomposeunicode disabled", ^{
231231
NSString *decomposedFilename = [filename decomposedStringWithCanonicalMapping];
232-
GTIndexEntry *entry = [index entryWithName:decomposedFilename error:NULL];
232+
GTIndexEntry *entry = [index entryWithPath:decomposedFilename error:NULL];
233233
expect(@(fileStatusEqualsExpected(entry.path, GTStatusDeltaStatusUnmodified, GTStatusDeltaStatusUnmodified))).to(beTruthy());
234234

235235
expect(@([[NSFileManager defaultManager] moveItemAtURL:fileURL toURL:renamedFileURL error:NULL])).to(beTruthy());
236236

237-
entry = [index entryWithName:decomposedFilename error:NULL];
237+
entry = [index entryWithPath:decomposedFilename error:NULL];
238238
expect(@(fileStatusEqualsExpected(entry.path, GTStatusDeltaStatusUnmodified, GTStatusDeltaStatusDeleted))).to(beTruthy());
239239

240240
[index removeFile:filename error:NULL];
241241
[index addFile:renamedFilename error:NULL];
242242
[index write:NULL];
243243

244-
entry = [index entryWithName:[renamedFilename decomposedStringWithCanonicalMapping] error:NULL];
244+
entry = [index entryWithPath:[renamedFilename decomposedStringWithCanonicalMapping] error:NULL];
245245
expect(@(fileStatusEqualsExpected(entry.path, GTStatusDeltaStatusRenamed, GTStatusDeltaStatusUnmodified))).to(beTruthy());
246246
});
247247

248248
it(@"it preserves precomposed Unicode in index paths with precomposeunicode enabled", ^{
249-
GTIndexEntry *fileEntry = [index entryWithName:[filename decomposedStringWithCanonicalMapping] error:NULL];
249+
GTIndexEntry *fileEntry = [index entryWithPath:[filename decomposedStringWithCanonicalMapping] error:NULL];
250250
expect(fileEntry).notTo(beNil());
251251
expect(@(fileStatusEqualsExpected(fileEntry.path, GTStatusDeltaStatusUnmodified, GTStatusDeltaStatusUnmodified))).to(beTruthy());
252252

253253
[configuration setBool:true forKey:@"core.precomposeunicode"];
254254
expect(@([configuration boolForKey:@"core.precomposeunicode"])).to(beTruthy());
255255

256-
GTIndexEntry *decomposedFileEntry = [index entryWithName:[filename decomposedStringWithCanonicalMapping] error:NULL];
256+
GTIndexEntry *decomposedFileEntry = [index entryWithPath:[filename decomposedStringWithCanonicalMapping] error:NULL];
257257
expect(decomposedFileEntry).notTo(beNil());
258258
expect(@(fileStatusEqualsExpected(decomposedFileEntry.path, GTStatusDeltaStatusUnmodified, GTStatusDeltaStatusDeleted))).to(beTruthy());
259259

260260
expect(@([[NSFileManager defaultManager] moveItemAtURL:fileURL toURL:renamedFileURL error:NULL])).to(beTruthy());
261261

262-
GTIndexEntry *precomposedFileEntry = [index entryWithName:filename error:NULL];
262+
GTIndexEntry *precomposedFileEntry = [index entryWithPath:filename error:NULL];
263263
expect(precomposedFileEntry).to(beNil());
264264

265-
decomposedFileEntry = [index entryWithName:[filename decomposedStringWithCanonicalMapping] error:NULL];
265+
decomposedFileEntry = [index entryWithPath:[filename decomposedStringWithCanonicalMapping] error:NULL];
266266
expect(decomposedFileEntry).notTo(beNil());
267267
expect(@(fileStatusEqualsExpected(decomposedFileEntry.path, GTStatusDeltaStatusUnmodified, GTStatusDeltaStatusDeleted))).to(beTruthy());
268268

269269
[index removeFile:filename error:NULL];
270270
[index addFile:renamedFilename error:NULL];
271271
[index write:NULL];
272272

273-
GTIndexEntry *precomposedRenamedFileEntry = [index entryWithName:renamedFilename error:NULL];
273+
GTIndexEntry *precomposedRenamedFileEntry = [index entryWithPath:renamedFilename error:NULL];
274274
expect(precomposedRenamedFileEntry).notTo(beNil());
275275
expect(@(fileStatusEqualsExpected(precomposedFileEntry.path, GTStatusDeltaStatusRenamed, GTStatusDeltaStatusUntracked))).to(beTruthy());
276276
});
@@ -292,10 +292,10 @@
292292

293293
it(@"should store data at given path", ^{
294294
NSData *data = [NSData dataWithBytes:"foo" length:4];
295-
[index addData:data withName:@"bar/foo" error:&error];
295+
[index addData:data withPath:@"bar/foo" error:&error];
296296
expect(error).to(beNil());
297297

298-
GTIndexEntry *entry = [index entryWithName:@"bar/foo" error:&error];
298+
GTIndexEntry *entry = [index entryWithPath:@"bar/foo" error:&error];
299299
expect(entry).notTo(beNil());
300300
expect(error).to(beNil());
301301
});

0 commit comments

Comments
 (0)