setup: inline `check_and_apply_repository_format()`

We have two callsites of `check_and_apply_repository_format()`. In a subsequent commit we'll want to adapt one of those callsites to change the order in which we read and apply the repository format, at which point the helper function will not really be a good fit for us anymore. Inline the function to both of the callsites. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Jun 25, 2026 at 11:19 UTC 35b6b8256cb793a7f5d4903635038b5002f338f6
1 file changed +16 -31
setup.c
+16 -31
@@ -1788,32 +1788,6 @@ int apply_repository_format(struct repository *repo,
1788 return 0;
1789 }
1790
1791 -/*
1792 - * Check the repository format version in the path found in repo_get_git_dir(repo),
1793 - * and die if it is a version we don't understand. Generally one would
1794 - * set_git_dir() before calling this, and use it only for "are we in a valid
1795 - * repo?".
1796 - *
1797 - * If successful and fmt is not NULL, fill fmt with data.
1798 - */
1799 -static void check_and_apply_repository_format(struct repository *repo,
1800 - struct repository_format *fmt,
1801 - enum apply_repository_format_flags flags)
1802 -{
1803 - struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT;
1804 - struct strbuf err = STRBUF_INIT;
1805 -
1806 - if (!fmt)
1807 - fmt = &repo_fmt;
1808 -
1809 - check_repository_format_gently(repo_get_git_dir(repo), fmt, NULL);
1810 - if (apply_repository_format(repo, fmt, flags, &err) < 0)
1811 - die("%s", err.buf);
1812 - startup_info->have_repository = 1;
1813 -
1814 - clear_repository_format(&repo_fmt);
1815 -}
1816 -
1791 const char *enter_repo(struct repository *repo, const char *path, unsigned flags)
1792 {
1793 static struct strbuf validated_path = STRBUF_INIT;
@@ -1887,9 +1861,17 @@ const char *enter_repo(struct repository *repo, const char *path, unsigned flags
1861 }
1862
1863 if (is_git_directory(".")) {
1864 + struct repository_format fmt = REPOSITORY_FORMAT_INIT;
1865 + struct strbuf err = STRBUF_INIT;
1866 +
1867 set_git_dir(repo, ".", 0);
1891 - check_and_apply_repository_format(repo, NULL,
1892 - APPLY_REPOSITORY_FORMAT_HONOR_ENV);
1868 + check_repository_format_gently(".", &fmt, NULL);
1869 + if (apply_repository_format(repo, &fmt, APPLY_REPOSITORY_FORMAT_HONOR_ENV, &err) < 0)
1870 + die("%s", err.buf);
1871 + startup_info->have_repository = 1;
1872 +
1873 + clear_repository_format(&fmt);
1874 + strbuf_release(&err);
1875 return path;
1876 }
1877
@@ -2820,6 +2802,7 @@ int init_db(struct repository *repo,
2802 int exist_ok = flags & INIT_DB_EXIST_OK;
2803 char *original_git_dir = real_pathdup(git_dir, 1);
2804 struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT;
2805 + struct strbuf err = STRBUF_INIT;
2806
2807 if (real_git_dir) {
2808 struct stat st;
@@ -2846,9 +2829,10 @@ int init_db(struct repository *repo,
2829 * config file, so this will not fail. What we are catching
2830 * is an attempt to reinitialize new repository with an old tool.
2831 */
2849 - check_and_apply_repository_format(repo, &repo_fmt,
2850 - APPLY_REPOSITORY_FORMAT_HONOR_ENV);
2851 -
2832 + check_repository_format_gently(repo_get_git_dir(repo), &repo_fmt, NULL);
2833 + if (apply_repository_format(repo, &repo_fmt, APPLY_REPOSITORY_FORMAT_HONOR_ENV, &err) < 0)
2834 + die("%s", err.buf);
2835 + startup_info->have_repository = 1;
2836 repository_format_configure(repo, &repo_fmt, hash, ref_storage_format);
2837
2838 /*
@@ -2904,6 +2888,7 @@ int init_db(struct repository *repo,
2888 }
2889
2890 clear_repository_format(&repo_fmt);
2891 + strbuf_release(&err);
2892 free(original_git_dir);
2893 return 0;
2894 }