{"thread":{"id":"10589","subject":"[PATCH 3/3] Act on WS_WARN for ws_mode_trailing.","startedAt":"2007-11-02T13:34:19Z","lastAt":"2007-11-02T15:25:53Z","messageCount":5,"participants":["David Symonds","Baz"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"57983","messageId":"11940104611948-git-send-email-dsymonds@gmail.com","threadId":"10589","inReplyTo":null,"subject":"[PATCH 1/3] Implement parsing for new core.whitespace.* options.","fromName":"David Symonds","fromEmail":"dsymonds@gmail.com","sentAt":"2007-11-02T13:34:19Z","receivedAt":"2007-11-02T13:34:19Z","isPatch":true,"sender":{"key":"dsymonds@gmail.com","avatar":"https://gravatar.com/avatar/b22f5051cbfc11836e36cf7a690e6cde4e225d835e13295ff98d15c7a9ee3c0f?d=mp&s=160"},"body":"Each of the new core.whitespace.* options (enumerated below) can be set to one\nof:\n\t* okay (default): Whitespace of this type is okay\n\t* warn: Whitespace of this type should be warned about\n\t* error: Whitespace of this type should raise an error\n\t* autofix: Whitespace of this type should be automatically fixed\n\nThe initial options are:\n\t* trailing: Whitespace at the end of a line\n\t* space-before-tab: SP HT sequence in the initial whitespace of a line\n\t* space-indent: At least 8 spaces in a row at the start of a line\n\nExample usage:\n\t[core \"whitespace\"]\n\t\ttrailing = autofix\n\t\tspace-before-tab = error\n\t\tspace-indent = warn\n\nSigned-off-by: David Symonds <dsymonds@gmail.com>\n---\n cache.h       |   16 ++++++++++++++++\n config.c      |   28 ++++++++++++++++++++++++++++\n environment.c |    3 +++\n 3 files changed, 47 insertions(+), 0 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex bfffa05..51e3982 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -602,4 +602,20 @@ extern int diff_auto_refresh_index;\n /* match-trees.c */\n void shift_tree(const unsigned char *, const unsigned char *, unsigned char *, int);\n \n+/*\n+ * whitespace rules.\n+ * used by both diff and apply\n+ */\n+enum whitespace_mode {\n+\tWS_OKAY = 0,\n+\tWS_WARN,\n+\tWS_ERROR,\n+\tWS_AUTOFIX\n+};\n+extern enum whitespace_mode ws_mode_trailing;\n+extern enum whitespace_mode ws_mode_space_before_tab;\n+extern enum whitespace_mode ws_mode_space_indent;\n+extern enum whitespace_mode git_config_whitespace_mode(const char *, const char *);\n+\n+\n #endif /* CACHE_H */\ndiff --git a/config.c b/config.c\nindex dc3148d..8e6f252 100644\n--- a/config.c\n+++ b/config.c\n@@ -297,6 +297,19 @@ int git_config_bool(const char *name, const char *value)\n \treturn git_config_int(name, value) != 0;\n }\n \n+enum whitespace_mode git_config_whitespace_mode(const char *name, const char *value)\n+{\n+\tif (!strcasecmp(value, \"okay\"))\n+\t\treturn WS_OKAY;\n+\tif (!strcasecmp(value, \"warn\"))\n+\t\treturn WS_WARN;\n+\tif (!strcasecmp(value, \"error\"))\n+\t\treturn WS_ERROR;\n+\tif (!strcasecmp(value, \"autofix\"))\n+\t\treturn WS_AUTOFIX;\n+\tdie(\"bad config value for '%s' in %s\", name, config_file_name);\n+}\n+\n int git_default_config(const char *var, const char *value)\n {\n \t/* This needs a better name */\n@@ -431,6 +444,21 @@ int git_default_config(const char *var, const char *value)\n \t\treturn 0;\n \t}\n \n+\tif (!strcmp(var, \"core.whitespace.trailing\")) {\n+\t\tws_mode_trailing = git_config_whitespace_mode(var, value);\n+\t\treturn 0;\n+\t}\n+\n+\tif (!strcmp(var, \"core.whitespace.space-before-tab\")) {\n+\t\tws_mode_space_before_tab = git_config_whitespace_mode(var, value);\n+\t\treturn 0;\n+\t}\n+\n+\tif (!strcmp(var, \"core.whitespace.space-indent\")) {\n+\t\tws_mode_space_indent = git_config_whitespace_mode(var, value);\n+\t\treturn 0;\n+\t}\n+\n \t/* Add other config variables here and to Documentation/config.txt. */\n \treturn 0;\n }\ndiff --git a/environment.c b/environment.c\nindex b5a6c69..71502fc 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -35,6 +35,9 @@ int pager_in_use;\n int pager_use_color = 1;\n char *editor_program;\n int auto_crlf = 0;\t/* 1: both ways, -1: only when adding git objects */\n+enum whitespace_mode ws_mode_trailing = WS_OKAY;\n+enum whitespace_mode ws_mode_space_before_tab = WS_OKAY;\n+enum whitespace_mode ws_mode_space_indent = WS_OKAY;\n \n /* This is set by setup_git_dir_gently() and/or git_default_config() */\n char *git_work_tree_cfg;\n-- \n1.5.3.1\n"},{"id":"57982","messageId":"11940104621856-git-send-email-dsymonds@gmail.com","threadId":"10589","inReplyTo":"11940104611948-git-send-email-dsymonds@gmail.com","subject":"[PATCH 2/3] Act on WS_WARN for ws_mode_space_before_tab.","fromName":"David Symonds","fromEmail":"dsymonds@gmail.com","sentAt":"2007-11-02T13:34:20Z","receivedAt":"2007-11-02T13:34:20Z","isPatch":true,"sender":{"key":"dsymonds@gmail.com","avatar":"https://gravatar.com/avatar/b22f5051cbfc11836e36cf7a690e6cde4e225d835e13295ff98d15c7a9ee3c0f?d=mp&s=160"},"body":"Signed-off-by: David Symonds <dsymonds@gmail.com>\n---\n diff.c |    8 ++++++--\n 1 files changed, 6 insertions(+), 2 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex a6aaaf7..6f9b624 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -508,8 +508,12 @@ static void emit_line_with_ws(int nparents,\n \tfor (i = col0; i < len; i++) {\n \t\tif (line[i] == '\\t') {\n \t\t\tlast_tab_in_indent = i;\n-\t\t\tif (0 <= last_space_in_indent)\n-\t\t\t\tneed_highlight_leading_space = 1;\n+\t\t\tif ((ws_mode_space_before_tab != WS_OKAY) &&\n+\t\t\t    (0 <= last_space_in_indent)) {\n+\t\t\t\tif (ws_mode_space_before_tab == WS_WARN)\n+\t\t\t\t\tneed_highlight_leading_space = 1;\n+\t\t\t\t/* TODO: handle WS_ERROR and WS_AUTOFIX */\n+\t\t\t}\n \t\t}\n \t\telse if (line[i] == ' ')\n \t\t\tlast_space_in_indent = i;\n-- \n1.5.3.1\n"},{"id":"57981","messageId":"1194010463982-git-send-email-dsymonds@gmail.com","threadId":"10589","inReplyTo":"11940104621856-git-send-email-dsymonds@gmail.com","subject":"[PATCH 3/3] Act on WS_WARN for ws_mode_trailing.","fromName":"David Symonds","fromEmail":"dsymonds@gmail.com","sentAt":"2007-11-02T13:34:21Z","receivedAt":"2007-11-02T13:34:21Z","isPatch":true,"sender":{"key":"dsymonds@gmail.com","avatar":"https://gravatar.com/avatar/b22f5051cbfc11836e36cf7a690e6cde4e225d835e13295ff98d15c7a9ee3c0f?d=mp&s=160"},"body":"Signed-off-by: David Symonds <dsymonds@gmail.com>\n---\n diff.c |   21 +++++++++++++--------\n 1 files changed, 13 insertions(+), 8 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 6f9b624..ebcc0f3 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -544,17 +544,22 @@ static void emit_line_with_ws(int nparents,\n \ttail = len - 1;\n \tif (line[tail] == '\\n' && i < tail)\n \t\ttail--;\n-\twhile (i < tail) {\n-\t\tif (!isspace(line[tail]))\n-\t\t\tbreak;\n-\t\ttail--;\n+\tif (ws_mode_trailing != WS_OKAY) {\n+\t\twhile (i < tail) {\n+\t\t\tif (!isspace(line[tail]))\n+\t\t\t\tbreak;\n+\t\t\ttail--;\n+\t\t}\n \t}\n \tif ((i < tail && line[tail + 1] != '\\n')) {\n \t\t/* This has whitespace between tail+1..len */\n-\t\tfputs(set, stdout);\n-\t\tfwrite(line + i, tail - i + 1, 1, stdout);\n-\t\tfputs(reset, stdout);\n-\t\temit_line(ws, reset, line + tail + 1, len - tail - 1);\n+\t\tif (ws_mode_trailing == WS_WARN) {\n+\t\t\tfputs(set, stdout);\n+\t\t\tfwrite(line + i, tail - i + 1, 1, stdout);\n+\t\t\tfputs(reset, stdout);\n+\t\t\temit_line(ws, reset, line + tail + 1, len - tail - 1);\n+\t\t}\n+\t\t/* TODO: handle WS_ERROR and WS_AUTOFIX */\n \t}\n \telse\n \t\temit_line(set, reset, line + i, len - i);\n-- \n1.5.3.1\n"},{"id":"57988","messageId":"ee77f5c20711020807i542071c0h70166cc0e32bd0ab@mail.gmail.com","threadId":"10589","inReplyTo":"1194010463982-git-send-email-dsymonds@gmail.com","subject":"Re: [PATCH 3/3] Act on WS_WARN for ws_mode_trailing.","fromName":"David Symonds","fromEmail":"dsymonds@gmail.com","sentAt":"2007-11-02T15:07:28Z","receivedAt":"2007-11-02T15:07:28Z","isPatch":true,"sender":{"key":"dsymonds@gmail.com","avatar":"https://gravatar.com/avatar/b22f5051cbfc11836e36cf7a690e6cde4e225d835e13295ff98d15c7a9ee3c0f?d=mp&s=160"},"body":"On 11/3/07, David Symonds <dsymonds@gmail.com> wrote:\n> Signed-off-by: David Symonds <dsymonds@gmail.com>\n> ---\n>  diff.c |   21 +++++++++++++--------\n>  1 files changed, 13 insertions(+), 8 deletions(-)\n\nSilly me; I somehow forgot I was only in diff.c. I'll fix and repost the series.\n\n\nDave.\n"},{"id":"57994","messageId":"2faad3050711020825y7d3ddc1et8d913e44d85ab989@mail.gmail.com","threadId":"10589","inReplyTo":"11940104611948-git-send-email-dsymonds@gmail.com","subject":"Re: [PATCH 1/3] Implement parsing for new core.whitespace.* options.","fromName":"Baz","fromEmail":"brian.ewins@gmail.com","sentAt":"2007-11-02T15:25:53Z","receivedAt":"2007-11-02T15:25:53Z","isPatch":true,"sender":{"key":"brian.ewins@gmail.com","avatar":"https://gravatar.com/avatar/9ac03d89105e50a7151e695a1b4b1228151064ec3ac380a73b74ab397796baf7?d=mp&s=160"},"body":"On 02/11/2007, David Symonds <dsymonds@gmail.com> wrote:\n> Each of the new core.whitespace.* options (enumerated below) can be set to one\n> of:\n>         * okay (default): Whitespace of this type is okay\n>         * warn: Whitespace of this type should be warned about\n>         * error: Whitespace of this type should raise an error\n>         * autofix: Whitespace of this type should be automatically fixed\n\nSorry, this is a bit bikesheddy, but shouldn't that be 'fix' rather\nthan autofix? Otherwise you might want to rename the others\n'autowarn', 'autookay' etc... since the computer does them\nautomatically too.\n\nCheers,\nBaz\n"}]}