{"thread":{"id":"44809","subject":"[PATCH] diff: add interhunk context config option","startedAt":"2017-01-02T23:34:09Z","lastAt":"2017-01-08T03:02:45Z","messageCount":3,"participants":["Vegard Nossum","Pranit Bauva","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"308694","messageId":"20170102233114.20778-1-vegard.nossum@oracle.com","threadId":"44809","inReplyTo":null,"subject":"[PATCH] diff: add interhunk context config option","fromName":"Vegard Nossum","fromEmail":"vegard.nossum@oracle.com","sentAt":"2017-01-02T23:31:14Z","receivedAt":"2017-01-02T23:34:09Z","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>\nSigned-off-by: Vegard Nossum <vegard.nossum@oracle.com>\n---\n Documentation/diff-options.txt | 2 ++\n diff.c                         | 8 ++++++++\n 2 files changed, 10 insertions(+)\n\ndiff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt\nindex e6215c372..163b65444 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 84dba60c4..40b4e6afe 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 = 0;\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 \n-- \n2.11.0.1.gaa10c3f\n\n"},{"id":"308696","messageId":"CAFZEwPMLk5KTeLR9zygU6ZH5zN7TLnQzmJVpyCNig8FrYcOazw@mail.gmail.com","threadId":"44809","inReplyTo":"20170102233114.20778-1-vegard.nossum@oracle.com","subject":"Re: [PATCH] diff: add interhunk context config option","fromName":"Pranit Bauva","fromEmail":"pranit.bauva@gmail.com","sentAt":"2017-01-03T06:19:25Z","receivedAt":"2017-01-03T06:19:32Z","isPatch":true,"sender":{"key":"pranit.bauva@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2959938?v=4"},"body":"Hey Vegard,\n\nOn Tue, Jan 3, 2017 at 5:01 AM, Vegard Nossum <vegard.nossum@oracle.com> wrote:\n> The --inter-hunk-context= option was added in commit 6d0e674a5754\n> (\"diff: add option to show context between close hunks\"). This patch\n> allows configuring a default for this option.\n>\n> Cc: René Scharfe <l.s.r@web.de>\n> Signed-off-by: Vegard Nossum <vegard.nossum@oracle.com>\n> ---\n>  Documentation/diff-options.txt | 2 ++\n>  diff.c                         | 8 ++++++++\n>  2 files changed, 10 insertions(+)\n>\n> diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt\n> index e6215c372..163b65444 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>         Show the context between diff hunks, up to the specified number\n>         of lines, thereby fusing hunks that are close to each other.\n> +       Defaults to `diff.interhunkcontext` or 0 if the config option\n> +       is unset.\n\nSeems good. But I think you have missed adding the documentation of\nthis to Documentation/diff-config.txt . Generally whatever config\nvariable one adds, is added to Documentation/config.txt but in this\ncase, there exists a separate Documentation/diff-config.txt for all\n\"diff\" related things which is included in Documentation/config.txt .\nAlso, you need to link the link both the parts of this documentation.\nPlease refer to commit id aaab84203 so as to know what I am talking\nabout.\n\n>  -W::\n>  --function-context::\n> diff --git a/diff.c b/diff.c\n> index 84dba60c4..40b4e6afe 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 = 0;\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>                         return -1;\n>                 return 0;\n>         }\n> +       if (!strcmp(var, \"diff.interhunkcontext\")) {\n> +               diff_interhunk_context_default = git_config_int(var, value);\n> +               if (diff_interhunk_context_default < 0)\n> +                       return -1;\n> +               return 0;\n> +       }\n>         if (!strcmp(var, \"diff.renames\")) {\n>                 diff_detect_rename_default = git_config_rename(var, value);\n>                 return 0;\n> @@ -3371,6 +3378,7 @@ void diff_setup(struct diff_options *options)\n>         options->rename_limit = -1;\n>         options->dirstat_permille = diff_dirstat_permille_default;\n>         options->context = diff_context_default;\n> +       options->interhunkcontext = diff_interhunk_context_default;\n>         options->ws_error_highlight = ws_error_highlight_default;\n>         DIFF_OPT_SET(options, RENAME_EMPTY);\n\nOn a first look, it seems that we can overwrite the default config\nvalues by using a different command line argument which is good.\n\nAlso, tests are missing. It seems that t/t4032 might be a good place\nto add those tests.\n\nRest all is quite good! :)\n\nRegards,\nPranit Bauva\n"},{"id":"308945","messageId":"xmqqtw9a1cfo.fsf@gitster.mtv.corp.google.com","threadId":"44809","inReplyTo":"CAFZEwPMLk5KTeLR9zygU6ZH5zN7TLnQzmJVpyCNig8FrYcOazw@mail.gmail.com","subject":"Re: [PATCH] diff: add interhunk context config option","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-01-08T03:02:35Z","receivedAt":"2017-01-08T03:02:45Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Pranit Bauva <pranit.bauva@gmail.com> writes:\n\n>> diff --git a/diff.c b/diff.c\n>> index 84dba60c4..40b4e6afe 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 = 0;\n\nDo not explicitly initialize BSS variables to 0 (or NULL).\n\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>>                         return -1;\n>>                 return 0;\n>>         }\n>> +       if (!strcmp(var, \"diff.interhunkcontext\")) {\n>> +               diff_interhunk_context_default = git_config_int(var, value);\n>> +               if (diff_interhunk_context_default < 0)\n>> +                       return -1;\n>> +               return 0;\n>> +       }\n>>         if (!strcmp(var, \"diff.renames\")) {\n>>                 diff_detect_rename_default = git_config_rename(var, value);\n>>                 return 0;\n>> @@ -3371,6 +3378,7 @@ void diff_setup(struct diff_options *options)\n>>         options->rename_limit = -1;\n>>         options->dirstat_permille = diff_dirstat_permille_default;\n>>         options->context = diff_context_default;\n>> +       options->interhunkcontext = diff_interhunk_context_default;\n\nWill this receive -1 if diff.interhunkcontext configuration variable\nis misconfigured and the *_default variable receives the error return\nvalue from git_config_int()?\n\n\n>>         options->ws_error_highlight = ws_error_highlight_default;\n>>         DIFF_OPT_SET(options, RENAME_EMPTY);\n>\n> On a first look, it seems that we can overwrite the default config\n> values by using a different command line argument which is good.\n>\n> Also, tests are missing. It seems that t/t4032 might be a good place\n> to add those tests.\n>\n> Rest all is quite good! :)\n>\n> Regards,\n> Pranit Bauva\n"}]}