Skip to content

Commit ecd81df

Browse files
neerajsi-msftgitster
authored andcommitted
tmp-objdir: disable ref updates when replacing the primary odb
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/[email protected]/ Reported-by: Jeff King <[email protected]> Signed-off-by: Neeraj Singh <[email protected]> Reviewed-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b3cecf4 commit ecd81df

File tree

6 files changed

+21
-1
lines changed

6 files changed

+21
-1
lines changed

environment.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ void setup_git_env(const char *git_dir)
177177
args.graft_file = getenv_safe(&to_free, GRAFT_ENVIRONMENT);
178178
args.index_file = getenv_safe(&to_free, INDEX_ENVIRONMENT);
179179
args.alternate_db = getenv_safe(&to_free, ALTERNATE_DB_ENVIRONMENT);
180+
if (getenv(GIT_QUARANTINE_ENVIRONMENT)) {
181+
args.disable_ref_updates = 1;
182+
}
183+
180184
repo_set_gitdir(the_repository, git_dir, &args);
181185
strvec_clear(&to_free);
182186

object-file.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,12 @@ struct object_directory *set_temporary_primary_odb(const char *dir, int will_des
767767
*/
768768
new_odb = xcalloc(1, sizeof(*new_odb));
769769
new_odb->path = xstrdup(dir);
770+
771+
/*
772+
* Disable ref updates while a temporary odb is active, since
773+
* the objects in the database may roll back.
774+
*/
775+
new_odb->disable_ref_updates = 1;
770776
new_odb->will_destroy = will_destroy;
771777
new_odb->next = the_repository->objects->odb;
772778
the_repository->objects->odb = new_odb;

object-store.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ struct object_directory {
2727
uint32_t loose_objects_subdir_seen[8]; /* 256 bits */
2828
struct oidtree *loose_objects_cache;
2929

30+
/*
31+
* This is a temporary object store created by the tmp_objdir
32+
* facility. Disable ref updates since the objects in the store
33+
* might be discarded on rollback.
34+
*/
35+
int disable_ref_updates;
36+
3037
/*
3138
* This object store is ephemeral, so there is no need to fsync.
3239
*/

refs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2126,7 +2126,7 @@ int ref_transaction_prepare(struct ref_transaction *transaction,
21262126
break;
21272127
}
21282128

2129-
if (getenv(GIT_QUARANTINE_ENVIRONMENT)) {
2129+
if (refs->repo->objects->odb->disable_ref_updates) {
21302130
strbuf_addstr(err,
21312131
_("ref updates forbidden inside quarantine environment"));
21322132
return -1;

repository.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ void repo_set_gitdir(struct repository *repo,
8080
expand_base_dir(&repo->objects->odb->path, o->object_dir,
8181
repo->commondir, "objects");
8282

83+
repo->objects->odb->disable_ref_updates = o->disable_ref_updates;
84+
8385
free(repo->objects->alternate_db);
8486
repo->objects->alternate_db = xstrdup_or_null(o->alternate_db);
8587
expand_base_dir(&repo->graft_file, o->graft_file,

repository.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ struct set_gitdir_args {
162162
const char *graft_file;
163163
const char *index_file;
164164
const char *alternate_db;
165+
int disable_ref_updates;
165166
};
166167

167168
void repo_set_gitdir(struct repository *repo, const char *root,

0 commit comments

Comments
 (0)