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, 21:47 UTC
Message-ID
<20171206214722.GA118027@google.com>
In-Reply-To
<CAGZ79kbvkopatFZi64Hxoa=wX6CJxJw6V+9RnQqrx6gTBL-78w@mail.gmail.com>
On 12/05, Stefan Beller wrote:
Show 46 quoted lines
> On Tue, Dec 5, 2017 at 2: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.
> >
> > Reported-by: Ben Boeckel <ben.boeckel@kitware.com>
> > Signed-off-by: Brandon Williams <bmwill@google.com>
> > ---
> >
> > This patch should fix the regression.  Let me know if it doesn't solve the
> > issue and I'll investigate some more.
> >
> 
> Thanks for fixing this bug! The commit message is helpful
> to understand how this bug could slip in!
> 
> > diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c
> > index d66499909..cfe7d0281 100644
> > --- 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();
> 
> 
> Although we do have very few unchecked calls to read_cache, I'd suggest
> to avoid spreading them. Most of the read_cache calls are guarded via:
> 
>     if (read_cache() < 0)
>         die(_("index file corrupt"));
Thanks, I'll add this change.
Show 9 quoted lines
> 
> I wonder if this hints at a bad API, and we'd rather have read_cache
> die() on errors, and the few callers that try to get out of trouble might
> need to use read_cache_gently() instead.
> (While this potentially large refactoring may be deferred, I'd ask for
> an if at least)
> 
> Thanks,
> Stefan
-- 
Brandon Williams
Previous: Stefan BellerNext: Eric Sunshine
Message 11 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.