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

Re: BUG: git diff --name-only ignores --ignore-*

From
SHStefan Hoffmeister <stefan.hoffmeister@econos.de>
Date
Aug 26, 2021, 09:05 UTC
Message-ID
<CALhB_QN1k6=j8KQZcP6W3doiQ3BWZYFAKw9fRhVLz2ZRz9gm4g@mail.gmail.com>
A quick peek suggests options to tackle this:

a) by including XDF_IGNORE_BLANK_LINES as an option that also forces a content check b) adjusting the implementation in diff_flush to better take into account the specified --ignore-* flags

Now, looking closely at diff_flush it would seem as if all of the
command-line options
  --raw
  --name-only
  --name-status
might benefit from taking into account --ignore-*

So, in the end this is a matter intent and requirements - what should happen whenever a user provided --ignore*?

From my point of view, git diff --raw, --name-only, name-status all should honour --ignore-whitespace*, and all should also honour --ignore-blank-lines

Below please find a patch which shows the code areas affected; implementation quality is not acceptable as-is (logic distributed across the function), because I'd love to get some feedback on --raw and --name-status and the general approach.

*********************
diff --git a/diff.c b/diff.c
index a8113f1707..7b19cfa5f0 100644
--- a/diff.c
+++ b/diff.c
@@ -4645,11 +4645,13 @@ void diff_setup_done(struct diff_options *options)
/*
* Most of the time we can say "there are changes"
* only by checking if there are changed paths, but
- * --ignore-whitespace* options force us to look
- * inside contents.
+ * options
+ * --ignore-whitespace*
+ * --ignore-blank-lines
+ * force us to look inside contents.
*/
- if ((options->xdl_opts & XDF_WHITESPACE_FLAGS) ||
+ if ((options->xdl_opts & (XDF_WHITESPACE_FLAGS | XDF_IGNORE_BLANK_LINES)) ||
options->ignore_regex_nr)
options->flags.diff_from_contents = 1;
else
@@ -6408,10 +6410,10 @@ void diff_flush(struct diff_options *options)
if (!q->nr)
goto free_queue;
- if (output_format & (DIFF_FORMAT_RAW |
- DIFF_FORMAT_NAME |
+ if ((output_format & (DIFF_FORMAT_RAW |
DIFF_FORMAT_NAME_STATUS |
- DIFF_FORMAT_CHECKDIFF)) {
+ DIFF_FORMAT_CHECKDIFF)) ||
+ (output_format & DIFF_FORMAT_NAME && !options->flags.diff_from_contents)) {
for (i = 0; i < q->nr; i++) {
struct diff_filepair *p = q->queue[i];
if (check_pair_status(p))
@@ -6449,9 +6451,10 @@ void diff_flush(struct diff_options *options)
separator++;
}
- if (output_format & DIFF_FORMAT_NO_OUTPUT &&
+ if ((output_format & DIFF_FORMAT_NO_OUTPUT &&
options->flags.exit_with_status &&
- options->flags.diff_from_contents) {
+ options->flags.diff_from_contents)) ||
+ (output_format & DIFF_FORMAT_NAME && options->flags.diff_from_contents) {
/*
* run diff_flush_patch for the exit status. setting
* options->file to /dev/null should be safe, because we
Message 1 of 1 in “Re: BUG: git diff --name-only ignores --ignore-*”
  1. Stefan HoffmeisterAug 26, 2021

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.