Git development
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Karthik Nayak <karthik.188@gmail.com>
Cc: git@vger.kernel.org,
	Kristoffer Haugsbakk <kristofferhaugsbakk@fastmail.com>,
	Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH v2 3/8] setup: deduplicate logic to apply repository format
Date: Thu, 4 Jun 2026 08:08:33 +0200	[thread overview]
Message-ID: <aiEWYUzLHLCRfSKC@pks.im> (raw)
In-Reply-To: <CAOLa=ZSnDz1+C8y7ozFDdv68vqLFk-E+FsXhAnhwbm2D6a1Fng@mail.gmail.com>

On Wed, Jun 03, 2026 at 05:43:34AM -0700, Karthik Nayak wrote:
> Patrick Steinhardt <ps@pks.im> writes:
> > diff --git a/repository.c b/repository.c
> > index db57b8308b..58a13f7c4f 100644
> > --- a/repository.c
> > +++ b/repository.c
> > @@ -262,8 +262,8 @@ void repo_set_worktree(struct repository *repo, const char *path)
> >  	trace2_def_repo(repo);
> >  }
> >
> > -static int read_and_verify_repository_format(struct repository_format *format,
> > -					     const char *commondir)
> > +static int read_repository_format_from_commondir(struct repository_format *format,
> > +						 const char *commondir)
> 
> Nit: The commit explicitly calls out one rename, but this one wasn't.

Fair. I'll add a sentence or two about this.

> > @@ -272,11 +272,6 @@ static int read_and_verify_repository_format(struct repository_format *format,
> >  	read_repository_format(format, sb.buf);
> >  	strbuf_reset(&sb);
> >
> > -	if (verify_repository_format(format, &sb) < 0) {
> > -		warning("%s", sb.buf);
> > -		ret = -1;
> > -	}
> > -
> 
> So we remove this, so that the callee would independently verify the
> format I assume.
> 
> Edit: seems like we call verify_repository_format() within
> apply_repository_format() and the latter is called by the callee.
> 
> >  	strbuf_release(&sb);
> >  	return ret;
> >  }

Yeah. I guess this could be explained a bit better.

