git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 0/6] worktree: initialize refdb via ref backends

From
Patrick Steinhardt <ps@pks.im>
Date
Jan 8, 2024, 10:05 UTC
Message-ID
<cover.1704705733.git.ps@pks.im>
In-Reply-To
<cover.1703754513.git.ps@pks.im>
Hi,

this is the second version of my patch series that refactors the initialization of worktree refdbs to use the refs API.

Changes compared to v1:
  - Improved commit messages.
  - This series is now based on `ps/refstorage-extension`, 1b2234079b
    (t9500: write "extensions.refstorage" into config, 2023-12-29).
    While there is no functional dependency between those series,
    merging both topics causes a merge conflict.
Patrick
Patrick Steinhardt (6):
  refs: prepare `refs_init_db()` for initializing worktree refs
  setup: move creation of "refs/" into the files backend
  refs/files: skip creation of "refs/{heads,tags}" for worktrees
  builtin/worktree: move setup of commondir file earlier
  worktree: expose interface to look up worktree by name
  builtin/worktree: create refdb via ref backend
 builtin/worktree.c    | 53 ++++++++++++++++++++-----------------------
 refs.c                |  6 ++---
 refs.h                |  4 +++-
 refs/debug.c          |  4 ++--
 refs/files-backend.c  | 37 +++++++++++++++++++++++++-----
 refs/packed-backend.c |  1 +
 refs/refs-internal.h  |  4 +++-
 setup.c               | 17 +-------------
 worktree.c            | 27 +++++++++++++---------
 worktree.h            | 12 ++++++++++
 10 files changed, 96 insertions(+), 69 deletions(-)
