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

Re: [PATCH] diff-tree: read the index so attribute checks work in bare repositories

From
BWBrandon Williams <bmwill@google.com>
Date
Dec 6, 2017, 22:00 UTC
Message-ID
<20171206220055.GB118027@google.com>
In-Reply-To
<CAPig+cS6zf3AvQVi7PZf=ignL-7JZKzYUyN9RoJSPZzL=Dj7FA@mail.gmail.com>
On 12/05, Eric Sunshine wrote:
Show 44 quoted lines
> On Tue, Dec 5, 2017 at 5:13 PM, Brandon Williams <bmwill@google.com> wrote:
> > A regression was introduced in 557a5998d (submodule: remove
> > gitmodules_config, 2017-08-03) to how attribute processing was handled
> > in bare repositories when running the diff-tree command.
> >
> > By default the attribute system will first try to read ".gitattribute"
> > files from the working tree and then falls back to reading them from the
> > index if there isn't a copy checked out in the worktree.  Prior to
> > 557a5998d the index was read as a side effect of the call to
> > 'gitmodules_config()' which ensured that the index was already populated
> > before entering the attribute subsystem.
> >
> > Since the call to 'gitmodules_config()' was removed the index is no
> > longer being read so when the attribute system tries to read from the
> > in-memory index it doesn't find any ".gitattribute" entries effectively
> > ignoring any configured attributes.
> >
> > Fix this by explicitly reading the index during the setup of diff-tree.
> 
> This commit message does a good job of explaining the issue, so
> someone who hasn't followed the thread (or has not followed it
> closely, like me) can understand the problem and solution. Thanks.
> 
> A few comments below...
> 
> > Reported-by: Ben Boeckel <ben.boeckel@kitware.com>
> > Signed-off-by: Brandon Williams <bmwill@google.com>
> > ---
> > diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c
> > @@ -110,6 +110,7 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
> >
> >         git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
> >         init_revisions(opt, prefix);
> > +       read_cache();
> 
> 557a5998d (submodule: remove gitmodules_config, 2017-08-03) touched a
> fair number of built-in commands. It's not clear from the current
> patch's commit message if diff-tree is the only command which
> regressed. Is it? Or are other commands also likely to have regressed?
> Perhaps the commit message could say something about this. For
> instance: "All other commands touched by 557a5998d have been audited
> and were found to be regression-free" or "Other commands may regress
> in the same way, but we will take a wait-and-see attitude and fix them
> as needed because <fill-in-reason>".

I don't know if any other commands have regressed. This was such an odd regression that I think it would be difficult to say for certain that there couldn't be others. I did go through the affected builtins to see if I could find anything. I came up empty handed so I think we should be ok.

Show 30 quoted lines
> 
> > diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh
> > @@ -636,6 +636,23 @@ test_expect_success 'check with space before tab in indent (diff-tree)' '
> > +test_expect_success 'check with ignored trailing whitespace attr (diff-tree)' '
> > +       test_when_finished "git reset --hard HEAD^" &&
> 
> A few style nits...
> 
> > +       # Create a whitespace error that should be ignored.
> 
> Comments in nearby tests are not capitalized and do not end with period.
> 
> > +       echo "* -whitespace" > ".gitattributes" &&
> 
> Please drop unnecessary quotes around the filename, as the extra noise
> makes it a bit harder to read. Also, lose space after redirection
> operator:
> 
>     echo "* -whitespace" >.gitattributes &&
> 
> > +       git add ".gitattributes" &&
> > +       echo "trailing space -> " > "trailing-space" &&
> 
> All the nearby tests use some variation of:
> 
>     echo "foo ();  " >x &&
> 
> which differs from the "trailing space ->" and filename
> 'trailing-space' used in this test. Lack of consistency makes this new
> test stick out like a sore thumb.

You're right, when writing the tests I didn't really consider the surrounding ones. I'll make the requested changes.

Show 10 quoted lines
> 
> > +       git add "trailing-space" &&
> > +       git commit -m "trailing space" &&
> > +
> > +       # With a worktree diff-tree ignores the whitespace error
> > +       git diff-tree --root --check HEAD &&
> > +
> > +       # Without a worktree diff-tree still ignores the whitespace error
> > +       git -C .git diff-tree --root --check HEAD
> > +'
-- 
Brandon Williams
Previous: Eric SunshineNext: Eric Sunshine
Message 13 of 15 in “gitattributes not read for diff-tree anymore in 2.15?”
  1. Ben BoeckelDec 4, 2017
  2. Brandon WilliamsDec 4, 2017
  3. Ben BoeckelDec 5, 2017
  4. Brandon WilliamsDec 5, 2017
  5. Ben BoeckelDec 5, 2017
  6. diff-tree: read the index so attribute checks work in bare repositoriesBrandon Williams, Dec 5, 2017
  7. Ben BoeckelDec 5, 2017
  8. Brandon WilliamsDec 5, 2017
  9. Junio C HamanoDec 5, 2017
  10. Stefan BellerDec 5, 2017
  11. Brandon WilliamsDec 6, 2017
  12. Eric SunshineDec 5, 2017
  13. Brandon WilliamsDec 6, 2017
  14. Eric SunshineDec 6, 2017
  15. diff-tree: read the index so attribute checks work in bare repositoriesBrandon Williams, Dec 6, 2017

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.