git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Andrew Hlynskyi <ahlincq@gmail.com>, git@vger.kernel.org
Subject: Re: [BUG] `git gc` or `git pack-refs` wipes all notes for `git notes` command
Date: Fri, 6 Jan 2023 08:04:51 -0500	[thread overview]
Message-ID: <Y7gcczFWyTePVjlk@coredump.intra.peff.net> (raw)
In-Reply-To: <xmqqilhjsuo9.fsf@gitster.g>

On Fri, Jan 06, 2023 at 09:40:22PM +0900, Junio C Hamano wrote:

> > I don't think we have any fsck checks that the packed-refs file is in
> > sorted order. It might be reasonable to have them. Likewise, when
> > pack-refs rewrites the file, it should be able to cheaply double-check
> > that the input is sorted by comparing each entry against its previous.
> 
> True.  I would not mind a patch to make us do so in the code path
> where we rewrite the file and add "sorted" trait to the file.
> refs/packed-backend.c::sort_snapshot() seems to be already equipped
> to do this?

I think it may be a little trickier than that. Yes, sort_snapshot()
knows about sorting, but it only kicks in when the file isn't already
marked as sorted (and we sort on the fly so that the rest of the code
can use the same lookup routines).

And it's possible that we can just sort_snapshot() before writing, even
if the original claims to be sorted. But I'm not sure what performance
impact that might have on the normal case that everything is already in
good order. Maybe it's not a big deal; the write is already O(n), so
adding an O(n log n) might not be the end of the world.

But I was thinking more that write_with_updates() would, while iterating
through the existing entries, check that the values it gets from the
ref_iterator are indeed in sorted order. And if not, I think it needs to
actually bail, since we might already have written a partially-confused
result. And there "bail" may mean "write a warning to the user, abort
the current write, call sort_snapshot(), and then try again".

All of which is to say I don't think it's conceptually _too_ hard, but
it was not simple enough that I was comfortable dashing off a one-liner
and saying "probably something like this". ;)

> So we can conclude that this discussion thread has an
> incorrect Subject: and the symptom was caused by human error?

That's my read on it.

-Peff

      reply	other threads:[~2023-01-06 13:05 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-03  3:22 [BUG] `git gc` or `git pack-refs` wipes all notes for `git notes` command Andrew Hlynskyi
2023-01-03  9:04 ` Jeff King
2023-01-05 16:59   ` Andrew Hlynskyi
2023-01-06  8:57     ` Jeff King
2023-01-06 12:40       ` Junio C Hamano
2023-01-06 13:04         ` Jeff King [this message]

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=Y7gcczFWyTePVjlk@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=ahlincq@gmail.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).