> > @@ -290,6 +285,8 @@ int repo_init(struct repository *repo,
> >  	      const char *worktree)
> >  {
> >  	struct repository_format format = REPOSITORY_FORMAT_INIT;
> > +	struct strbuf err = STRBUF_INIT;
> > +
> >  	memset(repo, 0, sizeof(*repo));
> >
> >  	initialize_repository(repo);
> > @@ -297,21 +294,13 @@ int repo_init(struct repository *repo,
> >  	if (repo_init_gitdir(repo, gitdir))
> >  		goto error;
> >
> > -	if (read_and_verify_repository_format(&format, repo->commondir))
> > +	if (read_repository_format_from_commondir(&format, repo->commondir))
> >  		goto error;
> >
> > -	repo_set_hash_algo(repo, format.hash_algo);
> > -	repo_set_compat_hash_algo(repo, format.compat_hash_algo);
> > -	repo_set_ref_storage_format(repo, format.ref_storage_format,
> > -				    format.ref_storage_payload);
> > -	repo->repository_format_worktree_config = format.worktree_config;
> > -	repo->repository_format_relative_worktrees = format.relative_worktrees;
> > -	repo->repository_format_precious_objects = format.precious_objects;
> > -	repo->repository_format_submodule_path_cfg = format.submodule_path_cfg;
> > -
> > -	/* take ownership of format.partial_clone */
> 
> I see that we now do an xstrdup for format.partial_clone, meaning we
> have our own memory segment to care about. Do we have to worry about
> format.partial_clone not being free'd?

No, `clear_repository_format()` already releases the memory for us. It
also did beforehand, but there we did the dance of just moving ownership
over. So we already had to free the string before.

> > diff --git a/setup.h b/setup.h
> > index 9409326fe4..5ed92f53fa 100644
> > --- a/setup.h
> > +++ b/setup.h
> > @@ -221,6 +221,15 @@ void clear_repository_format(struct repository_format *format);
> >  int verify_repository_format(const struct repository_format *format,
> >  			     struct strbuf *err);
> >
> > +/*
> > + * Apply the given repository format to the repo. This initializes extensions
> > + * and basic data structures required for normal operation. Returns 0 on
> > + * success, a negative error code otherwise.
> > + */
> 
> Nit: perhaps we should also mention that we verify the format?

Will do.

Patrick

  reply	other threads:[~2026-06-04  6:08 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-21  7:42 [PATCH 0/8] setup: centralize object database creation Patrick Steinhardt
2026-05-21  7:42 ` [PATCH 1/8] t0001: plug test gaps for git-init(1) with GIT_OBJECT_DIRECTORY Patrick Steinhardt
2026-05-21 16:49   ` Junio C Hamano
2026-05-21 17:51   ` Kristoffer Haugsbakk
2026-05-22  6:06     ` Patrick Steinhardt
2026-05-22  9:05       ` Kristoffer Haugsbakk
2026-05-21  7:42 ` [PATCH 2/8] setup: drop `setup_git_env()` Patrick Steinhardt
2026-05-21  7:42 ` [PATCH 3/8] setup: deduplicate logic to apply repository format Patrick Steinhardt
2026-05-21  7:42 ` [PATCH 4/8] repository: stop initializing the object database in `repo_set_gitdir()` Patrick Steinhardt
2026-05-21  7:42 ` [PATCH 5/8] setup: stop creating the object database in `setup_git_env()` Patrick Steinhardt
2026-05-21  7:42 ` [PATCH 6/8] setup: stop initializing object database without repository Patrick Steinhardt
2026-05-21  7:42 ` [PATCH 7/8] repository: stop reading loose object map twice on repo init Patrick Steinhardt
2026-05-21  7:42 ` [PATCH 8/8] setup: construct object database in `apply_repository_format()` Patrick Steinhardt
2026-05-21 17:59   ` Junio C Hamano
2026-05-22  6:03     ` Patrick Steinhardt
2026-05-22  0:32 ` [PATCH 0/8] setup: centralize object database creation Junio C Hamano
2026-05-22  6:03   ` Patrick Steinhardt
2026-05-26  5:56 ` [PATCH v2 " Patrick Steinhardt
2026-05-26  5:56   ` [PATCH v2 1/8] t0001: plug test gaps for git-init(1) with GIT_OBJECT_DIRECTORY Patrick Steinhardt
2026-06-03 12:22     ` Karthik Nayak
2026-05-26  5:56   ` [PATCH v2 2/8] setup: drop `setup_git_env()` Patrick Steinhardt
2026-05-26  5:56   ` [PATCH v2 3/8] setup: deduplicate logic to apply repository format Patrick Steinhardt
2026-06-03 12:43     ` Karthik Nayak
2026-06-04  6:08       ` Patrick Steinhardt [this message]
2026-05-26  5:56   ` [PATCH v2 4/8] repository: stop initializing the object database in `repo_set_gitdir()` Patrick Steinhardt
2026-06-03 12:49     ` Karthik Nayak
2026-06-04  6:08       ` Patrick Steinhardt
2026-05-26  5:57   ` [PATCH v2 5/8] setup: stop creating the object database in `setup_git_env()` Patrick Steinhardt
2026-06-03 12:57     ` Karthik Nayak
2026-05-26  5:57   ` [PATCH v2 6/8] setup: stop initializing object database without repository Patrick Steinhardt
2026-05-26  5:57   ` [PATCH v2 7/8] repository: stop reading loose object map twice on repo init Patrick Steinhardt
2026-05-26  5:57   ` [PATCH v2 8/8] setup: construct object database in `apply_repository_format()` Patrick Steinhardt
2026-06-03 13:04   ` [PATCH v2 0/8] setup: centralize object database creation Karthik Nayak
2026-06-04  6:08     ` Patrick Steinhardt
2026-06-04  7:46 ` [PATCH v3 " Patrick Steinhardt
2026-06-04  7:46   ` [PATCH v3 1/8] t0001: plug test gaps for git-init(1) with GIT_OBJECT_DIRECTORY Patrick Steinhardt
2026-06-04  7:46   ` [PATCH v3 2/8] setup: drop `setup_git_env()` Patrick Steinhardt
2026-06-04  7:46   ` [PATCH v3 3/8] setup: deduplicate logic to apply repository format Patrick Steinhardt
2026-06-04  7:46   ` [PATCH v3 4/8] repository: stop initializing the object database in `repo_set_gitdir()` Patrick Steinhardt
2026-06-04  7:46   ` [PATCH v3 5/8] setup: stop creating the object database in `setup_git_env()` Patrick Steinhardt
2026-06-04  7:46   ` [PATCH v3 6/8] setup: stop initializing object database without repository Patrick Steinhardt
2026-06-04  7:46   ` [PATCH v3 7/8] repository: stop reading loose object map twice on repo init Patrick Steinhardt
2026-06-04  7:46   ` [PATCH v3 8/8] setup: construct object database in `apply_repository_format()` Patrick Steinhardt

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aiEWYUzLHLCRfSKC@pks.im \
    --to=ps@pks.im \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=karthik.188@gmail.com \
    --cc=kristofferhaugsbakk@fastmail.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox