git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] Implement parsing for new core.whitespace.* options.
@ 2007-11-02 13:34 David Symonds
  2007-11-02 13:34 ` [PATCH 2/3] Act on WS_WARN for ws_mode_space_before_tab David Symonds
  2007-11-02 15:25 ` [PATCH 1/3] Implement parsing for new core.whitespace.* options Baz
  0 siblings, 2 replies; 5+ messages in thread
From: David Symonds @ 2007-11-02 13:34 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Andreas Ericsson, David Symonds

Each of the new core.whitespace.* options (enumerated below) can be set to one
of:
	* okay (default): Whitespace of this type is okay
	* warn: Whitespace of this type should be warned about
	* error: Whitespace of this type should raise an error
	* autofix: Whitespace of this type should be automatically fixed

The initial options are:
	* trailing: Whitespace at the end of a line
	* space-before-tab: SP HT sequence in the initial whitespace of a line
	* space-indent: At least 8 spaces in a row at the start of a line

Example usage:
	[core "whitespace"]
		trailing = autofix
		space-before-tab = error
		space-indent = warn

Signed-off-by: David Symonds <dsymonds@gmail.com>
---
 cache.h       |   16 ++++++++++++++++
 config.c      |   28 ++++++++++++++++++++++++++++
 environment.c |    3 +++
 3 files changed, 47 insertions(+), 0 deletions(-)

diff --git a/cache.h b/cache.h
index bfffa05..51e3982 100644
--- a/cache.h
+++ b/cache.h
@@ -602,4 +602,20 @@ extern int diff_auto_refresh_index;
 /* match-trees.c */
 void shift_tree(const unsigned char *, const unsigned char *, unsigned char *, int);
 
+/*
+ * whitespace rules.
+ * used by both diff and apply
+ */
+enum whitespace_mode {
+	WS_OKAY = 0,
+	WS_WARN,
+	WS_ERROR,
+	WS_AUTOFIX
+};
+extern enum whitespace_mode ws_mode_trailing;
+extern enum whitespace_mode ws_mode_space_before_tab;
+extern enum whitespace_mode ws_mode_space_indent;
+extern enum whitespace_mode git_config_whitespace_mode(const char *, const char *);
+
+
 #endif /* CACHE_H */
diff --git a/config.c b/config.c
index dc3148d..8e6f252 100644
--- a/config.c
+++ b/config.c
@@ -297,6 +297,19 @@ int git_config_bool(const char *name, const char *value)
 	return git_config_int(name, value) != 0;
 }
 
+enum whitespace_mode git_config_whitespace_mode(const char *name, const char *value)
+{
+	if (!strcasecmp(value, "okay"))
+		return WS_OKAY;
+	if (!strcasecmp(value, "warn"))
+		return WS_WARN;
+	if (!strcasecmp(value, "error"))
+		return WS_ERROR;
+	if (!strcasecmp(value, "autofix"))
+		return WS_AUTOFIX;
+	die("bad config value for '%s' in %s", name, config_file_name);
+}
+
 int git_default_config(const char *var, const char *value)
 {
 	/* This needs a better name */
@@ -431,6 +444,21 @@ int git_default_config(const char *var, const char *value)
 		return 0;
 	}
 
+	if (!strcmp(var, "core.whitespace.trailing")) {
+		ws_mode_trailing = git_config_whitespace_mode(var, value);
+		return 0;
+	}
+
+	if (!strcmp(var, "core.whitespace.space-before-tab")) {
+		ws_mode_space_before_tab = git_config_whitespace_mode(var, value);
+		return 0;
+	}
+
+	if (!strcmp(var, "core.whitespace.space-indent")) {
+		ws_mode_space_indent = git_config_whitespace_mode(var, value);
+		return 0;
+	}
+
 	/* Add other config variables here and to Documentation/config.txt. */
 	return 0;
 }
diff --git a/environment.c b/environment.c
index b5a6c69..71502fc 100644
--- a/environment.c
+++ b/environment.c
@@ -35,6 +35,9 @@ int pager_in_use;
 int pager_use_color = 1;
 char *editor_program;
 int auto_crlf = 0;	/* 1: both ways, -1: only when adding git objects */
+enum whitespace_mode ws_mode_trailing = WS_OKAY;
+enum whitespace_mode ws_mode_space_before_tab = WS_OKAY;
+enum whitespace_mode ws_mode_space_indent = WS_OKAY;
 
 /* This is set by setup_git_dir_gently() and/or git_default_config() */
 char *git_work_tree_cfg;
-- 
1.5.3.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] Act on WS_WARN for ws_mode_space_before_tab.
  2007-11-02 13:34 [PATCH 1/3] Implement parsing for new core.whitespace.* options David Symonds
