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

[RFH] index_name_exists() conversion

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 21, 2008, 09:07 UTC
Message-ID
<7vy79evfsn.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<7v7igywvnj.fsf@gitster.siamese.dyndns.org>

While (hopefully) I have your attention, I have another question about the recent optimization.

        commit cf558704fb68514a820e3666968967c900e0fd29
        Author: Linus Torvalds <torvalds@linux-foundation.org>
            Create pathname-based hash-table lookup into index
        diff --git a/dir.c b/dir.c
        index 1b9cc7a..6543105 100644
        --- a/dir.c
        +++ b/dir.c
        @@ -346,7 +346,7 @@ static struct dir_entry *dir_entry_new(cons...
         struct dir_entry *dir_add_name(struct dir_struct *dir, const c...
         {
        -	if (cache_name_pos(pathname, len) >= 0)
        +	if (cache_name_exists(pathname, len))
                        return NULL;
                ALLOC_GROW(dir->entries, dir->nr+1, dir->alloc);

This used to check if there is a stage#0 entry of that name in the index. But the name-hash based index look-up does not care about the stage as far as I can tell.

I haven't managed to come up with a failure case to demonstrate, but I think this can affect ls-files and clean, potentially in a bad way. "git add dir/" to resolve unmerged paths under dir/ somewhere should not be affected, as the codepath calls read_directory() before reading the cache (so the check will always say "Nope, we do not have such a path in the index yet").

I am not sure what the right solution would be. The motivation for the patch was to make "does this name exist in the index" and also "does this exist under an equivalent name" efficient, but it is asking a question that is not precise enough. Are we interested in such an entry at any stage, or only at stage#0, or what?

This could be related to the recent "status segfaults, bisected to cf558704" issue posted to the list. I dunno.

Previous: Junio C HamanoNext: Linus Torvalds
Message 2 of 10 in “[RFH] CE_REMOVE conversion”
  1. Junio C HamanoFeb 21, 2008
  2. [RFH] index_name_exists() conversionJunio C Hamano, Feb 21, 2008
  3. Linus TorvaldsFeb 21, 2008
  4. Johannes SchindelinFeb 21, 2008
  5. Linus TorvaldsFeb 21, 2008
  6. Linus TorvaldsFeb 21, 2008
  7. Junio C HamanoFeb 21, 2008
  8. Linus TorvaldsFeb 21, 2008
  9. Linus TorvaldsFeb 21, 2008
  10. Junio C HamanoFeb 21, 2008

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.