-
Notifications
You must be signed in to change notification settings - Fork 282
Diff #103
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
Diff #103
Changes from all commits
5012bd2
abbeada
543ded7
bf67679
e9cb72f
0f69f51
b9e1dce
c7488b5
595c0eb
6924548
04a250f
a7080d5
aa40c44
a2701e9
fe41bc2
b4f0c1d
7147838
f8bfb12
542d8eb
f6e2d94
fe68272
f8c8e7d
f284d8b
86484d5
583faca
7faa681
1782579
18af33f
90b04c1
eccc58c
5c743f5
e35e59b
75cad03
27d91e8
be3b54d
8ed3942
d849daf
c4fffb4
aff2911
1d13af1
970f80b
90d73a2
83a114d
b863826
e27e129
d4d2750
d20ea18
94d6ccf
79a361f
5833ebd
60e49e9
3cfd2e8
a9be483
b2c681a
4b3f1d2
4af300b
c55ac1d
4bd0faf
f4dc110
fe888e3
11a2650
64662f5
3588a67
e31a8b4
e1fd8f9
8ee8f8a
08c439f
003836c
260cb4a
ff9a35e
09fa475
d97733e
6c975af
5943df0
07c6b5b
7cb03c2
6c9cd12
6dffb7f
8bb9a38
088ee0a
7244eb0
cf82c0f
27ac67c
b80d355
4216ce9
8f2a753
587c2d7
cea22d0
9377752
b89e3b1
838b971
48cc651
b7702d9
e7bd6f1
6759e89
3ee7044
2ed1806
fb7f585
c689349
687d28b
31c91e0
07b38f7
a77854c
e8d25b4
32e1d0c
5f00a30
3811b2c
85f6dcf
0e96d8a
2d22b60
3ef8978
934a826
7f68b0f
f4a3e56
0b49035
7500fef
6ce9109
53336ec
90728c0
57bd3bb
e46310c
9aa5127
f2ed1d9
1fd5d68
38d07a1
50a9212
35d9f64
9991f92
e9ac8ed
f778aa9
34aa843
e26d732
7ff2294
ee39f62
9f691b2
346592a
c94eab9
52b3c98
13bcd6f
d360980
d853045
65729cc
1dc6e87
f3e3ee7
599b88d
2a8ebde
d2988e7
8b440f5
ff80bfa
cea4994
aeb2776
4ce57b0
011ce40
c2ff71d
478e177
ef154c3
2bd17ee
068560b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,221 @@ | ||
| // | ||
| // GTDiff.h | ||
| // ObjectiveGitFramework | ||
| // | ||
| // Created by Danny Greg on 29/11/2012. | ||
| // Copyright (c) 2012 GitHub, Inc. All rights reserved. | ||
| // | ||
|
|
||
| #import "git2.h" | ||
|
|
||
| #import "GTDiffDelta.h" | ||
|
|
||
| @class GTDiffDelta; | ||
| @class GTRepository; | ||
| @class GTTree; | ||
|
|
||
| // An `NSNumber` wrapped `GTDiffOptionsFlags` representing any flags you wish to | ||
| // pass into the initialisation. | ||
| extern NSString *const GTDiffOptionsFlagsKey; | ||
|
|
||
| // An `NSNumber` wrapped `NSUInteger` dictating the number of unchanged lines | ||
| // that define the boundary of a hunk (and to display around it). | ||
| // | ||
| // Defaults to 3. | ||
| extern NSString *const GTDiffOptionsContextLinesKey; | ||
|
|
||
| // An `NSNumber` wrapped `NSUInteger` dictating the maximum number of unchanged | ||
| // lines between hunk boundaries before the hunks will be merged. | ||
| // | ||
| // Defaults to 0. | ||
| extern NSString *const GTDiffOptionsInterHunkLinesKey; | ||
|
|
||
| // An `NSString` to prefix old file names with. | ||
| // | ||
| // Defaults to "a". | ||
| extern NSString *const GTDiffOptionsOldPrefixKey; | ||
|
|
||
| // An `NSString` to prefix new file names with. | ||
| // | ||
| // Defaults to "b". | ||
| extern NSString *const GTDiffOptionsNewPrefixKey; | ||
|
|
||
| // An `NSNumber` wrapped `NSUInteger` determining the maximum size (in bytes) | ||
| // of a file to diff. Above this size the file will be treated as binary. | ||
| // | ||
| // Defaults to 512MB. | ||
| extern NSString *const GTDiffOptionsMaxSizeKey; | ||
|
|
||
| // Enum for use as documented in the options dictionary with the | ||
| // `GTDiffOptionsFlagsKey` key. | ||
| // | ||
| // See diff.h for documentation of each individual flag. | ||
| typedef enum : git_diff_option_t { | ||
| GTDiffOptionsFlagsNormal = GIT_DIFF_NORMAL, | ||
| GTDiffOptionsFlagsReverse = GIT_DIFF_REVERSE, | ||
| GTDiffOptionsFlagsForceText = GIT_DIFF_FORCE_TEXT, | ||
| GTDiffOptionsFlagsIgnoreWhitespace = GIT_DIFF_IGNORE_WHITESPACE, | ||
| GTDiffOptionsFlagsIgnoreWhitespaceChange = GIT_DIFF_IGNORE_WHITESPACE_CHANGE, | ||
| GTDiffOptionsFlagsIgnoreWhitespaceEOL = GIT_DIFF_IGNORE_WHITESPACE_EOL, | ||
| GTDiffOptionsFlagsIgnoreSubmodules = GIT_DIFF_IGNORE_SUBMODULES, | ||
| GTDiffOptionsFlagsPatience = GIT_DIFF_PATIENCE, | ||
| GTDiffOptionsFlagsIncludeIgnored = GIT_DIFF_INCLUDE_IGNORED, | ||
| GTDiffOptionsFlagsIncludeUntracked = GIT_DIFF_INCLUDE_UNTRACKED, | ||
| GTDiffOptionsFlagsIncludeUnmodified = GIT_DIFF_INCLUDE_UNMODIFIED, | ||
| GTDiffOptionsFlagsRecurseUntrackedDirs = GIT_DIFF_RECURSE_UNTRACKED_DIRS, | ||
| GTDiffOptionsFlagsDisablePathspecMatch = GIT_DIFF_DISABLE_PATHSPEC_MATCH, | ||
| GTDiffOptionsFlagsDeltasAreICase = GIT_DIFF_DELTAS_ARE_ICASE, | ||
| GTDiffOptionsFlagsIncludeUntrackedContent = GIT_DIFF_INCLUDE_UNTRACKED_CONTENT, | ||
| GTDiffOptionsFlagsSkipBinaryCheck = GIT_DIFF_SKIP_BINARY_CHECK, | ||
| GTDiffOptionsFlagsIncludeTypeChange = GIT_DIFF_INCLUDE_TYPECHANGE, | ||
| GTDiffOptionsFlagsIncludeTypeChangeTrees = GIT_DIFF_INCLUDE_TYPECHANGE_TREES, | ||
| GTDiffOptionsFlagsIgnoreFileMode = GIT_DIFF_IGNORE_FILEMODE, | ||
| } GTDiffOptionsFlags; | ||
|
|
||
| // An `NSNumber` wrapped `GTDiffOptionsFlags` bitmask containing any of the | ||
| // flags documented below. | ||
| // | ||
| // Defualts to `GTDiffFindOptionsFlagsFindRenames`. | ||
| extern NSString *const GTDiffFindOptionsFlagsKey; | ||
|
|
||
| // An `NSNumber` wrapped `NSUInteger` dictating the similarity between files | ||
| // to be considered a rename. | ||
| // | ||
| // This is a value as per the git similarity index and should be between 1 and | ||
| // 100 (0 and above 100 use the default). | ||
| // | ||
| // Defaults to 50. | ||
| extern NSString *const GTDiffFindOptionsRenameThresholdKey; | ||
|
|
||
| // An `NSNumber` wrapped `NSUInteger` dictating how similar a modified file can | ||
| // be to be eligable as a rename. | ||
| // | ||
| // This is a value as per the git similarity index and should be between 1 and | ||
| // 100 (0 and above 100 use the default). | ||
| // | ||
| // Defaults to 50. | ||
| extern NSString *const GTDiffFindOptionsRenameFromRewriteThresholdKey; | ||
|
|
||
| // An `NSNumber` wrapped `NSUInteger` dictating how similar a modified file can | ||
| // be to be considered a copy. | ||
| // | ||
| // This is a value as per the git similarity index and should be between 1 and | ||
| // 100 (0 and above 100 use the default). | ||
| // | ||
| // Defaults to 50. | ||
| extern NSString *const GTDiffFindOptionsCopyThresholdKey; | ||
|
|
||
| // An `NSNumber` wrapped `NSUInteger` dictating how similar a modified file can | ||
| // be to be to be broken into a separate deletion and addition pair. | ||
| // | ||
| // This is a value as per the git similarity index and should be between 1 and | ||
| // 100 (0 and above 100 use the default). | ||
| // | ||
| // Defaults to 60. | ||
| extern NSString *const GTDiffFindOptionsBreakRewriteThresholdKey; | ||
|
|
||
| // An `NSNumber` wrapped `NSUInteger` dictating the maximum amount of similarity | ||
| // sources to examine. | ||
| // | ||
| // This is the equivalent of the `diff.renameLimit` config value. | ||
| // | ||
| // Defaults to 200. | ||
| extern NSString *const GTDiffFindOptionsTargetLimitKey; | ||
|
|
||
| // Enum for options passed into `-findSimilarWithOptions:`. | ||
| // | ||
| // For individual case documentation see `diff.h`. | ||
| typedef enum : git_diff_find_t { | ||
| GTDiffFindOptionsFlagsFindRenames = GIT_DIFF_FIND_RENAMES, | ||
| GTDiffFindOptionsFlagsFindRenamesFromRewrites = GIT_DIFF_FIND_RENAMES_FROM_REWRITES, | ||
| GTDiffFindOptionsFlagsFindCopies = GIT_DIFF_FIND_COPIES, | ||
| GTDiffFindOptionsFlagsFindCopiesFromUnmodified = GIT_DIFF_FIND_COPIES_FROM_UNMODIFIED, | ||
| GTDiffFindOptionsFlagsFindAndBreakRewrites = GIT_DIFF_FIND_AND_BREAK_REWRITES, | ||
| } GTDiffFindOptionsFlags; | ||
|
|
||
| // A class representing a single "diff". | ||
| // | ||
| // Analagous to `git_diff_list` in libgit2, this object represents a list of | ||
| // changes or "deltas", which are represented by `GTDiffDelta` objects. | ||
| @interface GTDiff : NSObject | ||
|
|
||
| // The libgit2 diff list object. | ||
| @property (nonatomic, readonly) git_diff_list *git_diff_list; | ||
|
|
||
| // The number of deltas represented by the diff object. | ||
| @property (nonatomic, readonly) NSUInteger deltaCount; | ||
|
|
||
| // Create a diff between 2 `GTTree`s. | ||
| // | ||
| // The 2 trees must be from the same repository, or an exception will be thrown. | ||
| // | ||
| // oldTree - The "left" side of the diff. | ||
| // newTree - The "right" side of the diff. | ||
| // options - A dictionary containing any of the above options key constants, or | ||
| // nil to use the defaults. | ||
| // | ||
| // Returns a newly created `GTDiff` object or nil on error. | ||
| + (GTDiff *)diffOldTree:(GTTree *)oldTree withNewTree:(GTTree *)newTree options:(NSDictionary *)options; | ||
|
|
||
| // Create a diff between a repository's current index. | ||
| // | ||
| // This is equivalent to `git diff --cached <treeish>` or if you pass the HEAD | ||
| // tree, then `git diff --cached`. | ||
| // | ||
| // The tree you pass will be used for the "left" side of the diff, and the | ||
| // index will be used for the "right" side of the diff. | ||
| // | ||
| // tree - The tree to be diffed. The index will be taken from this tree's | ||
| // repository. The left side of the diff. | ||
| // options - A dictionary containing any of the above options key constants, or | ||
| // nil to use the defaults. | ||
| // | ||
| // Returns a newly created `GTDiff` object or nil on error. | ||
| + (GTDiff *)diffIndexFromTree:(GTTree *)tree options:(NSDictionary *)options; | ||
|
|
||
| // Create a diff between the index and working directory in a given repository. | ||
| // | ||
| // This matches the `git diff` command. | ||
| // | ||
| // repository - The repository to be used for the diff. | ||
| // options - A dictionary containing any of the above options key constants, | ||
| // or nil to use the defaults. | ||
| // | ||
| // Returns a newly created `GTDiff` object or nil on error. | ||
| + (GTDiff *)diffIndexToWorkingDirectoryInRepository:(GTRepository *)repository options:(NSDictionary *)options; | ||
|
|
||
| // Create a diff between a repository's working directory and a tree. | ||
| // | ||
| // tree - The tree to be diffed. The tree will be the left side of the diff. | ||
| // options - A dictionary containing any of the above options key constants, or | ||
| // nil to use the defaults. | ||
| // | ||
| // Returns a newly created `GTDiff` object or nil on error. | ||
| + (GTDiff *)diffWorkingDirectoryFromTree:(GTTree *)tree options:(NSDictionary *)options; | ||
|
|
||
| // Designated initialiser. | ||
| - (instancetype)initWithGitDiffList:(git_diff_list *)diffList; | ||
|
|
||
| // The number of deltas of the given type that are contained in the diff. | ||
| - (NSUInteger)numberOfDeltasWithType:(GTDiffDeltaType)deltaType; | ||
|
|
||
| // Enumerate the deltas in a diff. | ||
| // | ||
| // It is worth noting that the `git_diff_patch` objects backing each delta | ||
| // contain the entire contents in memory. It is therefore recommended you | ||
| // do not store the `delta` object given here, but instead perform any work | ||
| // necessary within the provided block. | ||
| // | ||
| // Also note that this method blocks during the enumeration. | ||
| // | ||
| // block - A block to be executed for each delta. Setting `stop` to `YES` | ||
| // immediately stops the enumeration. | ||
| - (void)enumerateDeltasUsingBlock:(void (^)(GTDiffDelta *delta, BOOL *stop))block; | ||
|
|
||
| // Modify the diff list to combine similar changes using the given options. | ||
| // | ||
| // options - A dictionary containing any of the above find options key constants | ||
| // or nil to use the defaults. | ||
| - (void)findSimilarWithOptions:(NSDictionary *)options; | ||
|
|
||
| @end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,177 @@ | ||
| // | ||
| // GTDiff.m | ||
| // ObjectiveGitFramework | ||
| // | ||
| // Created by Danny Greg on 29/11/2012. | ||
| // Copyright (c) 2012 GitHub, Inc. All rights reserved. | ||
| // | ||
|
|
||
| #import "GTDiff.h" | ||
|
|
||
| #import "GTDiffDelta.h" | ||
| #import "GTRepository.h" | ||
| #import "GTTree.h" | ||
|
|
||
| NSString *const GTDiffOptionsFlagsKey = @"GTDiffOptionsFlagsKey"; | ||
| NSString *const GTDiffOptionsContextLinesKey = @"GTDiffOptionsContextLinesKey"; | ||
| NSString *const GTDiffOptionsInterHunkLinesKey = @"GTDiffOptionsInterHunkLinesKey"; | ||
| NSString *const GTDiffOptionsOldPrefixKey = @"GTDiffOptionsOldPrefixKey"; | ||
| NSString *const GTDiffOptionsNewPrefixKey = @"GTDiffOptionsNewPrefixKey"; | ||
| NSString *const GTDiffOptionsMaxSizeKey = @"GTDiffOptionsMaxSizeKey"; | ||
|
|
||
| NSString *const GTDiffFindOptionsFlagsKey = @"GTDiffFindOptionsFlagsKey"; | ||
| NSString *const GTDiffFindOptionsRenameThresholdKey = @"GTDiffFindOptionsRenameThresholdKey"; | ||
| NSString *const GTDiffFindOptionsRenameFromRewriteThresholdKey = @"GTDiffFindOptionsRenameFromRewriteThresholdKey"; | ||
| NSString *const GTDiffFindOptionsCopyThresholdKey = @"GTDiffFindOptionsCopyThresholdKey"; | ||
| NSString *const GTDiffFindOptionsBreakRewriteThresholdKey = @"GTDiffFindOptionsBreakRewriteThresholdKey"; | ||
| NSString *const GTDiffFindOptionsTargetLimitKey = @"GTDiffFindOptionsTargetLimitKey"; | ||
|
|
||
| @implementation GTDiff | ||
|
|
||
| + (BOOL)optionsStructFromDictionary:(NSDictionary *)dictionary optionsStruct:(git_diff_options *)newOptions { | ||
| if (dictionary == nil || dictionary.count < 1) return NO; | ||
|
|
||
| NSNumber *flagsNumber = dictionary[GTDiffOptionsFlagsKey]; | ||
| if (flagsNumber != nil) newOptions->flags = (uint32_t)flagsNumber.unsignedIntegerValue; | ||
|
|
||
| NSNumber *contextLinesNumber = dictionary[GTDiffOptionsContextLinesKey]; | ||
| if (contextLinesNumber != nil) newOptions->context_lines = (uint16_t)contextLinesNumber.unsignedIntegerValue; | ||
|
|
||
| NSNumber *interHunkLinesNumber = dictionary[GTDiffOptionsInterHunkLinesKey]; | ||
| if (interHunkLinesNumber != nil) newOptions->interhunk_lines = (uint16_t)interHunkLinesNumber.unsignedIntegerValue; | ||
|
|
||
| // We cast to char* below to work around a current bug in libgit2, which is | ||
| // fixed in https://github.com/libgit2/libgit2/pull/1118 | ||
|
|
||
| NSString *oldPrefix = dictionary[GTDiffOptionsOldPrefixKey]; | ||
| if (oldPrefix != nil) newOptions->old_prefix = (char *)oldPrefix.UTF8String; | ||
|
|
||
| NSString *newPrefix = dictionary[GTDiffOptionsNewPrefixKey]; | ||
| if (newPrefix != nil) newOptions->new_prefix = (char *)newPrefix.UTF8String; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| NSNumber *maxSizeNumber = dictionary[GTDiffOptionsMaxSizeKey]; | ||
| if (maxSizeNumber != nil) newOptions->max_size = (uint16_t)maxSizeNumber.unsignedIntegerValue; | ||
|
|
||
| return YES; | ||
| } | ||
|
|
||
| + (GTDiff *)diffOldTree:(GTTree *)oldTree withNewTree:(GTTree *)newTree options:(NSDictionary *)options { | ||
| NSParameterAssert([oldTree.repository isEqualTo:newTree.repository]); | ||
|
|
||
| git_diff_options optionsStruct = GIT_DIFF_OPTIONS_INIT; | ||
| BOOL optionsStructCreated = [self optionsStructFromDictionary:options optionsStruct:&optionsStruct]; | ||
| git_diff_list *diffList; | ||
| int returnValue = git_diff_tree_to_tree(&diffList, oldTree.repository.git_repository, oldTree.git_tree, newTree.git_tree, (optionsStructCreated ? &optionsStruct : NULL)); | ||
| if (returnValue != GIT_OK) return nil; | ||
|
|
||
| GTDiff *newDiff = [[GTDiff alloc] initWithGitDiffList:diffList]; | ||
| return newDiff; | ||
| } | ||
|
|
||
| + (GTDiff *)diffIndexFromTree:(GTTree *)tree options:(NSDictionary *)options { | ||
| NSParameterAssert(tree != nil); | ||
|
|
||
| git_diff_options optionsStruct = GIT_DIFF_OPTIONS_INIT; | ||
| BOOL optionsStructCreated = [self optionsStructFromDictionary:options optionsStruct:&optionsStruct]; | ||
| git_diff_list *diffList; | ||
| int returnValue = git_diff_tree_to_index(&diffList, tree.repository.git_repository, tree.git_tree, NULL, (optionsStructCreated ? &optionsStruct : NULL)); | ||
| if (returnValue != GIT_OK) return nil; | ||
|
|
||
| GTDiff *newDiff = [[GTDiff alloc] initWithGitDiffList:diffList]; | ||
| return newDiff; | ||
| } | ||
|
|
||
| + (GTDiff *)diffIndexToWorkingDirectoryInRepository:(GTRepository *)repository options:(NSDictionary *)options { | ||
| NSParameterAssert(repository != nil); | ||
|
|
||
| git_diff_options optionsStruct = GIT_DIFF_OPTIONS_INIT; | ||
| BOOL optionsStructCreated = [self optionsStructFromDictionary:options optionsStruct:&optionsStruct]; | ||
| git_diff_list *diffList; | ||
| int returnValue = git_diff_index_to_workdir(&diffList, repository.git_repository, NULL, (optionsStructCreated ? &optionsStruct : NULL)); | ||
| if (returnValue != GIT_OK) return nil; | ||
|
|
||
| GTDiff *newDiff = [[GTDiff alloc] initWithGitDiffList:diffList]; | ||
| return newDiff; | ||
| } | ||
|
|
||
| + (GTDiff *)diffWorkingDirectoryFromTree:(GTTree *)tree options:(NSDictionary *)options { | ||
| NSParameterAssert(tree != nil); | ||
|
|
||
| git_diff_options optionsStruct = GIT_DIFF_OPTIONS_INIT; | ||
| BOOL optionsStructCreated = [self optionsStructFromDictionary:options optionsStruct:&optionsStruct]; | ||
| git_diff_list *diffList; | ||
| int returnValue = git_diff_tree_to_workdir(&diffList, tree.repository.git_repository, tree.git_tree, (optionsStructCreated ? &optionsStruct : NULL)); | ||
| if (returnValue != GIT_OK) return nil; | ||
|
|
||
| GTDiff *newDiff = [[GTDiff alloc] initWithGitDiffList:diffList]; | ||
| return newDiff; | ||
| } | ||
|
|
||
| - (instancetype)initWithGitDiffList:(git_diff_list *)diffList { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method should assert that the argument isn't There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (This was done) |
||
| NSParameterAssert(diffList != NULL); | ||
|
|
||
| self = [super init]; | ||
| if (self == nil) return nil; | ||
|
|
||
| _git_diff_list = diffList; | ||
|
|
||
| return self; | ||
| } | ||
|
|
||
| - (void)dealloc { | ||
| git_diff_list_free(self.git_diff_list); | ||
| } | ||
|
|
||
| - (void)enumerateDeltasUsingBlock:(void (^)(GTDiffDelta *delta, BOOL *stop))block { | ||
| NSParameterAssert(block != nil); | ||
|
|
||
| for (NSUInteger idx = 0; idx < self.deltaCount; idx ++) { | ||
| git_diff_patch *patch; | ||
| int result = git_diff_get_patch(&patch, NULL, self.git_diff_list, idx); | ||
| if (result != GIT_OK) continue; | ||
| GTDiffDelta *delta = [[GTDiffDelta alloc] initWithGitPatch:patch]; | ||
| BOOL stop = NO; | ||
| block(delta, &stop); | ||
| if (stop) return; | ||
| } | ||
| } | ||
|
|
||
| - (NSUInteger)deltaCount { | ||
| return git_diff_num_deltas(self.git_diff_list); | ||
| } | ||
|
|
||
| - (NSUInteger)numberOfDeltasWithType:(GTDiffDeltaType)deltaType { | ||
| return git_diff_num_deltas_of_type(self.git_diff_list, (git_delta_t)deltaType); | ||
| } | ||
|
|
||
| - (BOOL)findOptionsStructWithDictionary:(NSDictionary *)dictionary optionsStruct:(git_diff_find_options *)newOptions { | ||
| if (dictionary == nil || dictionary.count < 1) return NO; | ||
|
|
||
| NSNumber *flagsNumber = dictionary[GTDiffFindOptionsFlagsKey]; | ||
| if (flagsNumber != nil) newOptions->flags = (uint32_t)flagsNumber.unsignedIntegerValue; | ||
|
|
||
| NSNumber *renameThresholdNumber = dictionary[GTDiffFindOptionsRenameThresholdKey]; | ||
| if (renameThresholdNumber != nil) newOptions->rename_threshold = renameThresholdNumber.unsignedIntValue; | ||
|
|
||
| NSNumber *renameFromRewriteThresholdNumber = dictionary[GTDiffFindOptionsRenameFromRewriteThresholdKey]; | ||
| if (renameFromRewriteThresholdNumber != nil) newOptions->rename_from_rewrite_threshold = renameFromRewriteThresholdNumber.unsignedIntValue; | ||
|
|
||
| NSNumber *copyThresholdNumber = dictionary[GTDiffFindOptionsCopyThresholdKey]; | ||
| if (copyThresholdNumber != nil) newOptions->copy_threshold = copyThresholdNumber.unsignedIntValue; | ||
|
|
||
| NSNumber *breakRewriteThresholdNumber = dictionary[GTDiffFindOptionsBreakRewriteThresholdKey]; | ||
| if (renameThresholdNumber != nil) newOptions->break_rewrite_threshold = breakRewriteThresholdNumber.unsignedIntValue; | ||
|
|
||
| NSNumber *targetLimitNumber = dictionary[GTDiffFindOptionsTargetLimitKey]; | ||
| if (targetLimitNumber != nil) newOptions->target_limit = targetLimitNumber.unsignedIntValue; | ||
|
|
||
| return YES; | ||
| } | ||
|
|
||
| - (void)findSimilarWithOptions:(NSDictionary *)options { | ||
| git_diff_find_options findOptions = GIT_DIFF_FIND_OPTIONS_INIT; | ||
| BOOL findOptionsCreated = [self findOptionsStructWithDictionary:options optionsStruct:&findOptions]; | ||
| git_diff_find_similar(self.git_diff_list, (findOptionsCreated ? &findOptions : NULL)); | ||
| } | ||
|
|
||
| @end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we have to cast this, either we're wrong, or libgit2 is. One of the two needs to be fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think libgit2 is wrong. It should be
const char *and I see that it is not currently.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yarp.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I open an issue on libgit2/libgit2 @arrbee
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. I fixed it in libgit2/libgit2#1118 but that's not really an appropriate place for that fix, plus it will probably be a week before that PR is ready to merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dannygreg Can we add a comment to this code referencing that PR, just so we know that the cast is a temporary workaround?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can indeed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment added in 838b971.