From: Junio C Hamano <gitster@pobox.com>
To: Wincent Colaiuta <win@wincent.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 2/4] Extract and improve whitespace check from "git apply"
Date: Wed, 12 Dec 2007 11:39:59 -0800 [thread overview]
Message-ID: <7vsl277ldc.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <1197476582-18956-3-git-send-email-win@wincent.com> (Wincent Colaiuta's message of "Wed, 12 Dec 2007 17:23:00 +0100")
Wincent Colaiuta <win@wincent.com> writes:
> diff --git a/ws.c b/ws.c
> index 52c10ca..884d373 100644
> --- a/ws.c
> +++ b/ws.c
> +unsigned check_whitespace(const char *line, int len, unsigned ws_rule)
> +{
> + ...
> + if (ws_rule & WS_TRAILING_SPACE) {
> + /* Lines start with "+" or "-" so length is at least 1 */
> + if (line[len - 1] == '\n') {
> + if (isspace(line[len - 2]))
> + result |= WS_TRAILING_SPACE;
> + }
I like the direction, but I think it would make much more sense if you
make check_whitespace() not about "a line in a patch that adds a line",
but about "here is a line, check if that is acceptable". IOW, make line
variable zero-based (and len = strlen(line)). The change would mean
that existing callers need to be modified to do something like:
if (line[0] == '+')
check_whitespace(line+1, len-1, ...);
but at the same time we could conceivably teach "git show" to show
whitespace errors in a blob, i.e. "git show --show-ws-error HEAD:ws.c"
by using such a check_whitespace().
The highlighting code may need similar changes. I was actually hoping
you would consolidate the logic there that decides which segment of the
string to highlight, and the logic in check_whitespace() to decide if
there is an error to begin with. Conceptually, if emit_line_with_ws()
decides there is nothing to highlight with DIFF_WHITESPACE color, that
means there is no whitespace error on the line and vice-versa, no?
next prev parent reply other threads:[~2007-12-12 19:40 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-12-12 16:22 [PATCH 0/4] Refactoring for apply and diff Wincent Colaiuta
2007-12-12 16:22 ` [PATCH 1/4] Fix "diff --check" whitespace detection Wincent Colaiuta
2007-12-12 16:23 ` [PATCH 2/4] Extract and improve whitespace check from "git apply" Wincent Colaiuta
2007-12-12 16:23 ` [PATCH 3/3] Make "diff --check" use shared whitespace functions Wincent Colaiuta
2007-12-12 16:23 ` [PATCH 4/4] Add tests for "git diff --check" with core.whitespace options Wincent Colaiuta
2007-12-12 19:39 ` Junio C Hamano [this message]
2007-12-12 22:50 ` [PATCH 2/4] Extract and improve whitespace check from "git apply" Wincent Colaiuta
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=7vsl277ldc.fsf@gitster.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=win@wincent.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 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).