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

Re: [PATCH 1/4] document index_name_pos

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 18, 2017, 21:11 UTC
Message-ID
<xmqqk29s3wg0.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20170117233503.27137-2-sbeller@google.com>
Stefan Beller <sbeller@google.com> writes:
Show 25 quoted lines
> Signed-off-by: Stefan Beller <sbeller@google.com>
> ---
>  cache.h | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
>
> diff --git a/cache.h b/cache.h
> index 1b67f078dd..270a0d0ea7 100644
> --- a/cache.h
> +++ b/cache.h
> @@ -575,7 +575,22 @@ extern int verify_path(const char *path);
>  extern int index_dir_exists(struct index_state *istate, const char *name, int namelen);
>  extern void adjust_dirname_case(struct index_state *istate, char *name);
>  extern struct cache_entry *index_file_exists(struct index_state *istate, const char *name, int namelen, int igncase);
> +
> +/*
> + * Searches for an entry defined by name and namelen in the given index.
> + * If the return value is positive (including 0) it is the position of an
> + * exact match. If the return value is negative, the negated value minus 1 is the
> + * position where the entry would be inserted.
> + * Example: In the current index we have the files b,d,e:
> + * index_name_pos(&index, "a", 1) -> -1
> + * index_name_pos(&index, "b", 1) ->  0
> + * index_name_pos(&index, "c", 1) -> -2
> + * index_name_pos(&index, "d", 1) ->  1
> + * index_name_pos(&index, "e", 1) ->  2

The above may not be wrong per-se, but it misses one important case. A conflicted entry in the index with the same name is considered to sort after the name this asks. If there are stage #1 and stage #3 entries for path "g" in addition to the above, i.e.

	[0] [1] [2] [3] [4]
	b#0 d#0 e#0 g#1 g#3
then 
	index_name_pos(&index, "g", 1) -> -3 - 1 = -4
        index_name_pos(&index, "h", 1) -> -5 - 1 = -6
> + * index_name_pos(&index, "f", 1) -> -3
> + */

Shouldn't this be -4? We originally have [0], [1], and [2] in the index, and "f" needs to go to [3], so -3 - 1 = -4, no?

Show 5 quoted lines
>  extern int index_name_pos(const struct index_state *, const char *name, int namelen);
> +
>  #define ADD_CACHE_OK_TO_ADD 1		/* Ok to add */
>  #define ADD_CACHE_OK_TO_REPLACE 2	/* Ok to replace file/directory */
>  #define ADD_CACHE_SKIP_DFCHECK 4	/* Ok to skip DF conflict checks */
Previous: Stefan BellerNext: Stefan Beller
Message 6 of 25 in “start documenting core functions”
  1. 0/4 start documenting core functionsStefan Beller, Jan 17, 2017
  2. 2/4 remove_index_entry_at: move documentation to cache.hStefan Beller, Jan 17, 2017
  3. Junio C HamanoJan 18, 2017
  4. Stefan BellerJan 18, 2017
  5. 1/4 document index_name_posStefan Beller, Jan 17, 2017
  6. Junio C HamanoJan 18, 2017
  7. Stefan BellerJan 18, 2017
  8. 3/4 document add_[file_]to_indexStefan Beller, Jan 17, 2017
  9. Junio C HamanoJan 18, 2017
  10. Stefan BellerJan 18, 2017
  11. 4/4 documentation: retire unfinished documentationStefan Beller, Jan 17, 2017
  12. Junio C HamanoJan 18, 2017
  13. 0/4 start documenting core functionsStefan Beller, Jan 18, 2017
  14. 2/4 cache.h: document remove_index_entry_atStefan Beller, Jan 18, 2017
  15. 3/4 cache.h: document add_[file_]to_indexStefan Beller, Jan 18, 2017
  16. Brandon WilliamsJan 19, 2017
  17. Stefan BellerJan 19, 2017
  18. 1/4 cache.h: document index_name_posStefan Beller, Jan 18, 2017
  19. 0/4 start documenting core functionsStefan Beller, Jan 19, 2017
  20. 1/4 cache.h: document index_name_posStefan Beller, Jan 19, 2017
  21. Junio C HamanoJan 19, 2017
  22. 2/4 cache.h: document remove_index_entry_atStefan Beller, Jan 19, 2017
  23. 4/4 documentation: retire unfinished documentationStefan Beller, Jan 19, 2017
  24. 3/4 cache.h: document add_[file_]to_indexStefan Beller, Jan 19, 2017
  25. 4/4 documentation: retire unfinished documentationStefan Beller, Jan 18, 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.