From: Stefan Beller <sbeller@google.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: "git@vger.kernel.org" <git@vger.kernel.org>
Subject: Re: [PATCH 1/4] document index_name_pos
Date: Wed, 18 Jan 2017 14:02:15 -0800 [thread overview]
Message-ID: <CAGZ79kbOEk9o=CsHcF876D+u1J+vYa64aEYWs_NdLSJmy-7TOQ@mail.gmail.com> (raw)
In-Reply-To: <xmqqk29s3wg0.fsf@gitster.mtv.corp.google.com>
On Wed, Jan 18, 2017 at 1:11 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Stefan Beller <sbeller@google.com> writes:
>
>> 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
>> + */
Oh, I see. With this property in mind, we know that
when using index_name_pos for sorting, the stages for a
given path are ordered correctly (in ascending order,
0 comes before 1, which comes before 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?
yes, it should be -4.
next prev parent reply other threads:[~2017-01-18 22:02 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-17 23:34 [PATCH 0/4] start documenting core functions Stefan Beller
2017-01-17 23:35 ` [PATCH 1/4] document index_name_pos Stefan Beller
2017-01-18 21:11 ` Junio C Hamano
2017-01-18 22:02 ` Stefan Beller [this message]
2017-01-17 23:35 ` [PATCH 2/4] remove_index_entry_at: move documentation to cache.h Stefan Beller
2017-01-18 21:16 ` Junio C Hamano
2017-01-18 22:06 ` Stefan Beller
2017-01-17 23:35 ` [PATCH 3/4] document add_[file_]to_index Stefan Beller
2017-01-18 21:22 ` Junio C Hamano
2017-01-18 22:09 ` Stefan Beller
2017-01-17 23:35 ` [PATCH 4/4] documentation: retire unfinished documentation Stefan Beller
2017-01-18 21:23 ` Junio C Hamano
2017-01-18 23:21 ` [PATCHv2 0/4] start documenting core functions Stefan Beller
2017-01-18 23:21 ` [PATCHv2 1/4] cache.h: document index_name_pos Stefan Beller
2017-01-19 3:18 ` [PATCHv3 0/4] start documenting core functions Stefan Beller
2017-01-19 3:18 ` [PATCHv3 1/4] cache.h: document index_name_pos Stefan Beller
2017-01-19 20:17 ` Junio C Hamano
2017-01-19 3:18 ` [PATCHv3 2/4] cache.h: document remove_index_entry_at Stefan Beller
2017-01-19 3:18 ` [PATCHv3 3/4] cache.h: document add_[file_]to_index Stefan Beller
2017-01-19 3:18 ` [PATCHv3 4/4] documentation: retire unfinished documentation Stefan Beller
2017-01-18 23:21 ` [PATCHv2 2/4] cache.h: document remove_index_entry_at Stefan Beller
2017-01-18 23:21 ` [PATCHv2 3/4] cache.h: document add_[file_]to_index Stefan Beller
2017-01-19 0:00 ` Brandon Williams
2017-01-19 0:08 ` Stefan Beller
2017-01-18 23:21 ` [PATCHv2 4/4] documentation: retire unfinished documentation Stefan Beller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAGZ79kbOEk9o=CsHcF876D+u1J+vYa64aEYWs_NdLSJmy-7TOQ@mail.gmail.com' \
--to=sbeller@google.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).