All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org, Jonathan Niedier <jrnieder@gmail.com>
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 06/16] Add core.column
Date: Wed,  9 Feb 2011 19:24:34 +0700	[thread overview]
Message-ID: <1297254284-3729-7-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1297254284-3729-1-git-send-email-pclouds@gmail.com>

FIXME: should probably go as color.* (i.e. column.*)

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 Documentation/config.txt |   11 ++++++++
 cache.h                  |    1 +
 column.c                 |   64 ++++++++++++++++++++++++++++++++++++++++++++++
 column.h                 |    1 +
 config.c                 |    4 +++
 environment.c            |    1 +
 6 files changed, 82 insertions(+), 0 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index c5e1835..45b5f5b 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -567,6 +567,17 @@ core.sparseCheckout::
 	Enable "sparse checkout" feature. See section "Sparse checkout" in
 	linkgit:git-read-tree[1] for more information.
 
+core.column::
+	Specify whether a command should output in columns. Only commands
+	that support `--column` will be affected by this. This variable
+	consists of a list of tokens separated by either spaces or commas:
+	`never` (do not output in columns), `auto` (output in columns if
+	the output is to a terminal), `always` (always output in
+	columns), `column` (fill column before row), `row` (fill row
+	before column), `dense` (unequal column width).
+	Setting `--column` or `--no-column` will override this
+	variable. This option defaults to never.
+
 add.ignore-errors::
 add.ignoreErrors::
 	Tells 'git add' to continue adding files when some files cannot be
diff --git a/cache.h b/cache.h
index d83d68c..b370657 100644
--- a/cache.h
+++ b/cache.h
@@ -559,6 +559,7 @@ extern int read_replace_refs;
 extern int fsync_object_files;
 extern int core_preload_index;
 extern int core_apply_sparse_checkout;
+extern int core_column;
 
 enum safe_crlf {
 	SAFE_CRLF_FALSE = 0,
diff --git a/column.c b/column.c
index e7facf4..615a698 100644
--- a/column.c
+++ b/column.c
@@ -206,3 +206,67 @@ void display_columns(const struct string_list *list, int mode, int width, int pa
 		die("BUG: invalid mode %d", MODE(mode));
 	}
 }
+
+static int parse_column_option(const char *arg, int len, int *mode)
+{
+	int negate = !strncmp(arg, "no", 2);
+
+	if (negate)
+		arg += 2;
+
+	if (!negate && !strncmp(arg, "column", 6)) {
+		*mode &= ~COL_MODE;
+		*mode |= COL_MODE_COLUMN;
+		return 0;
+	}
+	else if (!negate && !strncmp(arg, "row", 3)) {
+		*mode &= ~COL_MODE;
+		*mode |= COL_MODE_ROW;
+		return 0;
+	}
+	else if (!strncmp(arg, "dense", 5)) {
+		if (negate)
+			*mode &= ~COL_DENSE;
+		else
+			*mode |= COL_DENSE;
+		return 0;
+	}
+	else
+		return error("unsupported style '%s'", arg);
+	return 0;
+}
+
+int git_config_column(const char *var, const char *value, int stdout_is_tty)
+{
+	const char *sep = " ,";
+	int enable = 0;
+
+	while (*value) {
+		int len = strcspn(value, sep);
+		if (len) {
+			if (!strncasecmp(value, "never", 5))
+				enable = 0;
+			else if (!strncasecmp(value, "always", 6))
+				enable = 1;
+			else if (!strncasecmp(value, "auto", 4)) {
+				if (stdout_is_tty < 0)
+					stdout_is_tty = isatty(1);
+				if (stdout_is_tty || (pager_in_use() && pager_use_color))
+					enable = 1;
+			}
+			else if (!parse_column_option(value, len, &core_column))
+				;
+			else
+				return -1;
+
+			value += len;
+		}
+		value += strspn(value, sep);
+	}
+	if (!enable)
+		core_column = 0;
+	else if (MODE(core_column) == COL_MODE_PLAIN)
+		core_column |= COL_MODE_COLUMN;
+
+	return 0;
+}
diff --git a/column.h b/column.h
index cef354d..0749793 100644
--- a/column.h
+++ b/column.h
@@ -10,5 +10,6 @@
 
 extern int term_columns(void);
 extern void display_columns(const struct string_list *list, int mode, int width, int padding, const char *indent);
