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

Re: [PATCH 0/4] grep: add more information to hunk separators

From
René Scharfe <rene.scharfe@lsrfire.ath.cx>
Date
Mar 26, 2012, 21:12 UTC
Message-ID
<4F70DBAC.4010609@lsrfire.ath.cx>
In-Reply-To
<7vobrjp7gu.fsf@alter.siamese.dyndns.org>
Am 26.03.2012 20:01, schrieb Junio C Hamano:
Show 26 quoted lines
> René Scharfe<rene.scharfe@lsrfire.ath.cx>  writes:
>
>> Looking at the above, I thought: We have unified diffs between two
>> files, we have combined diffs between more than two, what about
>> showing grep results as one-sided unified diffs?  ("What's the sound
>> of one hand clapping?" :-)
>>
>> 	--- a/git.c
>> 	@ -570,3 @ int main(int argc, const char **argv)
>> 	-		printf("usage: %s\n\n", git_usage_string);
>> 	:		list_common_cmds_help();
>> 	-		printf("\n%s\n", git_more_info_string);
>>
>> Pro: Generalization of an established format for showing interesting
>> parts of a file.  Less duplication of meta-information.  Markers that
>> tell us the kind of the shown lines are kept ("-" for context, ":" for
>> matches).  Machine parsable.
>>
>> Con: Why the "a/" prefix?  One-sided diffs, srsly?
>
> Cute, and I tend to agree that this is probably easier to read if you are
> used to reading unified diffs.
>
> Wouldn't it make more sense to replace your '-/:' with ' /=', so that at
> least ' ' SP retains the meaning of "this is shown merely to give you
> context, it is not a proper part of what you are looking for"?

Ah, good idea, the space makes for a less cluttered output. For completeness sake, I have to mention that the current grep output uses '-/:/=', however, for context/match/function line ("especially interesting context"). Even function lines that happen to fall within the --context are marked with an equal sign. That's not the case for unified diffs; they simply get shown as normal context.

> The reasoning behind '=' is that it is not either -/+ as we are not really
> comparing anything with anything.

Mapping the '-/:/=' of grep to ' /:/=' or ' /:/ ' might be easier to understand. However, seeing a line starting with a colon or an equal sign feels both strange, because they are normally used as binary operators. Normal grep output shows a filename or a line number before the separator, so it doesn't invoke that strange feeling.

Perhaps mapping to ' /!/ ' is better instead, similar to context diffs?
> It may also make sense to replace the
> per-file header line with "=== git.c" to be consistent.
A context diffs would have '*** git.c', but they are ugly IMHO, overall.

What we also could do: Produce a valid unified diff that would remove the matching lines if we were to apply it (or the --reverse, i.e. + instead of -). Then we wouldn't need to invent a special format, but the output would be a bit more verbose due to the added +++ lines.

I guess it's time to implement these options in order to try them out against real code. Won't have time to do so before the second half of the week, however.

René
Previous: Junio C HamanoNext: Junio C Hamano
Message 12 of 15 in “grep: add more information to hunk separators”
  1. 0/4 grep: add more information to hunk separatorsMark Lodato, Mar 26, 2012
  2. 1/4 grep doc: add --break / --heading / -W to synopsisMark Lodato, Mar 26, 2012
  3. 2/4 add tests for grep --heading with contextMark Lodato, Mar 26, 2012
  4. 3/4 grep: move code to print hunk markers after headingMark Lodato, Mar 26, 2012
  5. 4/4 grep: add --hunk-heading optionMark Lodato, Mar 26, 2012
  6. Junio C HamanoMar 26, 2012
  7. René ScharfeMar 26, 2012
  8. Junio C HamanoMar 26, 2012
  9. Bert WesargMar 26, 2012
  10. René ScharfeMar 26, 2012
  11. Junio C HamanoMar 26, 2012
  12. René ScharfeMar 26, 2012
  13. Junio C HamanoMar 26, 2012
  14. 5/4 move sane_truncate_line to utf8_truncate_lineMark Lodato, Mar 27, 2012
  15. 6/4 add grep.hunkHeadingFunction optionMark Lodato, Mar 27, 2012

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.