Skip to content

Commit 7e3faf5

Browse files
committed
diff: expose the "indent heuristic" in the diff options
We default to off, but we might want to consider changing `GIT_DIFF_NORMAL` to include it.
1 parent a8f19f8 commit 7e3faf5

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ v0.26 + 1
1212

1313
* We now support conditional includes in configuration files.
1414

15+
* There is a new diff option, `GIT_DIFF_INDENT_HEURISTIC` which activates a
16+
heuristic which takes into account whitespace and indentation in order to
17+
produce better diffs when dealing with ambiguous diff hunks.
18+
1519
### API additions
1620

1721
* `git_remote_create_detached()` creates a remote that is not associated

include/git2/diff.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,12 @@ typedef enum {
206206
* can apply given diff information to binary files.
207207
*/
208208
GIT_DIFF_SHOW_BINARY = (1 << 30),
209+
210+
/** Use a heuristic that takes indentation and whitespace into account
211+
* which generally can produce better diffs when dealing with ambiguous
212+
* diff hunks.
213+
*/
214+
GIT_DIFF_INDENT_HEURISTIC = (1 << 31),
209215
} git_diff_option_t;
210216

211217
/**

src/diff_xdiff.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ void git_xdiff_init(git_xdiff_output *xo, const git_diff_options *opts)
239239
xo->params.flags |= XDF_IGNORE_WHITESPACE_CHANGE;
240240
if (flags & GIT_DIFF_IGNORE_WHITESPACE_EOL)
241241
xo->params.flags |= XDF_IGNORE_WHITESPACE_AT_EOL;
242+
if (flags & GIT_DIFF_INDENT_HEURISTIC)
243+
xo->params.flags |= XDF_INDENT_HEURISTIC;
242244

243245
if (flags & GIT_DIFF_PATIENCE)
244246
xo->params.flags |= XDF_PATIENCE_DIFF;

0 commit comments

Comments
 (0)