+extern int git_config_column(const char *var, const char *value, int stdout_is_tty);
 
 #endif
diff --git a/config.c b/config.c
index 625e051..68a432a 100644
--- a/config.c
+++ b/config.c
@@ -9,6 +9,7 @@
 #include "exec_cmd.h"
 #include "strbuf.h"
 #include "quote.h"
+#include "column.h"
 
 #define MAXNAME (256)
 
@@ -660,6 +661,9 @@ static int git_default_core_config(const char *var, const char *value)
 		return 0;
 	}
 
+	if (!strcmp(var, "core.column"))
+		return git_config_column(var, value, -1);
+
 	/* Add other config variables here and to Documentation/config.txt. */
 	return 0;
 }
diff --git a/environment.c b/environment.c
index 9564475..b420ea2 100644
--- a/environment.c
+++ b/environment.c
@@ -56,6 +56,7 @@ char *notes_ref_name;
 int grafts_replace_parents = 1;
 int core_apply_sparse_checkout;
 struct startup_info *startup_info;
+int core_column;
 
 /* Parallel index stat data preload? */
 int core_preload_index = 0;
-- 
1.7.2.2

  parent reply	other threads:[~2011-02-09 12:27 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-09 12:24 [PATCH 00/16] column output (v2) and git-ls Nguyễn Thái Ngọc Duy
2011-02-09 12:24 ` [PATCH 01/16] Move term_columns() to pager.c and save terminal width before pager Nguyễn Thái Ngọc Duy
2011-02-09 12:24 ` [PATCH 02/16] Add display_columns() to display in column layout Nguyễn Thái Ngọc Duy
2011-02-09 12:24 ` [PATCH 03/16] display_columns: add COL_MODE_{COLUMN,ROW} mode Nguyễn Thái Ngọc Duy
2011-02-09 12:24 ` [PATCH 04/16] display_columns: add COL_DENSE to do unequal column layout Nguyễn Thái Ngọc Duy
2011-02-09 12:24 ` [PATCH 05/16] Add test-column for testing " Nguyễn Thái Ngọc Duy
2011-02-09 12:24 ` Nguyễn Thái Ngọc Duy [this message]
2011-02-09 12:24 ` [PATCH 07/16] parseopt: OPT_COLUMN to set struct column_layout.mode Nguyễn Thái Ngọc Duy
2011-02-09 12:24 ` [PATCH 08/16] help: reuse display_columns() for help -a Nguyễn Thái Ngọc Duy
2011-02-09 12:24 ` [PATCH 09/16] tag: add --column Nguyễn Thái Ngọc Duy
2011-02-09 12:24 ` [PATCH 10/16] branch: " Nguyễn Thái Ngọc Duy
2011-02-09 12:24 ` [PATCH 11/16] Add ls command Nguyễn Thái Ngọc Duy
2011-02-09 12:24 ` [PATCH 12/16] ls: add --column Nguyễn Thái Ngọc Duy
2011-02-09 12:24 ` [PATCH 13/16] ls: add --recursive and turn default to non-recursive mode Nguyễn Thái Ngọc Duy
2011-02-09 12:24 ` [PATCH 14/16] ls: immitate UNIX ls output style Nguyễn Thái Ngọc Duy
2011-02-09 12:24 ` [PATCH 15/16] ls: strip common directory prefix from output Nguyễn Thái Ngọc Duy
2011-02-09 12:24 ` [PATCH 16/16] ls: color output Nguyễn Thái Ngọc Duy

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=1297254284-3729-7-git-send-email-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=jrnieder@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.