@ 2007-11-02 13:34 ` David Symonds
  2007-11-02 13:34   ` [PATCH 3/3] Act on WS_WARN for ws_mode_trailing David Symonds
  2007-11-02 15:25 ` [PATCH 1/3] Implement parsing for new core.whitespace.* options Baz
  1 sibling, 1 reply; 5+ messages in thread
From: David Symonds @ 2007-11-02 13:34 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Andreas Ericsson, David Symonds

Signed-off-by: David Symonds <dsymonds@gmail.com>
---
 diff.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/diff.c b/diff.c
index a6aaaf7..6f9b624 100644
--- a/diff.c
+++ b/diff.c
@@ -508,8 +508,12 @@ static void emit_line_with_ws(int nparents,
 	for (i = col0; i < len; i++) {
 		if (line[i] == '\t') {
 			last_tab_in_indent = i;
-			if (0 <= last_space_in_indent)
-				need_highlight_leading_space = 1;
+			if ((ws_mode_space_before_tab != WS_OKAY) &&
+			    (0 <= last_space_in_indent)) {
+				if (ws_mode_space_before_tab == WS_WARN)
+					need_highlight_leading_space = 1;
+				/* TODO: handle WS_ERROR and WS_AUTOFIX */
+			}
 		}
 		else if (line[i] == ' ')
 			last_space_in_indent = i;
-- 
1.5.3.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] Act on WS_WARN for ws_mode_trailing.
  2007-11-02 13:34 ` [PATCH 2/3] Act on WS_WARN for ws_mode_space_before_tab David Symonds
@ 2007-11-02 13:34   ` David Symonds
  2007-11-02 15:07     ` David Symonds
  0 siblings, 1 reply; 5+ messages in thread
From: David Symonds @ 2007-11-02 13:34 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Andreas Ericsson, David Symonds

Signed-off-by: David Symonds <dsymonds@gmail.com>
---
 diff.c |   21 +++++++++++++--------
 1 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/diff.c b/diff.c
index 6f9b624..ebcc0f3 100644
--- a/diff.c
+++ b/diff.c
@@ -544,17 +544,22 @@ static void emit_line_with_ws(int nparents,
 	tail = len - 1;
 	if (line[tail] == '\n' && i < tail)
 		tail--;
-	while (i < tail) {
-		if (!isspace(line[tail]))
-			break;
-		tail--;
+	if (ws_mode_trailing != WS_OKAY) {
+		while (i < tail) {
+			if (!isspace(line[tail]))
+				break;
+			tail--;
+		}
 	}
 	if ((i < tail && line[tail + 1] != '\n')) {
 		/* This has whitespace between tail+1..len */
-		fputs(set, stdout);
-		fwrite(line + i, tail - i + 1, 1, stdout);
-		fputs(reset, stdout);
-		emit_line(ws, reset, line + tail + 1, len - tail - 1);
+		if (ws_mode_trailing == WS_WARN) {
+			fputs(set, stdout);
+			fwrite(line + i, tail - i + 1, 1, stdout);
+			fputs(reset, stdout);
+			emit_line(ws, reset, line + tail + 1, len - tail - 1);
+		}
+		/* TODO: handle WS_ERROR and WS_AUTOFIX */
 	}
 	else
 		emit_line(set, reset, line + i, len - i);
-- 
1.5.3.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 3/3] Act on WS_WARN for ws_mode_trailing.
  2007-11-02 13:34   ` [PATCH 3/3] Act on WS_WARN for ws_mode_trailing David Symonds
@ 2007-11-02 15:07     ` David Symonds
  0 siblings, 0 replies; 5+ messages in thread
From: David Symonds @ 2007-11-02 15:07 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Andreas Ericsson, David Symonds

On 11/3/07, David Symonds <dsymonds@gmail.com> wrote:
> Signed-off-by: David Symonds <dsymonds@gmail.com>
> ---
>  diff.c |   21 +++++++++++++--------
>  1 files changed, 13 insertions(+), 8 deletions(-)

Silly me; I somehow forgot I was only in diff.c. I'll fix and repost the series.


Dave.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/3] Implement parsing for new core.whitespace.* options.
  2007-11-02 13:34 [PATCH 1/3] Implement parsing for new core.whitespace.* options David Symonds
  2007-11-02 13:34 ` [PATCH 2/3] Act on WS_WARN for ws_mode_space_before_tab David Symonds
@ 2007-11-02 15:25 ` Baz
  1 sibling, 0 replies; 5+ messages in thread
From: Baz @ 2007-11-02 15:25 UTC (permalink / raw)
  To: David Symonds; +Cc: git, Junio C Hamano, Andreas Ericsson

On 02/11/2007, David Symonds <dsymonds@gmail.com> wrote:
> Each of the new core.whitespace.* options (enumerated below) can be set to one
> of:
>         * okay (default): Whitespace of this type is okay
>         * warn: Whitespace of this type should be warned about
>         * error: Whitespace of this type should raise an error
>         * autofix: Whitespace of this type should be automatically fixed

Sorry, this is a bit bikesheddy, but shouldn't that be 'fix' rather
than autofix? Otherwise you might want to rename the others
'autowarn', 'autookay' etc... since the computer does them
automatically too.

Cheers,
Baz

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-11-02 15:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-02 13:34 [PATCH 1/3] Implement parsing for new core.whitespace.* options David Symonds
2007-11-02 13:34 ` [PATCH 2/3] Act on WS_WARN for ws_mode_space_before_tab David Symonds
2007-11-02 13:34   ` [PATCH 3/3] Act on WS_WARN for ws_mode_trailing David Symonds
2007-11-02 15:07     ` David Symonds
2007-11-02 15:25 ` [PATCH 1/3] Implement parsing for new core.whitespace.* options Baz

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).