Range-diff against v1:
1:  6cb4e0a99f ! 1:  a4894b3e15 refs: prepare `refs_init_db()` for initializing worktree refs
    @@ refs/refs-internal.h: typedef struct ref_store *ref_store_init_fn(struct reposit
      				       struct ref_transaction *transaction,
     
      ## setup.c ##
    -@@ setup.c: void create_reference_database(const char *initial_branch, int quiet)
    - 	safe_create_dir(git_path("refs"), 1);
    +@@ setup.c: void create_reference_database(unsigned int ref_storage_format,
      	adjust_shared_perm(git_path("refs"));
      
    + 	repo_set_ref_storage_format(the_repository, ref_storage_format);
     -	if (refs_init_db(&err))
     +	if (refs_init_db(get_main_ref_store(the_repository), 0, &err))
      		die("failed to set up refs db: %s", err.buf);
2:  ae013eaa4a ! 2:  f500db51c2 setup: move creation of "refs/" into the files backend
    @@ Commit message
         seems a lot more sensible to have it this way round than to require
         callers to create the directory themselves.
     
    +    An alternative to this would be to create "refs/" in `refs_init_db()`
    +    directly. This feels conceptually unclean though as the creation of the
    +    refdb is now cluttered across different callsites. Furthermore, both the
    +    "files" and the upcoming "reftable" backend write backend-specific data
    +    into the "refs/" directory anyway, so splitting up this logic would only
    +    make it harder to reason about.
    +
         Signed-off-by: Patrick Steinhardt <ps@pks.im>
     
      ## refs/files-backend.c ##
    @@ refs/files-backend.c: static int files_init_db(struct ref_store *ref_store,
      
     
      ## setup.c ##
    -@@ setup.c: void create_reference_database(const char *initial_branch, int quiet)
    +@@ setup.c: void create_reference_database(unsigned int ref_storage_format,
      	struct strbuf err = STRBUF_INIT;
      	int reinit = is_reinit();
      
    @@ 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"));
     -
    + 	repo_set_ref_storage_format(the_repository, ref_storage_format);
      	if (refs_init_db(get_main_ref_store(the_repository), 0, &err))
      		die("failed to set up refs db: %s", err.buf);
    - 
3:  3cf6ceb274 ! 3:  9e99efeaa3 refs/files: skip creation of "refs/{heads,tags}" for worktrees
    @@ Commit message
     
         The files ref backend will create both "refs/heads" and "refs/tags" in
         the Git directory. While this logic makes sense for normal repositories,
    -    it does not fo worktrees because those refs are "common" refs that would
    -    always be contained in the main repository's ref database.
    +    it does not for worktrees because those refs are "common" refs that
    +    would always be contained in the main repository's ref database.
     
         Introduce a new flag telling the backend that it is expected to create a
         per-worktree ref database and skip creation of these dirs in the files
4:  1a6337fc51 = 4:  f2eb020288 builtin/worktree: move setup of commondir file earlier
5:  f344a915e9 ! 5:  5525a9f9c2 worktree: expose interface to look up worktree by name
    @@ worktree.c
      	free (worktrees);
      }
      
    -@@ worktree.c: static struct worktree *get_main_worktree(void)
    +@@ worktree.c: static struct worktree *get_main_worktree(int skip_reading_head)
      	return worktree;
      }
      
    --static struct worktree *get_linked_worktree(const char *id)
    -+struct worktree *get_linked_worktree(const char *id)
    +-static struct worktree *get_linked_worktree(const char *id,
    +-					    int skip_reading_head)
    ++struct worktree *get_linked_worktree(const char *id,
    ++				     int skip_reading_head)
      {
      	struct worktree *worktree = NULL;
      	struct strbuf path = STRBUF_INIT;
    @@ worktree.h: struct worktree *find_worktree(struct worktree **list,
     + * Look up the worktree corresponding to `id`, or NULL of no such worktree
     + * exists.
     + */
    -+struct worktree *get_linked_worktree(const char *id);
    ++struct worktree *get_linked_worktree(const char *id,
    ++				     int skip_reading_head);
     +
      /*
       * Return the worktree corresponding to `path`, or NULL if no such worktree
6:  aae969301f ! 6:  240dc40de1 builtin/worktree: create refdb via ref backend
    @@ builtin/worktree.c: static int add_worktree(const char *path, const char *refnam
     -	strbuf_reset(&sb);
     -	strbuf_addf(&sb, "%s/HEAD", sb_repo.buf);
     -	write_file(sb.buf, "%s", oid_to_hex(null_oid()));
    -+	wt = get_linked_worktree(name);
    ++	wt = get_linked_worktree(name, 1);
     +	if (!wt) {
     +		ret = error(_("could not find created worktree '%s'"), name);
     +		goto done;
base-commit: 1b2234079b24da99dd78e4ce4bfe338a2a841aed
-- 
2.43.GIT
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 13 of 21 in “worktree: initialize refdb via ref backends”
  1. 0/6 worktree: initialize refdb via ref backendsPatrick Steinhardt, Dec 28, 2023
  2. 1/6 refs: prepare `refs_init_db()` for initializing worktree refsPatrick Steinhardt, Dec 28, 2023
  3. 2/6 setup: move creation of "refs/" into the files backendPatrick Steinhardt, Dec 28, 2023
  4. Karthik NayakJan 2, 2024
  5. Patrick SteinhardtJan 3, 2024
  6. 3/6 refs/files: skip creation of "refs/{heads,tags}" for worktreesPatrick Steinhardt, Dec 28, 2023
  7. Eric SunshineDec 29, 2023
  8. 4/6 builtin/worktree: move setup of commondir file earlierPatrick Steinhardt, Dec 28, 2023
  9. 5/6 worktree: expose interface to look up worktree by namePatrick Steinhardt, Dec 28, 2023
  10. 6/6 builtin/worktree: create refdb via ref backendPatrick Steinhardt, Dec 28, 2023
  11. Junio C HamanoDec 28, 2023
  12. Patrick SteinhardtDec 28, 2023
  13. 0/6 worktree: initialize refdb via ref backendsPatrick Steinhardt, Jan 8, 2024
  14. 1/6 refs: prepare `refs_init_db()` for initializing worktree refsPatrick Steinhardt, Jan 8, 2024
  15. 2/6 setup: move creation of "refs/" into the files backendPatrick Steinhardt, Jan 8, 2024
  16. 3/6 refs/files: skip creation of "refs/{heads,tags}" for worktreesPatrick Steinhardt, Jan 8, 2024
  17. 4/6 builtin/worktree: move setup of commondir file earlierPatrick Steinhardt, Jan 8, 2024
  18. 5/6 worktree: expose interface to look up worktree by namePatrick Steinhardt, Jan 8, 2024
  19. 6/6 builtin/worktree: create refdb via ref backendPatrick Steinhardt, Jan 8, 2024
  20. Karthik NayakJan 16, 2024
  21. Junio C HamanoJan 16, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.