From: "J. Bruce Fields" <bfields@citi.umich.edu>
To: Junio C Hamano <junkio@cox.net>
Cc: git@vger.kernel.org, "J. Bruce Fields" <bfields@citi.umich.edu>
Subject: [PATCH 2/3] git-apply: complain about >=8 consecutive spaces in initial indent
Date: Sun, 16 Sep 2007 18:49:01 -0400 [thread overview]
Message-ID: <1189982942187-git-send-email-bfields@citi.umich.edu> (raw)
In-Reply-To: <11899829424173-git-send-email-bfields@citi.umich.edu>
Complain if we find 8 spaces or more in a row as part of the initial
whitespace on a line, and (with --whitespace=stripspace) replace such by
a tab.
Well, linux's checkpatch.pl complains about this sort of thing.
Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
---
builtin-apply.c | 34 +++++++++++++++++++++++++++-------
1 files changed, 27 insertions(+), 7 deletions(-)
diff --git a/builtin-apply.c b/builtin-apply.c
index 70359c1..fb63089 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -918,6 +918,7 @@ static void check_whitespace(const char *line, int len)
{
const char *err = "Adds trailing whitespace";
int seen_space = 0;
+ int consecutive_spaces = 0;
int i;
/*
@@ -944,6 +945,18 @@ static void check_whitespace(const char *line, int len)
else
break;
}
+
+ err = "Initial indent contains eight or more spaces in a row";
+ for (i = 1; i < len; i++) {
+ if (line[i] == ' ')
+ consecutive_spaces++;
+ else if (line[i] == '\t')
+ consecutive_spaces = 0;
+ else
+ break;
+ if (consecutive_spaces == 8)
+ goto error;
+ }
return;
error:
@@ -1607,9 +1620,10 @@ static int apply_line(char *output, const char *patch, int plen)
int i;
int add_nl_to_tail = 0;
int fixed = 0;
- int last_tab_in_indent = -1;
+ int after_indent = -1;
int last_space_in_indent = -1;
int need_fix_leading_space = 0;
+ int consecutive_spaces = 0;
char *buf;
if ((new_whitespace != strip_whitespace) || !whitespace_error ||
@@ -1630,23 +1644,27 @@ static int apply_line(char *output, const char *patch, int plen)
for (i = 1; i < plen; i++) {
char ch = patch[i];
if (ch == '\t') {
- last_tab_in_indent = i;
+ consecutive_spaces = 0;
if (0 <= last_space_in_indent)
need_fix_leading_space = 1;
}
- else if (ch == ' ')
+ else if (ch == ' ') {
+ consecutive_spaces++;
last_space_in_indent = i;
- else
+ } else
break;
+ if (consecutive_spaces == 8)
+ need_fix_leading_space = 1;
}
+ after_indent=i;
buf = output;
if (need_fix_leading_space) {
- int consecutive_spaces = 0;
+ consecutive_spaces = 0;
/* between patch[1..last_tab_in_indent] strip the
* funny spaces, updating them to tab as needed.
*/
- for (i = 1; i < last_tab_in_indent; i++, plen--) {
+ for (i = 1; i < after_indent; i++, plen--) {
char ch = patch[i];
if (ch != ' ') {
consecutive_spaces = 0;
@@ -1660,7 +1678,9 @@ static int apply_line(char *output, const char *patch, int plen)
}
}
fixed = 1;
- i = last_tab_in_indent;
+ i = after_indent;
+ i -= consecutive_spaces;
+ plen += consecutive_spaces;
}
else
i = 1;
--
1.5.3.1.42.gfe5df
next prev parent reply other threads:[~2007-09-16 22:49 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-16 22:48 whitespace-stripping J. Bruce Fields
2007-09-16 22:49 ` [PATCH 1/3] git-apply: fix whitespace stripping J. Bruce Fields
2007-09-16 22:49 ` J. Bruce Fields [this message]
2007-09-16 22:49 ` [PATCH 3/3] git-apply: add tests for stripping of leading and trailing whitespace J. Bruce Fields
2007-09-17 14:16 ` Krzysztof Halasa
2007-09-17 15:02 ` J. Bruce Fields
2007-09-17 23:44 ` Krzysztof Halasa
2007-09-18 0:53 ` J. Bruce Fields
2007-09-16 23:24 ` [PATCH 2/3] git-apply: complain about >=8 consecutive spaces in initial indent Martin Langhoff
2007-09-17 2:45 ` J. Bruce Fields
2007-09-17 0:24 ` Junio C Hamano
2007-09-17 2:44 ` J. Bruce Fields
2007-10-03 1:00 ` [PATCH] git-diff: " Junio C Hamano
2007-09-18 8:55 ` [PATCH 1/3] git-apply: fix whitespace stripping David Kastrup
2007-09-18 13:12 ` J. Bruce Fields
2007-09-18 14:18 ` David Kastrup
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1189982942187-git-send-email-bfields@citi.umich.edu \
--to=bfields@citi.umich.edu \
--cc=git@vger.kernel.org \
--cc=junkio@cox.net \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).