git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Han-Wen Nienhuys <hanwen@google.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Han-Wen Nienhuys via GitGitGadget <gitgitgadget@gmail.com>,
	git <git@vger.kernel.org>, Han-Wen Nienhuys <hanwenn@gmail.com>
Subject: Re: [PATCH] init-db: init the_repository->hash_algo early from GIT_DEFAULT_HASH
Date: Thu, 3 Dec 2020 21:23:36 +0100	[thread overview]
Message-ID: <CAFQ2z_M3OO_nR6dhw6zzE0orYxcawP1DaJ_EOL5=+RUiZgCo8w@mail.gmail.com> (raw)
In-Reply-To: <xmqq5z5mruia.fsf@gitster.c.googlers.com>

On Tue, Dec 1, 2020 at 6:00 AM Junio C Hamano <gitster@pobox.com> wrote:
>
> "Han-Wen Nienhuys via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
> > From: Han-Wen Nienhuys <hanwen@google.com>
> >
> > The reftable backend needs to know the hash algorithm for writing the
> > initialization hash table.
> >
> > The initial reftable contains a symref HEAD => "main" (or "master"), which is
> > agnostic to the size of hash value, but this is an exceptional circumstance, and
> > the reftable library does not cater for this exception. It insists that all
> > tables in the stack have a consistent format ID for the hash algorithm.
> >
> > Call set_repo_hash_algo directly after reading out GIT_DEFAULT_HASH.
>
> Seeing that there is no mention of the_repository in the entire
> init-db.c file,

it's not because it's hidden in the call to refs_init_db().
refs_init_db accesses the_repository global variable, because
get_main_ref_store() takes a repository (and not repository_format)
argument.

> Isn't it the matter of passing the hash
> taken from repo_fmt to the refs API to initialize that part of the
> repository, instead of relying on half-initialized state in
> the_repository?

The refstore is created in get_main_ref_store(). I can't add a
repository_format argument there, because it has a lot of call sites
where the repository_format isn't available.

If the_repository is only half-initialized at this point in init_db(),
then why are we passing it in refs_init_db() just a couple of lines
further? At what point the_repository considered initialized?

> It's not like only the hash_algo member is yet to
> be prepared in the_repository instance at that point in the code.
> Most of the members are, except for a very few fields initialized by
> initialize_the_repository(), not filled in the codepath, no?
>
> So, this might have been the most convenient way to pass hash_algo
> down but the patch does not convince me that it is the best way.

I'm a bit at a loss here; I never learned how to cleanly work with so
many global variables, so I'm happy to take your suggestion.

-- 
Han-Wen Nienhuys - Google Munich
I work 80%. Don't expect answers from me on Fridays.
--

Google Germany GmbH, Erika-Mann-Strasse 33, 80636 Munich

Registergericht und -nummer: Hamburg, HRB 86891

Sitz der Gesellschaft: Hamburg

Geschäftsführer: Paul Manicle, Halimah DeLaine Prado

  reply	other threads:[~2020-12-03 20:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-26 19:39 [PATCH] init-db: init the_repository->hash_algo early from GIT_DEFAULT_HASH Han-Wen Nienhuys via GitGitGadget
2020-12-01  4:59 ` Junio C Hamano
2020-12-03 20:23   ` Han-Wen Nienhuys [this message]
2020-12-03 23:25     ` Junio C Hamano
2020-12-07 11:52       ` Han-Wen Nienhuys
2020-12-07 19:31         ` Junio C Hamano

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='CAFQ2z_M3OO_nR6dhw6zzE0orYxcawP1DaJ_EOL5=+RUiZgCo8w@mail.gmail.com' \
    --to=hanwen@google.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=gitster@pobox.com \
    --cc=hanwenn@gmail.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).