Git fork

tmp-objdir: stop using `the_repository`

Stop using `the_repository` in the "tmp-objdir" subsystem by passing
in the repostiroy when creating a new temporary object directory.

While we could trivially update the caller to pass in the hash algorithm
used by the index itself, we instead pass in `the_hash_algo`. This is
mostly done to stay consistent with the rest of the code in that file,
which isn't prepared to handle arbitrary repositories, either.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Patrick Steinhardt and committed by
Junio C Hamano
727c71a1 b81093ae

+14 -12
+1 -1
builtin/receive-pack.c
··· 2239 2239 strvec_push(&child.args, alt_shallow_file); 2240 2240 } 2241 2241 2242 - tmp_objdir = tmp_objdir_create("incoming"); 2242 + tmp_objdir = tmp_objdir_create(the_repository, "incoming"); 2243 2243 if (!tmp_objdir) { 2244 2244 if (err_fd > 0) 2245 2245 close(err_fd);
+1 -1
bulk-checkin.c
··· 333 333 if (!odb_transaction_nesting || bulk_fsync_objdir) 334 334 return; 335 335 336 - bulk_fsync_objdir = tmp_objdir_create("bulk-fsync"); 336 + bulk_fsync_objdir = tmp_objdir_create(the_repository, "bulk-fsync"); 337 337 if (bulk_fsync_objdir) 338 338 tmp_objdir_replace_primary_odb(bulk_fsync_objdir, 0); 339 339 }
+1 -1
log-tree.c
··· 1042 1042 * into the alternative object store list as the primary. 1043 1043 */ 1044 1044 if (opt->remerge_diff && !opt->remerge_objdir) { 1045 - opt->remerge_objdir = tmp_objdir_create("remerge-diff"); 1045 + opt->remerge_objdir = tmp_objdir_create(the_repository, "remerge-diff"); 1046 1046 if (!opt->remerge_objdir) 1047 1047 return error(_("unable to create temporary object directory")); 1048 1048 tmp_objdir_replace_primary_odb(opt->remerge_objdir, 1);
+8 -7
tmp-objdir.c
··· 1 - #define USE_THE_REPOSITORY_VARIABLE 2 - 3 1 #include "git-compat-util.h" 4 2 #include "tmp-objdir.h" 5 3 #include "abspath.h" ··· 16 14 #include "repository.h" 17 15 18 16 struct tmp_objdir { 17 + struct repository *repo; 19 18 struct strbuf path; 20 19 struct strvec env; 21 20 struct object_directory *prev_odb; ··· 116 115 return ret; 117 116 } 118 117 119 - struct tmp_objdir *tmp_objdir_create(const char *prefix) 118 + struct tmp_objdir *tmp_objdir_create(struct repository *r, 119 + const char *prefix) 120 120 { 121 121 static int installed_handlers; 122 122 struct tmp_objdir *t; ··· 125 125 BUG("only one tmp_objdir can be used at a time"); 126 126 127 127 t = xcalloc(1, sizeof(*t)); 128 + t->repo = r; 128 129 strbuf_init(&t->path, 0); 129 130 strvec_init(&t->env); 130 131 ··· 134 135 * them. 135 136 */ 136 137 strbuf_addf(&t->path, "%s/tmp_objdir-%s-XXXXXX", 137 - repo_get_object_directory(the_repository), prefix); 138 + repo_get_object_directory(r), prefix); 138 139 139 140 if (!mkdtemp(t->path.buf)) { 140 141 /* free, not destroy, as we never touched the filesystem */ ··· 154 155 } 155 156 156 157 env_append(&t->env, ALTERNATE_DB_ENVIRONMENT, 157 - absolute_path(repo_get_object_directory(the_repository))); 158 + absolute_path(repo_get_object_directory(r))); 158 159 env_replace(&t->env, DB_ENVIRONMENT, absolute_path(t->path.buf)); 159 160 env_replace(&t->env, GIT_QUARANTINE_ENVIRONMENT, 160 161 absolute_path(t->path.buf)); ··· 273 274 return 0; 274 275 275 276 if (t->prev_odb) { 276 - if (the_repository->objects->odb->will_destroy) 277 + if (t->repo->objects->odb->will_destroy) 277 278 BUG("migrating an ODB that was marked for destruction"); 278 279 restore_primary_odb(t->prev_odb, t->path.buf); 279 280 t->prev_odb = NULL; 280 281 } 281 282 282 283 strbuf_addbuf(&src, &t->path); 283 - strbuf_addstr(&dst, repo_get_object_directory(the_repository)); 284 + strbuf_addstr(&dst, repo_get_object_directory(t->repo)); 284 285 285 286 ret = migrate_paths(&src, &dst, 0); 286 287
+3 -2
tmp-objdir.h
··· 11 11 * Example: 12 12 * 13 13 * struct child_process child = CHILD_PROCESS_INIT; 14 - * struct tmp_objdir *t = tmp_objdir_create("incoming"); 14 + * struct tmp_objdir *t = tmp_objdir_create(repo, "incoming"); 15 15 * strvec_push(&child.args, cmd); 16 16 * strvec_pushv(&child.env, tmp_objdir_env(t)); 17 17 * if (!run_command(&child)) && !tmp_objdir_migrate(t)) ··· 21 21 * 22 22 */ 23 23 24 + struct repository; 24 25 struct tmp_objdir; 25 26 26 27 /* 27 28 * Create a new temporary object directory with the specified prefix; 28 29 * returns NULL on failure. 29 30 */ 30 - struct tmp_objdir *tmp_objdir_create(const char *prefix); 31 + struct tmp_objdir *tmp_objdir_create(struct repository *r, const char *prefix); 31 32 32 33 /* 33 34 * Return a list of environment strings, suitable for use with