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

Re: [PATCH] get_oid: handle NULL repo->index

From
Duy Nguyen <pclouds@gmail.com>
Date
May 15, 2019, 01:24 UTC
Message-ID
<CACsJy8AvsyOz2G1zjRjpKYVZ0DLKj02-v=hXJHS0BRHnxoeWAw@mail.gmail.com>
In-Reply-To
<20190514135455.GA17927@sigill.intra.peff.net>
On Tue, May 14, 2019 at 8:54 PM Jeff King <peff@peff.net> wrote:
Show 11 quoted lines
> diff --git a/sha1-name.c b/sha1-name.c
> index 775a73d8ad..455e9fb1ea 100644
> --- a/sha1-name.c
> +++ b/sha1-name.c
> @@ -1837,7 +1837,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
>                 if (flags & GET_OID_RECORD_PATH)
>                         oc->path = xstrdup(cp);
>
> -               if (!repo->index->cache)
> +               if (!repo->index || !repo->index->cache)
>                         repo_read_index(repo);

We could even drop the "if" and call repo_read_index() unconditionally. If the index is already read, it will be no-op (forcing a reread has always been discard_index(); read_index();)

Thanks for catching this by the way. I'll need to go through all the_index conversion to see if I left similar traps like this.

-- 
Duy
Previous: Eric WongNext: Jeff King
Message 7 of 16 in “new segfault in master (6a6c0f10a70a6eb1)”
  1. Eric WongMay 11, 2019
  2. Jeff KingMay 11, 2019
  3. Jeff KingMay 11, 2019
  4. Duy NguyenMay 12, 2019
  5. get_oid: handle NULL repo->indexJeff King, May 14, 2019
  6. Eric WongMay 14, 2019
  7. Duy NguyenMay 15, 2019
  8. Jeff KingMay 15, 2019
  9. Junio C HamanoMay 15, 2019
  10. Duy NguyenMay 15, 2019
  11. Junio C HamanoMay 16, 2019
  12. repository.c: always allocate 'index' at repo init timeNguyễn Thái Ngọc Duy, May 19, 2019
  13. Jeff KingMay 20, 2019
  14. Duy NguyenMay 21, 2019
  15. Jeff KingMay 21, 2019
  16. Junio C HamanoMay 28, 2019

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.