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

Re: [PATCH 1/1] Add a helper to reverse index_pos_to_insert_pos()

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Oct 9, 2019, 08:15 UTC
Message-ID
<nycvar.QRO.7.76.6.1910091011520.46@tvgsbejvaqbjf.bet>
In-Reply-To
<75a9c7ce-893c-6341-ba8d-eed3ccba7ee3@kdbg.org>
Hi Hannes,
On Tue, 8 Oct 2019, Johannes Sixt wrote:
Show 20 quoted lines
> Am 08.10.19 um 08:48 schrieb Johannes Schindelin via GitGitGadget:
> > We have just introduced the helper `index_pos_to_insert_pos()` to help
> > avoiding underflows when returning `-1 - pos` for cases where we want to
> > return an insert position, using the ones' complement (as `int`).
>
> We do not want to have it for *all* cases, where we return -1 - pos, but
> only for those cases, where the result was actually encoded by
> index_pos_to_insert_pos(). That excludes all cases where the argument is
> derived from index_name_pos(), and leaves just...
>
> > --- a/rerere.c
> > +++ b/rerere.c
> > @@ -154,7 +154,7 @@ static struct rerere_dir *find_rerere_dir(const char *hex)
> >  		rr_dir->status = NULL;
> >  		rr_dir->status_nr = 0;
> >  		rr_dir->status_alloc = 0;
> > -		pos = -1 - pos;
> > +		pos = insert_pos_to_index_pos(pos);
>
> ... this one...

This `pos` comes from that line (unfortunately not part of the diff context):

        pos = sha1_pos(hash, rerere_dir, rerere_dir_nr, rerere_dir_hash);
The `sha1_pos()` function was patched, as per Junio's suggestion, to...
        return index_pos_to_insert_pos(lo);
Show 16 quoted lines
>
> >
> >  		/* Make sure the array is big enough ... */
> >  		ALLOC_GROW(rerere_dir, rerere_dir_nr + 1, rerere_dir_alloc);
> > diff --git a/sha1-name.c b/sha1-name.c
> > index 49855ad24f..bee7ce39ee 100644
> > --- a/sha1-name.c
> > +++ b/sha1-name.c
> > @@ -98,7 +98,7 @@ static void find_short_object_filename(struct disambiguate_state *ds)
> >  		loose_objects = odb_loose_cache(odb, &ds->bin_pfx);
> >  		pos = oid_array_lookup(loose_objects, &ds->bin_pfx);
> >  		if (pos < 0)
> > -			pos = -1 - pos;
> > +			pos = insert_pos_to_index_pos(pos);
>
> ... and this one.

This `pos` comes from that `oid_array_lookup()` function that _is_ part of the diff context. What you don't see is the definition of that function:

	int oid_array_lookup(struct oid_array *array, const struct object_id *oid)
	{
		if (!array->sorted)
				oid_array_sort(array);
		return sha1_pos(oid->hash, array->oid, array->nr, sha1_access);
	}
There you go. `sha1_pos()` again.

So yes, both of these instances were changed to call that helper on purpose.

Ciao, Dscho

Show 7 quoted lines
>
> >  		while (!ds->ambiguous && pos < loose_objects->nr) {
> >  			const struct object_id *oid;
> >  			oid = loose_objects->oid + pos;
>
> -- Hannes
>
Previous: Johannes Schindelin
Message 11 of 11 in “Fallout from azure-pipelines-msvc”
  1. 0/1 Fallout from azure-pipelines-msvcJohannes Schindelin via GitGitGadget, Oct 8, 2019
  2. 1/1 Add a helper to reverse index_pos_to_insert_pos()Johannes Schindelin via GitGitGadget, Oct 8, 2019
  3. Johannes SixtOct 8, 2019
  4. Junio C HamanoOct 9, 2019
  5. Johannes SixtOct 9, 2019
  6. Johannes SchindelinOct 9, 2019
  7. Junio C HamanoOct 9, 2019
  8. Johannes SchindelinOct 9, 2019
  9. Junio C HamanoOct 9, 2019
  10. Johannes SchindelinOct 9, 2019
  11. Johannes SchindelinOct 9, 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.