git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: Junio C Hamano <gitster@pobox.com>
Cc: Johannes Sixt <j6t@kdbg.org>,
	Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>,
	git@vger.kernel.org
Subject: Re: [PATCH 1/1] Add a helper to reverse index_pos_to_insert_pos()
Date: Wed, 9 Oct 2019 10:11:31 +0200 (CEST)	[thread overview]
Message-ID: <nycvar.QRO.7.76.6.1910091009370.46@tvgsbejvaqbjf.bet> (raw)
In-Reply-To: <xmqq5zkyn2a7.fsf@gitster-ct.c.googlers.com>

Hi Junio,


On Wed, 9 Oct 2019, Junio C Hamano wrote:

> Johannes Sixt <j6t@kdbg.org> writes:
>
> > 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().
>
> Yup, I agree with you that decoder should be fed only the data
> emitted by the encoder.
>
> But shouldn't the code that yielded 'pos' that later gets decoded by
> computing "-1 -pos" without using the encoding helper be corrected
> to use the encoder instead?  After all, the primary purpose of
> inventing the encoder was to catch the arith overflow, wasn't it?

That was the primary purpose of the encoder. And it is used in those
places where we want to encode _unsigned_ positions.

All of the calls to `insert_pos_to_index_pos()` that I introduced in
this here patch pass _signed_ position values, though. They cannot
overflow nor underflow because `-1 - <int>` is just the one-complement,
i.e. all bits are flipped.

Ciao,
Dscho

>
> > 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...
> >
> >>
> >>  		/* 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.
> >
> >>  		while (!ds->ambiguous && pos < loose_objects->nr) {
> >>  			const struct object_id *oid;
> >>  			oid = loose_objects->oid + pos;
> >
> > -- Hannes
>

  parent reply	other threads:[~2019-10-09  8:11 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-08  6:48 [PATCH 0/1] Fallout from azure-pipelines-msvc Johannes Schindelin via GitGitGadget
2019-10-08  6:48 ` [PATCH 1/1] Add a helper to reverse index_pos_to_insert_pos() Johannes Schindelin via GitGitGadget
2019-10-08 21:03   ` Johannes Sixt
2019-10-09  1:19     ` Junio C Hamano
2019-10-09  5:51       ` Johannes Sixt
2019-10-09  8:17         ` Johannes Schindelin
2019-10-09 11:44           ` Junio C Hamano
2019-10-09 11:59             ` Johannes Schindelin
2019-10-09 12:09               ` Junio C Hamano
2019-10-09  8:11       ` Johannes Schindelin [this message]
2019-10-09  8:15     ` Johannes Schindelin

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=nycvar.QRO.7.76.6.1910091009370.46@tvgsbejvaqbjf.bet \
    --to=johannes.schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=gitster@pobox.com \
    --cc=j6t@kdbg.org \
    /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).