Skip to content

Commit

Permalink
Reimplement the enumeration in GTDiffHunk.
Browse files Browse the repository at this point in the history
  • Loading branch information
boidanny committed Dec 20, 2012
1 parent 02c8507 commit 1767cd8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Classes/GTDiffHunk.h
Expand Up @@ -9,6 +9,7 @@
#import "git2.h" #import "git2.h"


@class GTDiffDelta; @class GTDiffDelta;
@class GTDiffLine;


// A class representing a hunk within a diff delta. // A class representing a hunk within a diff delta.
@interface GTDiffHunk : NSObject @interface GTDiffHunk : NSObject
Expand All @@ -31,6 +32,6 @@
// //
// block - A block to execute on each line. Setting `stop` to `NO` will // block - A block to execute on each line. Setting `stop` to `NO` will
// immediately stop the enumeration and return from the method. // immediately stop the enumeration and return from the method.
- (void)enumerateLinesInHunkUsingBlock:(void (^)(NSString *lineContent, NSUInteger oldLineNumber, NSUInteger newLineNumber, GTDiffHunkLineOrigin lineOrigin, BOOL *stop))block; - (void)enumerateLinesInHunkUsingBlock:(void (^)(GTDiffLine *line, BOOL *stop))block;


@end @end
6 changes: 4 additions & 2 deletions Classes/GTDiffHunk.m
Expand Up @@ -9,6 +9,7 @@
#import "GTDiffHunk.h" #import "GTDiffHunk.h"


#import "GTDiffDelta.h" #import "GTDiffDelta.h"
#import "GTDiffLine.h"


@interface GTDiffHunk () @interface GTDiffHunk ()


Expand Down Expand Up @@ -38,7 +39,7 @@ - (instancetype)initWithDelta:(GTDiffDelta *)delta hunkIndex:(NSUInteger)hunkInd
return self; return self;
} }


- (void)enumerateLinesInHunkUsingBlock:(void (^)(NSString *lineContent, NSUInteger oldLineNumber, NSUInteger newLineNumber, GTDiffHunkLineOrigin lineOrigin, BOOL *stop))block { - (void)enumerateLinesInHunkUsingBlock:(void (^)(GTDiffLine *line, BOOL *stop))block {
NSParameterAssert(block != nil); NSParameterAssert(block != nil);


for (NSUInteger idx = 0; idx < self.lineCount; idx ++) { for (NSUInteger idx = 0; idx < self.lineCount; idx ++) {
Expand All @@ -51,8 +52,9 @@ - (void)enumerateLinesInHunkUsingBlock:(void (^)(NSString *lineContent, NSUInteg
if (result != GIT_OK) continue; if (result != GIT_OK) continue;


NSString *lineString = [[[NSString alloc] initWithBytes:content length:contentLength encoding:NSUTF8StringEncoding] stringByTrimmingCharactersInSet:NSCharacterSet.newlineCharacterSet]; NSString *lineString = [[[NSString alloc] initWithBytes:content length:contentLength encoding:NSUTF8StringEncoding] stringByTrimmingCharactersInSet:NSCharacterSet.newlineCharacterSet];
GTDiffLine *line = [[GTDiffLine alloc] initWithContent:lineString oldLineNumber:(NSUInteger)oldLineNumber newLineNumber:(NSUInteger)newLineNumber origin:lineOrigin];
BOOL stop = NO; BOOL stop = NO;
block(lineString, (NSUInteger)oldLineNumber, (NSUInteger)newLineNumber, lineOrigin, &stop); block(line, &stop);
if (stop) return; if (stop) return;
} }
} }
Expand Down

0 comments on commit 1767cd8

Please sign in to comment.