git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: mmr15@case.edu
To: git@vger.kernel.org
Cc: Matthew Ruffalo <matthew.ruffalo@case.edu>
Subject: [PATCH 2/3] diffstat: Use new diffstat config values
Date: Tue,  7 Dec 2010 21:44:22 -0500	[thread overview]
Message-ID: <1291776263-16320-2-git-send-email-matthew.ruffalo@case.edu> (raw)
In-Reply-To: <1291776263-16320-1-git-send-email-matthew.ruffalo@case.edu>

From: Matthew Ruffalo <matthew.ruffalo@case.edu>

Previously, the diffstat width could only be specified with the
command-line options '--width' and '--name-width'. This patch adds
support for config file options 'diffstat.width' and
'diffstat.namewidth'.

The diffstat width values are obtained in this order (of increasing
precedence):

 1. Compile-time defaults (80 width, 50 namewidth)
 2. Standard git config mechanism
 3. Command-line options

This required removing the diffstat options from 'struct diff_options'
and adding these values as static ints in diff.c. This preserves the
style of "config options are static ints, command-line options are
diff_options members". stat_opt now directly sets the global options.

Signed-off-by: Matthew Ruffalo <matthew.ruffalo@case.edu>
---
 diff.c |   24 ++++++++++++++++++------
 diff.h |    2 --
 2 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/diff.c b/diff.c
index 75938e4..d88c7f4 100644
--- a/diff.c
+++ b/diff.c
@@ -31,6 +31,8 @@ static const char *external_diff_cmd_cfg;
 int diff_auto_refresh_index = 1;
 static int diff_mnemonic_prefix;
 static int diff_no_prefix;
+static int diff_stat_width;
+static int diff_stat_name_width;
 static struct diff_options default_diff_options;
 
 static char diff_colors[][COLOR_MAXLEN] = {
@@ -148,6 +150,16 @@ int git_diff_basic_config(const char *var, const char *value, void *cb)
 	if (!prefixcmp(var, "submodule."))
 		return parse_submodule_config_option(var, value);
 
+	if (!strcmp(var, "diffstat.width")) {
+		diff_stat_width = git_config_int(var, value);
+		return 0;
+	}
+
+	if (!strcmp(var, "diffstat.namewidth")) {
+		diff_stat_name_width = git_config_int(var, value);
+		return 0;
+	}
+
 	return git_color_default_config(var, value, cb);
 }
 
@@ -1247,8 +1259,8 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
 		line_prefix = msg->buf;
 	}
 
-	width = options->stat_width ? options->stat_width : DIFF_STAT_DEFAULT_WIDTH;
-	name_width = options->stat_name_width ? options->stat_name_width : DIFF_STAT_DEFAULT_NAME_WIDTH;
+	width = diff_stat_width ? diff_stat_width : DIFF_STAT_DEFAULT_WIDTH;
+	name_width = diff_stat_name_width ? diff_stat_name_width : DIFF_STAT_DEFAULT_NAME_WIDTH;
 
 	/* Sanity: give at least 5 columns to the graph,
 	 * but leave at least 10 columns for the name.
@@ -3057,8 +3069,8 @@ static int stat_opt(struct diff_options *options, const char **av)
 {
 	const char *arg = av[0];
 	char *end;
-	int width = options->stat_width;
-	int name_width = options->stat_name_width;
+	int width = diff_stat_width;
+	int name_width = diff_stat_name_width;
 	int argcount = 1;
 
 	arg += strlen("--stat");
@@ -3098,8 +3110,8 @@ static int stat_opt(struct diff_options *options, const char **av)
 	if (*end)
 		return 0;
 	options->output_format |= DIFF_FORMAT_DIFFSTAT;
-	options->stat_name_width = name_width;
-	options->stat_width = width;
+	diff_stat_name_width = name_width;
+	diff_stat_width = width;
 	return argcount;
 }
 
diff --git a/diff.h b/diff.h
index 7b509c5..011f2ac 100644
--- a/diff.h
+++ b/diff.h
@@ -122,8 +122,6 @@ struct diff_options {
 	const char *stat_sep;
 	long xdl_opts;
 
-	int stat_width;
-	int stat_name_width;
 	const char *word_regex;
 	enum diff_words_type word_diff;
 
-- 
1.7.1

  reply	other threads:[~2010-12-08  2:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-28 23:51 [PATCH/RFC 2/3] diffstat: Use new diff.stat config values Matthew Ruffalo
2010-11-29 20:24 ` Junio C Hamano
2010-12-08  2:44   ` [PATCH 1/3] diffstat width: #define defaults in diff.h mmr15
2010-12-08  2:44     ` mmr15 [this message]
2010-12-09  5:54       ` [PATCH 2/3] diffstat: Use new diffstat config values Junio C Hamano
2010-12-08  2:44     ` [PATCH 3/3] Add documentation for new diffstat config options mmr15

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1291776263-16320-2-git-send-email-matthew.ruffalo@case.edu \
    --to=mmr15@case.edu \
    --cc=git@vger.kernel.org \
    --cc=matthew.ruffalo@case.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).