mbox series

[v2,00/12] Introduce `refStorage` extension

Message ID cover.1703753910.git.ps@pks.im (mailing list archive)
Headers show
Series Introduce `refStorage` extension | expand

Message

Patrick Steinhardt Dec. 28, 2023, 9:57 a.m. UTC
Hi,

this is the second version of my patch series that introduces the new
`refStorage` extension. This extension will be used for the upcoming
reftable backend.

Changes compared to v2:

  - Fixed various typos in commit messages.

  - Fixed redundant information when the refstorage extension's value
    isn't understood.

  - Introduced `repo_set_ref_storage_format()`.

Thanks for the feedback so far!

Patrick

Patrick Steinhardt (12):
  t: introduce DEFAULT_REPO_FORMAT prereq
  worktree: skip reading HEAD when repairing worktrees
  refs: refactor logic to look up storage backends
  setup: start tracking ref storage format
  setup: set repository's formats on init
  setup: introduce "extensions.refStorage" extension
  setup: introduce GIT_DEFAULT_REF_FORMAT envvar
  t: introduce GIT_TEST_DEFAULT_REF_FORMAT envvar
  builtin/rev-parse: introduce `--show-ref-format` flag
  builtin/init: introduce `--ref-format=` value flag
  builtin/clone: introduce `--ref-format=` value flag
  t9500: write "extensions.refstorage" into config

 Documentation/config/extensions.txt           | 11 +++
 Documentation/git-clone.txt                   |  6 ++
 Documentation/git-init.txt                    |  7 ++
 Documentation/git-rev-parse.txt               |  3 +
 Documentation/git.txt                         |  5 ++
 Documentation/ref-storage-format.txt          |  1 +
 .../technical/repository-version.txt          |  5 ++
 builtin/clone.c                               | 17 ++++-
 builtin/init-db.c                             | 15 +++-
 builtin/rev-parse.c                           |  4 ++
 refs.c                                        | 34 ++++++---
 refs.h                                        |  3 +
 refs/debug.c                                  |  1 -
 refs/files-backend.c                          |  1 -
 refs/packed-backend.c                         |  1 -
 refs/refs-internal.h                          |  1 -
 repository.c                                  |  6 ++
 repository.h                                  |  7 ++
 setup.c                                       | 63 +++++++++++++++--
 setup.h                                       |  9 ++-
 t/README                                      |  3 +
 t/t0001-init.sh                               | 70 +++++++++++++++++++
 t/t1500-rev-parse.sh                          | 17 +++++
 t/t3200-branch.sh                             |  2 +-
 t/t5601-clone.sh                              | 17 +++++
 t/t9500-gitweb-standalone-no-errors.sh        |  5 ++
 t/test-lib-functions.sh                       |  5 ++
 t/test-lib.sh                                 | 15 +++-
 worktree.c                                    | 24 ++++---
 29 files changed, 323 insertions(+), 35 deletions(-)
 create mode 100644 Documentation/ref-storage-format.txt

