From: Patrick Steinhardt <ps@pks.im>
To: git@vger.kernel.org
Cc: Sebastian Schuberth <sschuberth@gmail.com>
Subject: [PATCH 3/5] setup: merge configuration of repository formats
Date: Thu, 15 Aug 2024 10:00:03 +0200 [thread overview]
Message-ID: <16f52b75d8972343776adb269da305e7406ff385.1723708417.git.ps@pks.im> (raw)
In-Reply-To: <cover.1723708417.git.ps@pks.im>
The configuration of repository formats is split up across two functions
`validate_hash_algorithm()` and `validate_ref_storage_format()`. This is
fine as-is, but we are about to extend the logic to also read default
values from the config. With the logic split across two functions, we
would either have to pass in additional parameters read from the config,
or read the config multiple times. Both of these options feel a bit
unwieldy.
Merge the code into a new a new function `repository_format_configure()`
that is responsible for configuring the whole repository's format. Like
this, we can easily read the config in a single place, only.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
setup.c | 47 ++++++++++++++++++++---------------------------
1 file changed, 20 insertions(+), 27 deletions(-)
diff --git a/setup.c b/setup.c
index d458edcc02..5dfcdc99dd 100644
--- a/setup.c
+++ b/setup.c
@@ -2284,14 +2284,17 @@ static void separate_git_dir(const char *git_dir, const char *git_link)
write_file(git_link, "gitdir: %s", git_dir);
}
-static void validate_hash_algorithm(struct repository_format *repo_fmt, int hash)
+static void repository_format_configure(struct repository_format *repo_fmt,
+ int hash, enum ref_storage_format ref_format)
{
- const char *env = getenv(GIT_DEFAULT_HASH_ENVIRONMENT);
+ const char *env;
+
/*
* If we already have an initialized repo, don't allow the user to
* specify a different algorithm, as that could cause corruption.
* Otherwise, if the user has specified one on the command line, use it.
*/
+ env = getenv(GIT_DEFAULT_HASH_ENVIRONMENT);
if (repo_fmt->version >= 0 && hash != GIT_HASH_UNKNOWN && hash != repo_fmt->hash_algo)
die(_("attempt to reinitialize repository with different hash"));
else if (hash != GIT_HASH_UNKNOWN)
@@ -2302,25 +2305,22 @@ static void validate_hash_algorithm(struct repository_format *repo_fmt, int hash
die(_("unknown hash algorithm '%s'"), env);
repo_fmt->hash_algo = env_algo;
}
-}
-
-static void validate_ref_storage_format(struct repository_format *repo_fmt,
- enum ref_storage_format format)
-{
- const char *name = getenv("GIT_DEFAULT_REF_FORMAT");
+ repo_set_hash_algo(the_repository, repo_fmt->hash_algo);
+ env = getenv("GIT_DEFAULT_REF_FORMAT");
if (repo_fmt->version >= 0 &&
- format != REF_STORAGE_FORMAT_UNKNOWN &&
- format != repo_fmt->ref_storage_format) {
+ ref_format != REF_STORAGE_FORMAT_UNKNOWN &&
+ ref_format != repo_fmt->ref_storage_format) {
die(_("attempt to reinitialize repository with different reference storage format"));
- } else if (format != REF_STORAGE_FORMAT_UNKNOWN) {
- repo_fmt->ref_storage_format = format;
- } else if (name) {
- format = ref_storage_format_by_name(name);
- if (format == REF_STORAGE_FORMAT_UNKNOWN)
- die(_("unknown ref storage format '%s'"), name);
- repo_fmt->ref_storage_format = format;
+ } else if (ref_format != REF_STORAGE_FORMAT_UNKNOWN) {
+ repo_fmt->ref_storage_format = ref_format;
+ } else if (env) {
+ ref_format = ref_storage_format_by_name(env);
+ if (ref_format == REF_STORAGE_FORMAT_UNKNOWN)
+ die(_("unknown ref storage format '%s'"), env);
+ repo_fmt->ref_storage_format = ref_format;
}
+ repo_set_ref_storage_format(the_repository, repo_fmt->ref_storage_format);
}
int init_db(const char *git_dir, const char *real_git_dir,
@@ -2353,22 +2353,15 @@ int init_db(const char *git_dir, const char *real_git_dir,
}
startup_info->have_repository = 1;
- /* Check to see if the repository version is right.
+ /*
+ * Check to see if the repository version is right.
* Note that a newly created repository does not have
* config file, so this will not fail. What we are catching
* is an attempt to reinitialize new repository with an old tool.
*/
check_repository_format(&repo_fmt);
- validate_hash_algorithm(&repo_fmt, hash);
- validate_ref_storage_format(&repo_fmt, ref_storage_format);
-
- /*
- * Now that we have set up both the hash algorithm and the ref storage
- * format we can update the repository's settings accordingly.
- */
- repo_set_hash_algo(the_repository, repo_fmt.hash_algo);
- repo_set_ref_storage_format(the_repository, repo_fmt.ref_storage_format);
+ repository_format_configure(&repo_fmt, hash, ref_storage_format);
/*
* Ensure `core.hidedotfiles` is processed. This must happen after we
--
2.46.0.46.g406f326d27.dirty
next prev parent reply other threads:[~2024-08-15 8:00 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-15 7:59 [PATCH 0/5] Introduce configs for default repo format Patrick Steinhardt
2024-08-15 7:59 ` [PATCH 1/5] t0001: exercise initialization with ref formats more thoroughly Patrick Steinhardt
2024-08-15 20:35 ` Justin Tobler
2024-08-15 8:00 ` [PATCH 2/5] t0001: delete repositories when object format tests finish Patrick Steinhardt
2024-08-15 8:00 ` Patrick Steinhardt [this message]
2024-08-15 21:37 ` [PATCH 3/5] setup: merge configuration of repository formats Justin Tobler
2024-08-16 8:06 ` Patrick Steinhardt
2024-08-15 8:00 ` [PATCH 4/5] setup: make object format configurable via config Patrick Steinhardt
2024-08-15 22:17 ` Justin Tobler
2024-08-15 8:00 ` [PATCH 5/5] setup: make ref storage " Patrick Steinhardt
2024-08-15 22:29 ` Justin Tobler
2024-08-15 15:24 ` [PATCH 0/5] Introduce configs for default repo format shejialuo
2024-08-15 21:16 ` brian m. carlson
2024-08-15 21:52 ` Junio C Hamano
2024-08-16 8:07 ` Patrick Steinhardt
2024-08-15 21:22 ` brian m. carlson
2024-08-16 8:56 ` [PATCH v2 " Patrick Steinhardt
2024-08-16 8:56 ` [PATCH v2 1/5] t0001: exercise initialization with ref formats more thoroughly Patrick Steinhardt
2024-08-16 8:56 ` [PATCH v2 2/5] t0001: delete repositories when object format tests finish Patrick Steinhardt
2024-08-16 8:56 ` [PATCH v2 3/5] setup: merge configuration of repository formats Patrick Steinhardt
2024-08-16 8:57 ` [PATCH v2 4/5] setup: make object format configurable via config Patrick Steinhardt
2024-08-16 17:13 ` Junio C Hamano
2024-08-16 8:57 ` [PATCH v2 5/5] setup: make ref storage " Patrick Steinhardt
2024-08-16 14:46 ` [PATCH v2 0/5] Introduce configs for default repo format Justin Tobler
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=16f52b75d8972343776adb269da305e7406ff385.1723708417.git.ps@pks.im \
--to=ps@pks.im \
--cc=git@vger.kernel.org \
--cc=sschuberth@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.
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 NNTP newsgroup(s).