{"thread":{"id":"25860","subject":"[PATCH/RFC 2/3] diffstat: Use new diff.stat config values","startedAt":"2010-11-28T23:51:33Z","lastAt":"2010-12-09T05:54:07Z","messageCount":6,"participants":["Matthew Ruffalo","Junio C Hamano","mmr15@case.edu"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"156780","messageId":"4CF2EB05.5090300@case.edu","threadId":"25860","inReplyTo":null,"subject":"[PATCH/RFC 2/3] diffstat: Use new diff.stat config values","fromName":"Matthew Ruffalo","fromEmail":"mmr15@case.edu","sentAt":"2010-11-28T23:51:33Z","receivedAt":"2010-11-28T23:51:33Z","isPatch":true,"sender":{"key":"mmr15@case.edu","avatar":null},"body":">From f3ca8d4222776fb38a2def4fb9c4691c09c1e0fd Mon Sep 17 00:00:00 2001\nFrom: Matthew Ruffalo <matthew.ruffalo@case.edu>\nDate: Sun, 28 Nov 2010 14:44:00 -0500\nSubject: [PATCH 2/3] diffstat: Use new diff.stat config values\n\nPreviously, the diffstat width could only be specified with the\ncommand-line options '--width' and '--name-width'. This patch adds\nsupport for config file options 'diff.stat.width' and\n'diff.stat.namewidth'.\n\nThe diffstat width values are obtained in this order (of increasing\nprecedence):\n\n 1. Compile-time defaults (80 width, 50 namewidth)\n 2. Standard git config mechanism\n 3. Command-line options\n\nThis required removing the diffstat options from 'struct diff_options'\nand adding these values as static ints in diff.c. This preserves the\nstyle of \"config options are static ints, command-line options are\ndiff_options members\". stat_opt now directly sets the global options.\n\nSigned-off-by: Matthew Ruffalo <matthew.ruffalo@case.edu>\n---\n diff.c |   24 ++++++++++++++++++------\n diff.h |    2 --\n 2 files changed, 18 insertions(+), 8 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex a151681..d2a3e44 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -31,6 +31,8 @@ static const char *external_diff_cmd_cfg;\n int diff_auto_refresh_index = 1;\n static int diff_mnemonic_prefix;\n static int diff_no_prefix;\n+static int diff_stat_width;\n+static int diff_stat_name_width;\n static struct diff_options default_diff_options;\n \n static char diff_colors[][COLOR_MAXLEN] = {\n@@ -148,6 +150,16 @@ int git_diff_basic_config(const char *var, const\nchar *value, void *cb)\n        if (!prefixcmp(var, \"submodule.\"))\n                return parse_submodule_config_option(var, value);\n \n+       if (!strcmp(var, \"diff.stat.width\")) {\n+               diff_stat_width = git_config_int(var, value);\n+               return 0;\n+       }\n+\n+       if (!strcmp(var, \"diff.stat.namewidth\")) {\n+               diff_stat_name_width = git_config_int(var, value);\n+               return 0;\n+       }\n+\n        return git_color_default_config(var, value, cb);\n }\n \n@@ -1247,8 +1259,8 @@ static void show_stats(struct diffstat_t *data,\nstruct diff_options *options)\n                line_prefix = msg->buf;\n        }\n \n-       width = options->stat_width ? options->stat_width :\nDIFF_STAT_DEFAULT_WIDTH;\n-       name_width = options->stat_name_width ? options->stat_name_width\n: DIFF_STAT_DEFAULT_NAME_WIDTH;\n+       width = diff_stat_width ? diff_stat_width : DIFF_STAT_DEFAULT_WIDTH;\n+       name_width = diff_stat_name_width ? diff_stat_name_width :\nDIFF_STAT_DEFAULT_NAME_WIDTH;\n \n        /* Sanity: give at least 5 columns to the graph,\n         * but leave at least 10 columns for the name.\n@@ -3053,8 +3065,8 @@ static int stat_opt(struct diff_options *options,\nconst char **av)\n {\n        const char *arg = av[0];\n        char *end;\n-       int width = options->stat_width;\n-       int name_width = options->stat_name_width;\n+       int width = diff_stat_width;\n+       int name_width = diff_stat_name_width;\n        int argcount = 1;\n \n        arg += strlen(\"--stat\");\n@@ -3094,8 +3106,8 @@ static int stat_opt(struct diff_options *options,\nconst char **av)\n        if (*end)\n                return 0;\n        options->output_format |= DIFF_FORMAT_DIFFSTAT;\n-       options->stat_name_width = name_width;\n-       options->stat_width = width;\n+       diff_stat_name_width = name_width;\n+       diff_stat_width = width;\n        return argcount;\n }\n \ndiff --git a/diff.h b/diff.h\nindex 7b509c5..011f2ac 100644\n--- a/diff.h\n+++ b/diff.h\n@@ -122,8 +122,6 @@ struct diff_options {\n        const char *stat_sep;\n        long xdl_opts;\n \n-       int stat_width;\n-       int stat_name_width;\n        const char *word_regex;\n        enum diff_words_type word_diff;\n \n-- \n1.7.1\n"},{"id":"156837","messageId":"7vzksr280s.fsf@alter.siamese.dyndns.org","threadId":"25860","inReplyTo":"4CF2EB05.5090300@case.edu","subject":"Re: [PATCH/RFC 2/3] diffstat: Use new diff.stat config values","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-11-29T20:24:03Z","receivedAt":"2010-11-29T20:24:03Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Matthew Ruffalo <mmr15@case.edu> writes:\n\n> From f3ca8d4222776fb38a2def4fb9c4691c09c1e0fd Mon Sep 17 00:00:00 2001\n> From: Matthew Ruffalo <matthew.ruffalo@case.edu>\n> Date: Sun, 28 Nov 2010 14:44:00 -0500\n> Subject: [PATCH 2/3] diffstat: Use new diff.stat config values\n\nPlease drop these lines --- I can see them in the header of your e-mail.\n\n> Previously, the diffstat width could only be specified with the\n> command-line options '--width' and '--name-width'. This patch adds\n> support for config file options 'diff.stat.width' and\n> 'diff.stat.namewidth'.\n\nIn general, the second level in a three-level configuration variable name\nis to choose which one of unbound set of things to set the value for, and\nthe last level of a configuration variable name is to name the specific\nproperty to affect (e.g. \"difftool.<tool>.path\" \"remote.<name>.url\").\n\nSo this sounds more like \"diffstat.width\" and \"diffstat.namewidth\".  There\nis no set of \"<something>\" that share \"namewidth\" property to warrant the\nname \"diff.<something>.namewidth\".\n\nThe idea of the patch is good.  But the message is heavily whitespace\ndamaged and cannot be applied.  Please check the settings of your MUA.\n\nThanks.\n"},{"id":"157570","messageId":"1291776263-16320-1-git-send-email-matthew.ruffalo@case.edu","threadId":"25860","inReplyTo":"7vzksr280s.fsf@alter.siamese.dyndns.org","subject":"[PATCH 1/3] diffstat width: #define defaults in diff.h","fromName":"","fromEmail":"mmr15@case.edu","sentAt":"2010-12-08T02:44:21Z","receivedAt":"2010-12-08T02:44:21Z","isPatch":true,"sender":{"key":"mmr15@case.edu","avatar":null},"body":"From: Matthew Ruffalo <matthew.ruffalo@case.edu>\n\nSigned-off-by: Matthew Ruffalo <matthew.ruffalo@case.edu>\n---\n diff.c |    4 ++--\n diff.h |    3 +++\n 2 files changed, 5 insertions(+), 2 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex db5e844..75938e4 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -1247,8 +1247,8 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)\n \t\tline_prefix = msg->buf;\n \t}\n \n-\twidth = options->stat_width ? options->stat_width : 80;\n-\tname_width = options->stat_name_width ? options->stat_name_width : 50;\n+\twidth = options->stat_width ? options->stat_width : DIFF_STAT_DEFAULT_WIDTH;\n+\tname_width = options->stat_name_width ? options->stat_name_width : DIFF_STAT_DEFAULT_NAME_WIDTH;\n \n \t/* Sanity: give at least 5 columns to the graph,\n \t * but leave at least 10 columns for the name.\ndiff --git a/diff.h b/diff.h\nindex 0083d92..7b509c5 100644\n--- a/diff.h\n+++ b/diff.h\n@@ -86,6 +86,9 @@ typedef struct strbuf *(*diff_prefix_fn_t)(struct diff_options *opt, void *data)\n #define DIFF_XDL_SET(opts, flag)    ((opts)->xdl_opts |= XDF_##flag)\n #define DIFF_XDL_CLR(opts, flag)    ((opts)->xdl_opts &= ~XDF_##flag)\n \n+#define DIFF_STAT_DEFAULT_WIDTH       80\n+#define DIFF_STAT_DEFAULT_NAME_WIDTH  50\n+\n enum diff_words_type {\n \tDIFF_WORDS_NONE = 0,\n \tDIFF_WORDS_PORCELAIN,\n-- \n1.7.1\n"},{"id":"157571","messageId":"1291776263-16320-2-git-send-email-matthew.ruffalo@case.edu","threadId":"25860","inReplyTo":"1291776263-16320-1-git-send-email-matthew.ruffalo@case.edu","subject":"[PATCH 2/3] diffstat: Use new diffstat config values","fromName":"","fromEmail":"mmr15@case.edu","sentAt":"2010-12-08T02:44:22Z","receivedAt":"2010-12-08T02:44:22Z","isPatch":true,"sender":{"key":"mmr15@case.edu","avatar":null},"body":"From: Matthew Ruffalo <matthew.ruffalo@case.edu>\n\nPreviously, the diffstat width could only be specified with the\ncommand-line options '--width' and '--name-width'. This patch adds\nsupport for config file options 'diffstat.width' and\n'diffstat.namewidth'.\n\nThe diffstat width values are obtained in this order (of increasing\nprecedence):\n\n 1. Compile-time defaults (80 width, 50 namewidth)\n 2. Standard git config mechanism\n 3. Command-line options\n\nThis required removing the diffstat options from 'struct diff_options'\nand adding these values as static ints in diff.c. This preserves the\nstyle of \"config options are static ints, command-line options are\ndiff_options members\". stat_opt now directly sets the global options.\n\nSigned-off-by: Matthew Ruffalo <matthew.ruffalo@case.edu>\n---\n diff.c |   24 ++++++++++++++++++------\n diff.h |    2 --\n 2 files changed, 18 insertions(+), 8 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 75938e4..d88c7f4 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -31,6 +31,8 @@ static const char *external_diff_cmd_cfg;\n int diff_auto_refresh_index = 1;\n static int diff_mnemonic_prefix;\n static int diff_no_prefix;\n+static int diff_stat_width;\n+static int diff_stat_name_width;\n static struct diff_options default_diff_options;\n \n static char diff_colors[][COLOR_MAXLEN] = {\n@@ -148,6 +150,16 @@ int git_diff_basic_config(const char *var, const char *value, void *cb)\n \tif (!prefixcmp(var, \"submodule.\"))\n \t\treturn parse_submodule_config_option(var, value);\n \n+\tif (!strcmp(var, \"diffstat.width\")) {\n+\t\tdiff_stat_width = git_config_int(var, value);\n+\t\treturn 0;\n+\t}\n+\n+\tif (!strcmp(var, \"diffstat.namewidth\")) {\n+\t\tdiff_stat_name_width = git_config_int(var, value);\n+\t\treturn 0;\n+\t}\n+\n \treturn git_color_default_config(var, value, cb);\n }\n \n@@ -1247,8 +1259,8 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)\n \t\tline_prefix = msg->buf;\n \t}\n \n-\twidth = options->stat_width ? options->stat_width : DIFF_STAT_DEFAULT_WIDTH;\n-\tname_width = options->stat_name_width ? options->stat_name_width : DIFF_STAT_DEFAULT_NAME_WIDTH;\n+\twidth = diff_stat_width ? diff_stat_width : DIFF_STAT_DEFAULT_WIDTH;\n+\tname_width = diff_stat_name_width ? diff_stat_name_width : DIFF_STAT_DEFAULT_NAME_WIDTH;\n \n \t/* Sanity: give at least 5 columns to the graph,\n \t * but leave at least 10 columns for the name.\n@@ -3057,8 +3069,8 @@ static int stat_opt(struct diff_options *options, const char **av)\n {\n \tconst char *arg = av[0];\n \tchar *end;\n-\tint width = options->stat_width;\n-\tint name_width = options->stat_name_width;\n+\tint width = diff_stat_width;\n+\tint name_width = diff_stat_name_width;\n \tint argcount = 1;\n \n \targ += strlen(\"--stat\");\n@@ -3098,8 +3110,8 @@ static int stat_opt(struct diff_options *options, const char **av)\n \tif (*end)\n \t\treturn 0;\n \toptions->output_format |= DIFF_FORMAT_DIFFSTAT;\n-\toptions->stat_name_width = name_width;\n-\toptions->stat_width = width;\n+\tdiff_stat_name_width = name_width;\n+\tdiff_stat_width = width;\n \treturn argcount;\n }\n \ndiff --git a/diff.h b/diff.h\nindex 7b509c5..011f2ac 100644\n--- a/diff.h\n+++ b/diff.h\n@@ -122,8 +122,6 @@ struct diff_options {\n \tconst char *stat_sep;\n \tlong xdl_opts;\n \n-\tint stat_width;\n-\tint stat_name_width;\n \tconst char *word_regex;\n \tenum diff_words_type word_diff;\n \n-- \n1.7.1\n"},{"id":"157569","messageId":"1291776263-16320-3-git-send-email-matthew.ruffalo@case.edu","threadId":"25860","inReplyTo":"1291776263-16320-1-git-send-email-matthew.ruffalo@case.edu","subject":"[PATCH 3/3] Add documentation for new diffstat config options","fromName":"","fromEmail":"mmr15@case.edu","sentAt":"2010-12-08T02:44:23Z","receivedAt":"2010-12-08T02:44:23Z","isPatch":true,"sender":{"key":"mmr15@case.edu","avatar":null},"body":"From: Matthew Ruffalo <matthew.ruffalo@case.edu>\n\nSigned-off-by: Matthew Ruffalo <matthew.ruffalo@case.edu>\n---\n Documentation/config.txt |    9 +++++++++\n 1 files changed, 9 insertions(+), 0 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex ad5eb5f..5cae0f4 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -862,6 +862,15 @@ diff.ignoreSubmodules::\n \tcommands such as 'git diff-files'. 'git checkout' also honors\n \tthis setting when reporting uncommitted changes.\n \n+diffstat.width::\n+\tControls the default width of 'git diff --stat' output. Can be\n+\toverridden with the command line option '--stat-width'.\n+\n+diffstat.namewidth::\n+\tControls the default width of the filenames in 'git diff --stat'\n+\toutput. Can be overridden with the command line option\n+\t'--stat-namewidth'.\n+\n diff.suppressBlankEmpty::\n \tA boolean to inhibit the standard behavior of printing a space\n \tbefore each empty output line. Defaults to false.\n-- \n1.7.1\n"},{"id":"157671","messageId":"7vwrnjh4ow.fsf@alter.siamese.dyndns.org","threadId":"25860","inReplyTo":"1291776263-16320-2-git-send-email-matthew.ruffalo@case.edu","subject":"Re: [PATCH 2/3] diffstat: Use new diffstat config values","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-12-09T05:54:07Z","receivedAt":"2010-12-09T05:54:07Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"mmr15@case.edu writes:\n\n> This required removing the diffstat options from 'struct diff_options'\n> and adding these values as static ints in diff.c. This preserves the\n> style of \"config options are static ints, command-line options are\n> diff_options members\". stat_opt now directly sets the global options.\n\nIt is not that I do not trust/believe it, but I am very unhappy with the\nabove \"This required\".\n\nThe diff callchain was designed to be a highly reusable library and has\nbeen kept callable multiple times with different settings in a single\nprogram by passing different \"struct diff_options\".  The above sounds like\na rather huge regression.\n\nAren't there any way to avoid this?  Why do these two options need to be\nany different from other variables (e.g. a_prefix, context) that can be\nset from the config and can be overridden by the command line options\nwhile having a built-in fallback default values?\n\nIn general, the callflow of each git subcommand looks like this:\n\n (1) find $GIT_DIR;\n (2) read $GIT_DIR/config and friends;\n (3) parse command line options;\n (4) decide what the user asked us to do and do it.\n\nI would imagine that the following should do what you want:\n\n * declare two static int variables, stat_name_width_default and\n   stat_width_default, that are initialized to 80/50 at compile time;\n\n * add code to git_diff_ui_config() to update these two *_default\n   variables in step (2) above;\n\n * add code to diff_setup() to initialize opt->stat_name_width and\n   opt->stat_width from these two *_default variables;\n\n * add code to diff_opt_parse() to update opt->stat_name_width and\n   opt->stat_width from the command line parameters.\n\nThen follow cmd_diff() in diff.c to make sure the above is sufficient.\nObserve that:\n\n - The first thing cmd_diff() does is to read the config;\n - then init_revisions() will call diff_setup();\n - then setup_revisions() will call into diff_opt_parse().\n"}]}