git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/4] Extract and improve whitespace check from "git apply"

From
Wincent Colaiuta <win@wincent.com>
Date
Dec 12, 2007, 22:50 UTC
Message-ID
<C0D2E543-2F35-455B-BE58-A0177D087A8D@wincent.com>
In-Reply-To
<7vsl277ldc.fsf@gitster.siamese.dyndns.org>
El 12/12/2007, a las 20:39, Junio C Hamano escribió:
Show 10 quoted lines
> 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, ...);

Yes, good point. As you say, it can then potentially be used for any line, not just lines in patches.

Show 11 quoted lines
> 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?

You're dead right. As I said in my original message, there is a *lot* of diff code and I basically only looked at enough of it to figure out what changes would be necessary to implement what I wanted. I hadn't looked inside emit_line_with_ws but it is an obvious site of duplication and as you point out there is definitely scope for more refactoring here; instead of doing the whitespace checking in three places (the three that I know about so far) we can do it in just one place. I'll see what I can cook up.

Cheers, Wincent

Previous: Junio C Hamano
Message 7 of 7 in “Refactoring for apply and diff”
  1. 0/4 Refactoring for apply and diffWincent Colaiuta, Dec 12, 2007
  2. 1/4 Fix "diff --check" whitespace detectionWincent Colaiuta, Dec 12, 2007
  3. 2/4 Extract and improve whitespace check from "git apply"Wincent Colaiuta, Dec 12, 2007
  4. 3/3 Make "diff --check" use shared whitespace functionsWincent Colaiuta, Dec 12, 2007
  5. 4/4 Add tests for "git diff --check" with core.whitespace optionsWincent Colaiuta, Dec 12, 2007
  6. Junio C HamanoDec 12, 2007
  7. Wincent ColaiutaDec 12, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.