]> git.ipfire.org Git - thirdparty/git.git/commitdiff
tmp-objdir: disable ref updates when replacing the primary odb
authorNeeraj Singh <neerajsi@microsoft.com>
Mon, 6 Dec 2021 22:05:05 +0000 (22:05 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 8 Dec 2021 22:06:46 +0000 (14:06 -0800)
When creating a subprocess with a temporary ODB, we set the
GIT_QUARANTINE_ENVIRONMENT env var to tell child Git processes not
to update refs, since the tmp-objdir may go away.

Introduce a similar mechanism for in-process temporary ODBs when
we call tmp_objdir_replace_primary_odb. Now both mechanisms set
the disable_ref_updates flag on the odb, which is queried by
the ref_transaction_prepare function.

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/YVOn3hDsb5pnxR53@coredump.intra.peff.net/

Reported-by: Jeff King <peff@peff.net>
Signed-off-by: Neeraj Singh <neerajsi@microsoft.com>
Reviewed-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
environment.c
object-file.c
object-store.h
refs.c
repository.c
repository.h

index e3a285a08fbc169a81ad862f8e75fe87da3d8a37..d797f173b0d7a89ce6b61bf89a234b4a9827cbb2 100644 (file)
@@ -177,6 +177,10 @@ void setup_git_env(const char *git_dir)
        args.graft_file = getenv_safe(&to_free, GRAFT_ENVIRONMENT);
        args.index_file = getenv_safe(&to_free, INDEX_ENVIRONMENT);
        args.alternate_db = getenv_safe(&to_free, ALTERNATE_DB_ENVIRONMENT);
+       if (getenv(GIT_QUARANTINE_ENVIRONMENT)) {
+               args.disable_ref_updates = 1;
+       }
+
        repo_set_gitdir(the_repository, git_dir, &args);
        strvec_clear(&to_free);
 
index 990381abee57cd1beb07fbabf7e3d6b1431ed7e0..f16441afb938b6f65488ef27290e631a56b7891a 100644 (file)
@@ -767,6 +767,12 @@ struct object_directory *set_temporary_primary_odb(const char *dir, int will_des
         */
        new_odb = xcalloc(1, sizeof(*new_odb));
        new_odb->path = xstrdup(dir);
+
+       /*
+        * Disable ref updates while a temporary odb is active, since
+        * the objects in the database may roll back.
+        */
+       new_odb->disable_ref_updates = 1;
        new_odb->will_destroy = will_destroy;
        new_odb->next = the_repository->objects->odb;
        the_repository->objects->odb = new_odb;
index 74b1b5872a6adfe8a92b4b89c432de76bef35305..62a0c97f2739a14e7afa410c6103970d80b6a767 100644 (file)
@@ -27,6 +27,13 @@ struct object_directory {
        uint32_t loose_objects_subdir_seen[8]; /* 256 bits */
        struct oidtree *loose_objects_cache;
 
+       /*
+        * This is a temporary object store created by the tmp_objdir
+        * facility. Disable ref updates since the objects in the store
+        * might be discarded on rollback.
+        */
+       int disable_ref_updates;
+
        /*
         * This object store is ephemeral, so there is no need to fsync.
         */
diff --git a/refs.c b/refs.c
index 8b9f7c3a80a0f615e33a7d14cd505c27c3304491..b49864fc1a24ca6d87b49038d36892fa6615afb7 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -2126,7 +2126,7 @@ int ref_transaction_prepare(struct ref_transaction *transaction,
                break;
        }
 
-       if (getenv(GIT_QUARANTINE_ENVIRONMENT)) {
+       if (refs->repo->objects->odb->disable_ref_updates) {
                strbuf_addstr(err,
                              _("ref updates forbidden inside quarantine environment"));
                return -1;
index 710a3b4bf872fb0db64f859d5c49d085c198f089..18e0526da01d0edaca084cec0169ef8570b9fae0 100644 (file)
@@ -80,6 +80,8 @@ void repo_set_gitdir(struct repository *repo,
        expand_base_dir(&repo->objects->odb->path, o->object_dir,
                        repo->commondir, "objects");
 
+       repo->objects->odb->disable_ref_updates = o->disable_ref_updates;
+
        free(repo->objects->alternate_db);
        repo->objects->alternate_db = xstrdup_or_null(o->alternate_db);
        expand_base_dir(&repo->graft_file, o->graft_file,
index 3740c93bc0fe273c975e76e5643507bff35ceb06..77316367d998a398b787474ab20888580db65f60 100644 (file)
@@ -162,6 +162,7 @@ struct set_gitdir_args {
        const char *graft_file;
        const char *index_file;
        const char *alternate_db;
+       int disable_ref_updates;
 };
 
 void repo_set_gitdir(struct repository *repo, const char *root,