Subject: [PATCH v3 0/2] ns/tmp-objdir: add support for temporary writable databases

From: "Neeraj K. Singh via GitGitGadget" <[email-masked]>
Date: Mon, 06 Dec 2021 22:05:03 +0000

V3 (hopefully final):

 * Fix the commit description for patch [2/2] to reflect the fact that
   disabling ref updates no longer depends on the_repository.
 * Add a link to Jeff King's test case in patch [2/2]. The test relies on
   remerge-diff, so it can't be directly included here.
 * Adjust line spacing in update_relative_gitdir (gitster)
 * Switch struct object_directory to use full-width integers rather than
   flags (gitster)
 * Fix typo s/protentially/potentially (neerajsi)

V2 changes: I lost a couple changes in the shuffle while splitting these
changes out

 * Make the will-destroy boolean a single bit field of type unsigned int so
   that it doesn't change twice in this small patch series.
 * Remove a the_repository reference in the disable ref updates code. Now
   the repository is taken from the ref_store.

New interface into the tmp-objdir API to help in-core use of the quarantine
feature.

This patch series was formerly part of the ns/batched-fsync topic [1]. It's
now split out into its own gitgitgadget PR and discussion thread since it is
the base for en/remerge-diff as well.

The most recent feedback was in [2]. I removed printing from prune_subdir
and simplified the strbuf handling in prune_tmp_file.

References: [1]
https://lore.kernel.org/git/[email-masked]/
[2]
https://lore.kernel.org/git/[email-masked]/

Neeraj Singh (2):
  tmp-objdir: new API for creating temporary writable databases
  tmp-objdir: disable ref updates when replacing the primary odb

 builtin/prune.c        | 20 ++++++++++++---
 builtin/receive-pack.c |  2 +-
 environment.c          |  9 +++++++
 object-file.c          | 50 ++++++++++++++++++++++++++++++++++++--
 object-store.h         | 26 ++++++++++++++++++++
 object.c               |  2 +-
 refs.c                 |  2 +-
 repository.c           |  2 ++
 repository.h           |  1 +
 tmp-objdir.c           | 55 +++++++++++++++++++++++++++++++++++++++---
 tmp-objdir.h           | 29 +++++++++++++++++++---
 11 files changed, 183 insertions(+), 15 deletions(-)

base-commit: cd3e606211bb1cf8bc57f7d76bab98cc17a150bc
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1091%2Fneerajsi-msft%2Fns%2Ftmp-objdir-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1091/neerajsi-msft/ns/tmp-objdir-v3
Pull-Request: https://github.com/gitgitgadget/git/pull/1091

Range-diff vs v2:

 1:  36c00613d9a ! 1:  cccb3888070 tmp-objdir: new API for creating temporary writable databases
     @@ environment.c: static void update_relative_gitdir(const char *name,
       {
       	char *path = reparent_relative_path(old_cwd, new_cwd, get_git_dir());
      +	struct tmp_objdir *tmp_objdir = tmp_objdir_unapply_primary_odb();
     ++
       	trace_printf_key(&trace_setup_key,
       			 "setup: move $GIT_DIR to '%s'",
       			 path);
     -+
       	set_git_dir_1(path);
      +	if (tmp_objdir)
      +		tmp_objdir_reapply_primary_odb(tmp_objdir, old_cwd, new_cwd);
     @@ object-store.h: struct object_directory {
      +	/*
      +	 * This object store is ephemeral, so there is no need to fsync.
      +	 */
     -+	unsigned int will_destroy : 1;
     ++	int will_destroy;
      +
       	/*
       	 * Path to the alternative object store. If this is a relative path,
     @@ tmp-objdir.h: int tmp_objdir_destroy(struct tmp_objdir *);
       void tmp_objdir_add_as_alternate(const struct tmp_objdir *);
       
      +/*
     -+ * Replaces the main object store in the current process with the temporary
     ++ * Replaces the writable object store in the current process with the temporary
      + * object directory and makes the former main object store an alternate.
      + * If will_destroy is nonzero, the object directory may not be migrated.
      + */
     @@ tmp-objdir.h: int tmp_objdir_destroy(struct tmp_objdir *);
      +struct tmp_objdir *tmp_objdir_unapply_primary_odb(void);
      +
      +/*
     -+ * Reapplies the former primary temporary object database, after protentially
     ++ * Reapplies the former primary temporary object database, after potentially
      + * changing its relative path.
      + */
      +void tmp_objdir_reapply_primary_odb(struct tmp_objdir *, const char *old_cwd,
 2:  f667cbcc47d ! 2:  4e44121c2d7 tmp-objdir: disable ref updates when replacing the primary odb
     @@ Commit message
          the disable_ref_updates flag on the odb, which is queried by
          the ref_transaction_prepare function.
      
     -    Note: This change adds an assumption that the state of
     -    the_repository is relevant for any ref transaction that might
     -    be initiated. Unwinding this assumption should be straightforward
     -    by saving the relevant repository to query in the transaction or
     -    the ref_store.
     -
     -    Peff's test case was invoking ref updates via the cachetextconv
     +    Peff's test case [1] was invoking ref updates via the cachetextconv
          setting. That particular code silently does nothing when a ref
          update is forbidden. See the call to notes_cache_put in
          fill_textconv where errors are ignored.
      
     +    [1] https://lore.kernel.org/git/[email-masked]/
     +
          Reported-by: Jeff King <[email-masked]>
      
          Signed-off-by: Neeraj Singh <[email-masked]>
     @@ object-store.h: struct object_directory {
      +	 * facility. Disable ref updates since the objects in the store
      +	 * might be discarded on rollback.
      +	 */
     -+	unsigned int disable_ref_updates : 1;
     ++	int disable_ref_updates;
      +
       	/*
       	 * This object store is ephemeral, so there is no need to fsync.

-- 
gitgitgadget