From: Linus Torvalds <torvalds@osdl.org>
To: Andrew Morton <akpm@osdl.org>
Cc: Junio C Hamano <junkio@cox.net>, git@vger.kernel.org
Subject: Re: the war on trailing whitespace
Date: Sun, 26 Feb 2006 09:29:00 -0800 (PST) [thread overview]
Message-ID: <Pine.LNX.4.64.0602260925170.22647@g5.osdl.org> (raw)
In-Reply-To: <20060225210712.29b30f59.akpm@osdl.org>
On Sat, 25 Feb 2006, Andrew Morton wrote:
>
> I'd suggest a) git will simply refuse to apply such a patch unless given a
> special `forcing' flag, b) even when thus forced, it will still warn and c)
> with a different flag, it will strip-then-apply, without generating a
> warning.
This doesn't do the "strip-then-apply" thing, but it allows you to make
git-apply generate a warning or error on extraneous whitespace.
Use --whitespace=warn to warn, and (surprise, surprise) --whitespace=error
to make it a fatal error to have whitespace at the end.
Totally untested, of course. But it compiles, so it must be fine.
HOWEVER! Note that this literally will check every single patch-line with
"+" at the beginning. Which means that if you fix a simple typo, and the
line had a space at the end before, and you didn't remove it, that's still
considered a "new line with whitespace at the end", even though obviously
the line wasn't really new.
I assume this is what you wanted, and there isn't really any sane
alternatives (you could make the warning activate only for _pure_
additions with no deletions at all in that hunk, but that sounds a bit
insane).
Linus
---
diff --git a/apply.c b/apply.c
index 244718c..e7b3dca 100644
--- a/apply.c
+++ b/apply.c
@@ -34,6 +34,12 @@ static int line_termination = '\n';
static const char apply_usage[] =
"git-apply [--stat] [--numstat] [--summary] [--check] [--index] [--apply] [--no-add] [--index-info] [--allow-binary-replacement] [-z] [-pNUM] <patch>...";
+static enum whitespace_eol {
+ nowarn,
+ warn_on_whitespace,
+ error_on_whitespace
+} new_whitespace = nowarn;
+
/*
* For "diff-stat" like behaviour, we keep track of the biggest change
* we've seen, and the longest filename. That allows us to do simple
@@ -815,6 +821,22 @@ static int parse_fragment(char *line, un
oldlines--;
break;
case '+':
+ /*
+ * We know len is at least two, since we have a '+' and
+ * we checked that the last character was a '\n' above
+ */
+ if (isspace(line[len-2])) {
+ switch (new_whitespace) {
+ case nowarn:
+ break;
+ case warn_on_whitespace:
+ new_whitespace = nowarn; /* Just once */
+ error("Added whitespace at end of line at line %d", linenr);
+ break;
+ case error_on_whitespace:
+ die("Added whitespace at end of line at line %d", linenr);
+ }
+ }
added++;
newlines--;
break;
@@ -1839,6 +1861,17 @@ int main(int argc, char **argv)
line_termination = 0;
continue;
}
+ if (!strncmp(arg, "--whitespace=", 13)) {
+ if (strcmp(arg+13, "warn")) {
+ new_whitespace = warn_on_whitespace;
+ continue;
+ }
+ if (strcmp(arg+13, "error")) {
+ new_whitespace = error_on_whitespace;
+ continue;
+ }
+ die("unrecognixed whitespace option '%s'", arg+13);
+ }
if (check_index && prefix_length < 0) {
prefix = setup_git_directory();
next prev parent reply other threads:[~2006-02-26 17:29 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-02-26 1:40 the war on trailing whitespace Andrew Morton
2006-02-26 3:38 ` Junio C Hamano
2006-02-26 5:07 ` Andrew Morton
2006-02-26 17:29 ` Linus Torvalds [this message]
2006-02-26 18:36 ` Andrew Morton
2006-02-26 20:16 ` Linus Torvalds
2006-02-26 20:26 ` Dave Jones
2006-02-26 20:31 ` Dave Jones
2006-02-27 2:50 ` MIke Galbraith
2006-02-27 9:07 ` Johannes Schindelin
2006-02-27 9:18 ` Andrew Morton
2006-02-27 23:18 ` Junio C Hamano
2006-02-27 23:29 ` Peter Williams
2006-02-28 0:10 ` Junio C Hamano
2006-02-27 23:37 ` Andrew Morton
2006-02-28 9:13 ` [PATCH] git-apply: war on whitespace -- finishing touches Junio C Hamano
2006-02-28 1:13 ` [PATCH 1/3] apply: squelch excessive errors and --whitespace=error-all Junio C Hamano
2006-02-28 1:13 ` [PATCH 2/3] apply --whitespace: configuration option Junio C Hamano
2006-02-28 9:16 ` Andreas Ericsson
2006-02-28 9:38 ` Junio C Hamano
2006-02-28 9:46 ` Andreas Ericsson
2006-02-28 1:13 ` [PATCH 3/3] git-apply --whitespace=nowarn Junio C Hamano
2006-02-28 3:26 ` A Large Angry SCM
2006-02-28 5:08 ` Junio C Hamano
2006-02-27 11:26 ` the war on trailing whitespace Adrien Beau
2006-02-27 11:41 ` Andreas Ericsson
2006-02-27 13:31 ` Uwe Zeisberger
2006-02-27 14:10 ` Andreas Ericsson
2006-02-27 14:31 ` Peter Hagervall
2006-02-27 14:40 ` Johannes Schindelin
2006-02-27 15:22 ` Randal L. Schwartz
2006-02-27 16:08 ` Josef Weidendorfer
2006-02-27 16:22 ` Adrien Beau
2006-02-27 16:37 ` Uwe Zeisberger
2006-02-27 16:41 ` Andreas Ericsson
2006-02-27 11:55 ` Johannes Schindelin
2006-02-27 0:45 ` Junio C Hamano
2006-02-27 2:14 ` [PATCH] apply --whitespace fixes and enhancements Junio C Hamano
2006-02-26 20:29 ` the war on trailing whitespace Junio C Hamano
2006-02-26 19:45 ` Sam Ravnborg
-- strict thread matches above, loose matches on Subject: below --
2006-02-28 1:07 linux
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=Pine.LNX.4.64.0602260925170.22647@g5.osdl.org \
--to=torvalds@osdl.org \
--cc=akpm@osdl.org \
--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).