Skip to content

Commit ddd558b

Browse files
Doug Falesdougfales
Doug Fales
authored andcommitted
Exposing line info from git_diff_hunk in GTDiffHunk.
1 parent 5e24439 commit ddd558b

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

ObjectiveGit/GTDiffHunk.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ NS_ASSUME_NONNULL_BEGIN
2222
/// The number of lines represented in the hunk.
2323
@property (nonatomic, readonly) NSUInteger lineCount;
2424

25+
/// The starting line number in the old file
26+
@property (nonatomic, readonly) NSUInteger oldStart;
27+
28+
/// The number of lines in the old file
29+
@property (nonatomic, readonly) NSUInteger oldLines;
30+
31+
/// The starting line number in the new file
32+
@property (nonatomic, readonly) NSUInteger newStart;
33+
34+
/// The number of lines in the new file
35+
@property (nonatomic, readonly) NSUInteger newLines;
36+
2537
- (instancetype)init NS_UNAVAILABLE;
2638

2739
/// Designated initialiser.

ObjectiveGit/GTDiffHunk.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ - (instancetype)initWithPatch:(GTDiffPatch *)patch hunkIndex:(NSUInteger)hunkInd
4040
int result = git_patch_get_hunk(&_git_hunk, &gitLineCount, patch.git_patch, hunkIndex);
4141
if (result != GIT_OK) return nil;
4242
_lineCount = gitLineCount;
43+
_oldStart = self.git_hunk->old_start;
44+
_oldLines = self.git_hunk->old_lines;
45+
_newStart = self.git_hunk->new_start;
46+
_newLines = self.git_hunk->new_lines;
4347

4448
_patch = patch;
4549
_hunkIndex = hunkIndex;

ObjectiveGitTests/GTDiffSpec.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@
112112
[patch enumerateHunksUsingBlock:^(GTDiffHunk *hunk, BOOL *stop) {
113113
expect(hunk.header).to(equal(@"@@ -4,7 +4,7 @@"));
114114
expect(@(hunk.lineCount)).to(equal(@8));
115+
expect(@(hunk.oldStart)).to(equal(@4));
116+
expect(@(hunk.oldLines)).to(equal(@7));
117+
expect(@(hunk.newStart)).to(equal(@4));
118+
expect(@(hunk.newLines)).to(equal(@7));
115119

116120
NSArray *expectedLines = @[ @"//",
117121
@"// Created by Joe Ricioppo on 9/29/10.",

0 commit comments

Comments
 (0)