summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2013-03-09 16:04:34 +0100
committerCarlos Martín Nieto <cmn@dwim.me>2013-03-09 16:04:34 +0100
commit1aa5318a9ec4f0ec16518d1102b29e5ba94a801a (patch)
treef4c255cfa982becd1392608c1b60ea7c8b15fe97 /src
parent0887b580bfe83a9f6e9a8530368a22e478411a0f (diff)
downloadlibgit2-1aa5318a9ec4f0ec16518d1102b29e5ba94a801a.tar.gz
diff: allow asking for diffs with no context
Previously, 0 meant default. This is problematic, as asking for 0 context lines is a valid thing to do. Change GIT_DIFF_OPTIONS_INIT to default to three and stop treating 0 as a magic value. In case no options are provided, make sure the options in the diff object default to 3.
Diffstat (limited to 'src')
-rw-r--r--src/diff.c5
-rw-r--r--src/diff_output.c2
2 files changed, 5 insertions, 2 deletions
diff --git a/src/diff.c b/src/diff.c
index 0861b13eb..ca08f4233 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -291,8 +291,11 @@ static git_diff_list *git_diff_list_alloc(
* - diff.noprefix
*/
- if (opts == NULL)
+ if (opts == NULL) {
+ /* Make sure we default to 3 lines */
+ diff->opts.context_lines = 3;
return diff;
+ }
memcpy(&diff->opts, opts, sizeof(git_diff_options));
diff --git a/src/diff_output.c b/src/diff_output.c
index 209a6e017..43262b1ae 100644
--- a/src/diff_output.c
+++ b/src/diff_output.c
@@ -202,7 +202,7 @@ static void setup_xdiff_options(
memset(param, 0, sizeof(xpparam_t));
cfg->ctxlen =
- (!opts || !opts->context_lines) ? 3 : opts->context_lines;
+ (!opts) ? 3 : opts->context_lines;
cfg->interhunkctxlen =
(!opts) ? 0 : opts->interhunk_lines;