{"thread":{"id":"44863","subject":"[PATCH v2] diff: add interhunk context config option","startedAt":"2017-01-12T12:21:46Z","lastAt":"2017-01-12T20:56:20Z","messageCount":2,"participants":["Vegard Nossum","Junio C Hamano"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"309271","messageId":"1484223671-5476-1-git-send-email-vegard.nossum@oracle.com","threadId":"44863","inReplyTo":null,"subject":"[PATCH v2] diff: add interhunk context config option","fromName":"Vegard Nossum","fromEmail":"vegard.nossum@oracle.com","sentAt":"2017-01-12T12:21:11Z","receivedAt":"2017-01-12T12:21:46Z","isPatch":true,"sender":{"key":"vegard.nossum@oracle.com","avatar":"https://avatars.githubusercontent.com/u/24173?v=4"},"body":"The --inter-hunk-context= option was added in commit 6d0e674a5754\n(\"diff: add option to show context between close hunks\"). This patch\nallows configuring a default for this option.\n\nCc: René Scharfe <l.s.r@web.de>\nCc: Pranit Bauva <pranit.bauva@gmail.com>\nSigned-off-by: Vegard Nossum <vegard.nossum@oracle.com>\n\n---\nv2:\n - Update Documentation/diff-config.txt, suggested by Pranit Bauva.\n - Add tests, suggested by Pranit Bauva.\n - Don't initialize BSS variable to 0, suggested by Junio Hamano.\n - Junio: if git_config_int() fails, you will get something like:\n   \"fatal: bad config variable 'diff.interhunkcontext' in file '/home/vegard/.gitconfig' at line 5\"\n---\n Documentation/diff-config.txt      |  6 ++++++\n Documentation/diff-options.txt     |  2 ++\n diff.c                             |  8 ++++++++\n t/t4032-diff-inter-hunk-context.sh | 27 ++++++++++++++++++++++++++-\n 4 files changed, 42 insertions(+), 1 deletion(-)\n\ndiff --git a/Documentation/diff-config.txt b/Documentation/diff-config.txt\nindex 58f4bd6..d8cd854 100644\n--- a/Documentation/diff-config.txt\n+++ b/Documentation/diff-config.txt\n@@ -60,6 +60,12 @@ diff.context::\n \tGenerate diffs with <n> lines of context instead of the default\n \tof 3. This value is overridden by the -U option.\n \n+diff.interHunkContext::\n+\tShow the context between diff hunks, up to <n> lines, thereby\n+\tfusing the hunks that are close to each other. The default is 0,\n+\tmeaning no fusing will occur. This value is overridden by the\n+\t--inter-hunk-context option.\n+\n diff.external::\n \tIf this config variable is set, diff generation is not\n \tperformed using the internal diff machinery, but using the\ndiff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt\nindex e6215c3..a219aa2 100644\n--- a/Documentation/diff-options.txt\n+++ b/Documentation/diff-options.txt\n@@ -511,6 +511,8 @@ endif::git-format-patch[]\n --inter-hunk-context=<lines>::\n \tShow the context between diff hunks, up to the specified number\n \tof lines, thereby fusing hunks that are close to each other.\n+\tDefaults to `diff.interHunkContext` or 0 if the config option\n+\tis unset.\n \n -W::\n --function-context::\ndiff --git a/diff.c b/diff.c\nindex 84dba60..a92080c 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -33,6 +33,7 @@ static int diff_rename_limit_default = 400;\n static int diff_suppress_blank_empty;\n static int diff_use_color_default = -1;\n static int diff_context_default = 3;\n+static int diff_interhunk_context_default;\n static const char *diff_word_regex_cfg;\n static const char *external_diff_cmd_cfg;\n static const char *diff_order_file_cfg;\n@@ -248,6 +249,12 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)\n \t\t\treturn -1;\n \t\treturn 0;\n \t}\n+\tif (!strcmp(var, \"diff.interhunkcontext\")) {\n+\t\tdiff_interhunk_context_default = git_config_int(var, value);\n+\t\tif (diff_interhunk_context_default < 0)\n+\t\t\treturn -1;\n+\t\treturn 0;\n+\t}\n \tif (!strcmp(var, \"diff.renames\")) {\n \t\tdiff_detect_rename_default = git_config_rename(var, value);\n \t\treturn 0;\n@@ -3371,6 +3378,7 @@ void diff_setup(struct diff_options *options)\n \toptions->rename_limit = -1;\n \toptions->dirstat_permille = diff_dirstat_permille_default;\n \toptions->context = diff_context_default;\n+\toptions->interhunkcontext = diff_interhunk_context_default;\n \toptions->ws_error_highlight = ws_error_highlight_default;\n \tDIFF_OPT_SET(options, RENAME_EMPTY);\n \ndiff --git a/t/t4032-diff-inter-hunk-context.sh b/t/t4032-diff-inter-hunk-context.sh\nindex e4e3e28..d9ac9d1 100755\n--- a/t/t4032-diff-inter-hunk-context.sh\n+++ b/t/t4032-diff-inter-hunk-context.sh\n@@ -16,11 +16,15 @@ f() {\n }\n \n t() {\n+\tuse_config=\"\"\n+\tgit config --unset diff.interHunkContext\n+\n \tcase $# in\n \t4) hunks=$4; cmd=\"diff -U$3\";;\n \t5) hunks=$5; cmd=\"diff -U$3 --inter-hunk-context=$4\";;\n+\t6) hunks=$5; cmd=\"diff -U$3\"; git config diff.interHunkContext $4; use_config=\"(diff.interHunkContext=$4) \";;\n \tesac\n-\tlabel=\"$cmd, $1 common $2\"\n+\tlabel=\"$use_config$cmd, $1 common $2\"\n \tfile=f$1\n \texpected=expected.$file.$3.$hunks\n \n@@ -89,4 +93,25 @@ t 9 lines\t3\t\t2\n t 9 lines\t3\t2\t2\n t 9 lines\t3\t3\t1\n \n+#\t\t\t\t\tuse diff.interHunkContext?\n+t 1 line\t0\t0\t2\tconfig\n+t 1 line\t0\t1\t1\tconfig\n+t 1 line\t0\t2\t1\tconfig\n+t 9 lines\t3\t3\t1\tconfig\n+t 2 lines\t0\t0\t2\tconfig\n+t 2 lines\t0\t1\t2\tconfig\n+t 2 lines\t0\t2\t1\tconfig\n+t 3 lines\t1\t0\t2\tconfig\n+t 3 lines\t1\t1\t1\tconfig\n+t 3 lines\t1\t2\t1\tconfig\n+t 9 lines\t3\t2\t2\tconfig\n+t 9 lines\t3\t3\t1\tconfig\n+\n+test_expect_success 'diff.interHunkContext invalid' '\n+\tgit config diff.interHunkContext asdf &&\n+\ttest_must_fail git diff &&\n+\tgit config diff.interHunkContext -1 &&\n+\ttest_must_fail git diff\n+'\n+\n test_done\n-- \n2.7.4\n\n"},{"id":"309289","messageId":"xmqq4m14j8ur.fsf@gitster.mtv.corp.google.com","threadId":"44863","inReplyTo":"1484223671-5476-1-git-send-email-vegard.nossum@oracle.com","subject":"Re: [PATCH v2] diff: add interhunk context config option","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-01-12T20:56:12Z","receivedAt":"2017-01-12T20:56:20Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Vegard Nossum <vegard.nossum@oracle.com> writes:\n\n> diff --git a/Documentation/diff-config.txt b/Documentation/diff-config.txt\n> index 58f4bd6..d8cd854 100644\n> --- a/Documentation/diff-config.txt\n> +++ b/Documentation/diff-config.txt\n> @@ -60,6 +60,12 @@ diff.context::\n>  \tGenerate diffs with <n> lines of context instead of the default\n>  \tof 3. This value is overridden by the -U option.\n>  \n> +diff.interHunkContext::\n> +\tShow the context between diff hunks, up to <n> lines, thereby\n> +\tfusing the hunks that are close to each other. The default is 0,\n> +\tmeaning no fusing will occur. This value is overridden by the\n> +\t--inter-hunk-context option.\n\nThis is good if it were a description for\n\"--inter-hunk-context=<n>\", but the text needs to be adjusted if it\nwere to be used for \"diff.interHunkContext\".  It is unclear how the\n'<n>' the description refers to comes from.\n\nI suspect that it would be sufficient to just revert the first\nsentence to exactly match the way --inter-hunk-context=<lines> is\ndescribed.\n\n> diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt\n> index e6215c3..a219aa2 100644\n> --- a/Documentation/diff-options.txt\n> +++ b/Documentation/diff-options.txt\n> @@ -511,6 +511,8 @@ endif::git-format-patch[]\n>  --inter-hunk-context=<lines>::\n>  \tShow the context between diff hunks, up to the specified number\n>  \tof lines, thereby fusing hunks that are close to each other.\n> +\tDefaults to `diff.interHunkContext` or 0 if the config option\n> +\tis unset.\n\nThis one is good, but then \"The default is 0, meaning no fusing will\noccur.\" in \"diff.interHunkContext\" is misleading and unnecessary.\nWhen \"diff.interHunkContext\" is not set, it simply is not set (as\nopposed to having a default value of 0).\n\n> diff --git a/t/t4032-diff-inter-hunk-context.sh b/t/t4032-diff-inter-hunk-context.sh\n> index e4e3e28..d9ac9d1 100755\n> --- a/t/t4032-diff-inter-hunk-context.sh\n> +++ b/t/t4032-diff-inter-hunk-context.sh\n> @@ -16,11 +16,15 @@ f() {\n>  }\n>  \n>  t() {\n> +\tuse_config=\"\"\n\nIt is more customary to just say\n\n\tuse_config=\n\nAll of the above are micronits that I can locally touch-up.  For\nnow, I'll queue the following.\n\n-- >8 --\nFrom: Vegard Nossum <vegard.nossum@oracle.com>\nDate: Thu, 12 Jan 2017 13:21:11 +0100\nSubject: [PATCH] diff: add interhunk context config option\n\nThe --inter-hunk-context= option was added in commit 6d0e674a5754\n(\"diff: add option to show context between close hunks\"). This patch\nallows configuring a default for this option.\n\nSigned-off-by: Vegard Nossum <vegard.nossum@oracle.com>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n Documentation/diff-config.txt      |  6 ++++++\n Documentation/diff-options.txt     |  2 ++\n diff.c                             |  8 ++++++++\n t/t4032-diff-inter-hunk-context.sh | 27 ++++++++++++++++++++++++++-\n 4 files changed, 42 insertions(+), 1 deletion(-)\n\ndiff --git a/Documentation/diff-config.txt b/Documentation/diff-config.txt\nindex d8570f2a75..15521f5191 100644\n--- a/Documentation/diff-config.txt\n+++ b/Documentation/diff-config.txt\n@@ -60,6 +60,12 @@ diff.context::\n \tGenerate diffs with <n> lines of context instead of the default\n \tof 3. This value is overridden by the -U option.\n \n+diff.interHunkContext::\n+\tShow the context between diff hunks, up to the specified number\n+\tof lines, thereby fusing the hunks that are close to each other.\n+\tThis value serves as the default for the `--inter-hunk-context`\n+\tcommand line option.\n+\n diff.external::\n \tIf this config variable is set, diff generation is not\n \tperformed using the internal diff machinery, but using the\ndiff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt\nindex e6215c372c..a219aa2907 100644\n--- a/Documentation/diff-options.txt\n+++ b/Documentation/diff-options.txt\n@@ -511,6 +511,8 @@ endif::git-format-patch[]\n --inter-hunk-context=<lines>::\n \tShow the context between diff hunks, up to the specified number\n \tof lines, thereby fusing hunks that are close to each other.\n+\tDefaults to `diff.interHunkContext` or 0 if the config option\n+\tis unset.\n \n -W::\n --function-context::\ndiff --git a/diff.c b/diff.c\nindex e2eb6d66a9..f08cd8e033 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -32,6 +32,7 @@ static int diff_rename_limit_default = 400;\n static int diff_suppress_blank_empty;\n static int diff_use_color_default = -1;\n static int diff_context_default = 3;\n+static int diff_interhunk_context_default;\n static const char *diff_word_regex_cfg;\n static const char *external_diff_cmd_cfg;\n static const char *diff_order_file_cfg;\n@@ -239,6 +240,12 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)\n \t\t\treturn -1;\n \t\treturn 0;\n \t}\n+\tif (!strcmp(var, \"diff.interhunkcontext\")) {\n+\t\tdiff_interhunk_context_default = git_config_int(var, value);\n+\t\tif (diff_interhunk_context_default < 0)\n+\t\t\treturn -1;\n+\t\treturn 0;\n+\t}\n \tif (!strcmp(var, \"diff.renames\")) {\n \t\tdiff_detect_rename_default = git_config_rename(var, value);\n \t\treturn 0;\n@@ -3362,6 +3369,7 @@ void diff_setup(struct diff_options *options)\n \toptions->rename_limit = -1;\n \toptions->dirstat_permille = diff_dirstat_permille_default;\n \toptions->context = diff_context_default;\n+\toptions->interhunkcontext = diff_interhunk_context_default;\n \toptions->ws_error_highlight = ws_error_highlight_default;\n \tDIFF_OPT_SET(options, RENAME_EMPTY);\n \ndiff --git a/t/t4032-diff-inter-hunk-context.sh b/t/t4032-diff-inter-hunk-context.sh\nindex e4e3e28fc7..bada0cbd32 100755\n--- a/t/t4032-diff-inter-hunk-context.sh\n+++ b/t/t4032-diff-inter-hunk-context.sh\n@@ -16,11 +16,15 @@ f() {\n }\n \n t() {\n+\tuse_config=\n+\tgit config --unset diff.interHunkContext\n+\n \tcase $# in\n \t4) hunks=$4; cmd=\"diff -U$3\";;\n \t5) hunks=$5; cmd=\"diff -U$3 --inter-hunk-context=$4\";;\n+\t6) hunks=$5; cmd=\"diff -U$3\"; git config diff.interHunkContext $4; use_config=\"(diff.interHunkContext=$4) \";;\n \tesac\n-\tlabel=\"$cmd, $1 common $2\"\n+\tlabel=\"$use_config$cmd, $1 common $2\"\n \tfile=f$1\n \texpected=expected.$file.$3.$hunks\n \n@@ -89,4 +93,25 @@ t 9 lines\t3\t\t2\n t 9 lines\t3\t2\t2\n t 9 lines\t3\t3\t1\n \n+#\t\t\t\t\tuse diff.interHunkContext?\n+t 1 line\t0\t0\t2\tconfig\n+t 1 line\t0\t1\t1\tconfig\n+t 1 line\t0\t2\t1\tconfig\n+t 9 lines\t3\t3\t1\tconfig\n+t 2 lines\t0\t0\t2\tconfig\n+t 2 lines\t0\t1\t2\tconfig\n+t 2 lines\t0\t2\t1\tconfig\n+t 3 lines\t1\t0\t2\tconfig\n+t 3 lines\t1\t1\t1\tconfig\n+t 3 lines\t1\t2\t1\tconfig\n+t 9 lines\t3\t2\t2\tconfig\n+t 9 lines\t3\t3\t1\tconfig\n+\n+test_expect_success 'diff.interHunkContext invalid' '\n+\tgit config diff.interHunkContext asdf &&\n+\ttest_must_fail git diff &&\n+\tgit config diff.interHunkContext -1 &&\n+\ttest_must_fail git diff\n+'\n+\n test_done\n-- \n2.11.0-559-ge2476dcca1\n\n"}]}