Range-diff against v1:
 1:  239ca38efd !  1:  3613439cb7 t: introduce DEFAULT_REPO_FORMAT prereq
    @@ Commit message
         repository format or otherwise they would fail to run, e.g. because they
         fail to detect the correct hash function. While the hash function is the
         only extension right now that creates problems like this, we are about
    -    to add a second extensions for the ref format.
    +    to add a second extension for the ref format.
     
         Introduce a new DEFAULT_REPO_FORMAT prereq that can easily be amended
         whenever we add new format extensions. Next to making any such changes
 2:  e895091025 !  2:  ecf4f1ddee worktree: skip reading HEAD when repairing worktrees
    @@ Commit message
         worktree: skip reading HEAD when repairing worktrees
     
         When calling `git init --separate-git-dir=<new-path>` on a preexisting
    -    repository, then we move the Git directory of that repository to the new
    -    path specified by the user. If there are worktrees present in the Git
    -    repository, we need to repair the worktrees so that their gitlinks point
    -    to the new location of the repository.
    +    repository, we move the Git directory of that repository to the new path
    +    specified by the user. If there are worktrees present in the repository,
    +    we need to repair the worktrees so that their gitlinks point to the new
    +    location of the repository.
     
         This repair logic will load repositories via `get_worktrees()`, which
         will enumerate up and initialize all worktrees. Part of initialization
    @@ Commit message
         format, which does not work.
     
         We do not require the worktree HEADs at all to repair worktrees. So
    -    let's fix issue this by skipping over the step that reads them.
    +    let's fix this issue by skipping over the step that reads them.
     
         Signed-off-by: Patrick Steinhardt <ps@pks.im>
     
 3:  f712d5ef5b !  3:  12329b99b7 refs: refactor logic to look up storage backends
    @@ refs.c
     -	for (be = refs_backends; be; be = be->next)
     -		if (!strcmp(be->name, name))
     -			return be;
    -+	if (ref_storage_format && ref_storage_format < ARRAY_SIZE(refs_backends))
    ++	if (ref_storage_format < ARRAY_SIZE(refs_backends))
     +		return refs_backends[ref_storage_format];
      	return NULL;
      }
    @@ refs.c: static struct ref_store *ref_store_init(struct repository *repo,
      
      	if (!be)
     -		BUG("reference backend %s is unknown", be_name);
    -+		BUG("reference backend %s is unknown", ref_storage_format_to_name(format));
    ++		BUG("reference backend is unknown");
      
      	refs = be->init(repo, gitdir, flags);
      	return refs;
 4:  6564659d40 !  4:  ddd099fbaf setup: start tracking ref storage format when
    @@ Metadata
     Author: Patrick Steinhardt <ps@pks.im>
     
      ## Commit message ##
    -    setup: start tracking ref storage format when
    +    setup: start tracking ref storage format
     
         In order to discern which ref storage format a repository is supposed to
         use we need to start setting up and/or discovering the format. This
    @@ Commit message
           - The first path is when we create a repository via `init_db()`. When
             we are re-initializing a preexisting repository we need to retain
             the previously used ref storage format -- if the user asked for a
    -        different format then this indicates an erorr and we error out.
    +        different format then this indicates an error and we error out.
             Otherwise we either initialize the repository with the format asked
             for by the user or the default format, which currently is the
             "files" backend.
    @@ refs.c: static struct ref_store *ref_store_init(struct repository *repo,
      
     +	be = find_ref_storage_backend(repo->ref_storage_format);
      	if (!be)
    --		BUG("reference backend %s is unknown", ref_storage_format_to_name(format));
    -+		BUG("reference backend is unknown");
    - 
    - 	refs = be->init(repo, gitdir, flags);
    - 	return refs;
    -
    - ## refs.h ##
    -@@ refs.h: struct string_list;
    - struct string_list_item;
    - struct worktree;
    - 
    -+int default_ref_storage_format(void);
    - int ref_storage_format_by_name(const char *name);
    - const char *ref_storage_format_to_name(int ref_storage_format);
    + 		BUG("reference backend is unknown");
      
     
      ## repository.c ##
    +@@ repository.c: void repo_set_hash_algo(struct repository *repo, int hash_algo)
    + 	repo->hash_algo = &hash_algos[hash_algo];
    + }
    + 
    ++void repo_set_ref_storage_format(struct repository *repo, int format)
    ++{
    ++	repo->ref_storage_format = format;
    ++}
    ++
    + /*
    +  * Attempt to resolve and set the provided 'gitdir' for repository 'repo'.
    +  * Return 0 upon success and a non-zero value upon failure.
     @@ repository.c: int repo_init(struct repository *repo,
      		goto error;
      
      	repo_set_hash_algo(repo, format.hash_algo);
    -+	repo->ref_storage_format = format.ref_storage_format;
    ++	repo_set_ref_storage_format(repo, format.ref_storage_format);
      	repo->repository_format_worktree_config = format.worktree_config;
      
      	/* take ownership of format.partial_clone */
    @@ repository.h: struct repository {
      	/* A unique-id for tracing purposes. */
      	int trace2_repo_id;
      
    +@@ repository.h: void repo_set_gitdir(struct repository *repo, const char *root,
    + 		     const struct set_gitdir_args *extra_args);
    + void repo_set_worktree(struct repository *repo, const char *path);
    + void repo_set_hash_algo(struct repository *repo, int algo);
    ++void repo_set_ref_storage_format(struct repository *repo, int format);
    + void initialize_the_repository(void);
    + RESULT_MUST_BE_USED
    + int repo_init(struct repository *r, const char *gitdir, const char *worktree);
     
      ## setup.c ##
     @@ setup.c: const char *setup_git_directory_gently(int *nongit_ok)
      		}
      		if (startup_info->have_repository) {
      			repo_set_hash_algo(the_repository, repo_fmt.hash_algo);
    -+			the_repository->ref_storage_format =
    -+				repo_fmt.ref_storage_format;
    ++			repo_set_ref_storage_format(the_repository,
    ++						    repo_fmt.ref_storage_format);
      			the_repository->repository_format_worktree_config =
      				repo_fmt.worktree_config;
      			/* take ownership of repo_fmt.partial_clone */
    @@ setup.c: void check_repository_format(struct repository_format *fmt)
      	check_repository_format_gently(get_git_dir(), fmt, NULL);
      	startup_info->have_repository = 1;
      	repo_set_hash_algo(the_repository, fmt->hash_algo);
    -+	the_repository->ref_storage_format =
    -+		fmt->ref_storage_format;
    ++	repo_set_ref_storage_format(the_repository,
    ++				    fmt->ref_storage_format);
      	the_repository->repository_format_worktree_config =
      		fmt->worktree_config;
      	the_repository->repository_format_partial_clone =
    @@ setup.c: void create_reference_database(const char *initial_branch, int quiet)
      	safe_create_dir(git_path("refs"), 1);
      	adjust_shared_perm(git_path("refs"));
      
    -+	the_repository->ref_storage_format = ref_storage_format;
    ++	repo_set_ref_storage_format(the_repository, ref_storage_format);
      	if (refs_init_db(&err))
      		die("failed to set up refs db: %s", err.buf);
      
 5:  f90a63d63c !  5:  01a1e58a97 setup: set repository's formats on init
    @@ setup.c: int init_db(const char *git_dir, const char *real_git_dir,
     +	 * Now that we have set up both the hash algorithm and the ref storage
     +	 * format we can update the repository's settings accordingly.
     +	 */
    -+	the_repository->hash_algo = &hash_algos[repo_fmt.hash_algo];
    -+	the_repository->ref_storage_format = repo_fmt.ref_storage_format;
    ++	repo_set_hash_algo(the_repository, repo_fmt.hash_algo);
    ++	repo_set_ref_storage_format(the_repository, repo_fmt.ref_storage_format);
     +
      	if (!(flags & INIT_DB_SKIP_REFDB))
      		create_reference_database(repo_fmt.ref_storage_format,
 6:  beeb182f28 =  6:  0a586fa648 setup: introduce "extensions.refStorage" extension
 7:  dd91a75da4 =  7:  6d8754f73a setup: introduce GIT_DEFAULT_REF_FORMAT envvar
 8:  ed3bf008cd =  8:  c645932f3d t: introduce GIT_TEST_DEFAULT_REF_FORMAT envvar
 9:  8a3d950d69 =  9:  761d647770 builtin/rev-parse: introduce `--show-ref-format` flag
10:  4d98b53553 = 10:  e382b5bf08 builtin/init: introduce `--ref-format=` value flag
11:  71cf0ce827 = 11:  257233658d builtin/clone: introduce `--ref-format=` value flag
12:  bbe2fbb154 ! 12:  b8cd06ec53 t9500: write "extensions.refstorage" into config
    @@ Commit message
         t9500: write "extensions.refstorage" into config
     
         In t9500 we're writing a custom configuration that sets up gitweb. This
    -    requires us manually ensure that the repository format is configured as
    -    required, including both the repository format version and extensions.
    -    With the introduction of the "extensions.refStorage" extension we need
    -    to update the test to also write this new one.
    +    requires us to manually ensure that the repository format is configured
    +    as required, including both the repository format version and
    +    extensions. With the introduction of the "extensions.refStorage"
    +    extension we need to update the test to also write this new one.
     
         Signed-off-by: Patrick Steinhardt <ps@pks.im>
     

base-commit: e79552d19784ee7f4bbce278fe25f93fbda196fa