MCPcopy Index your code
hub / github.com/git/git / tmp_objdir_create

Function tmp_objdir_create

tmp-objdir.c:135–184  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

133}
134
135struct tmp_objdir *tmp_objdir_create(struct repository *r,
136 const char *prefix)
137{
138 static int installed_handlers;
139 struct tmp_objdir *t;
140
141 if (the_tmp_objdir)
142 BUG("only one tmp_objdir can be used at a time");
143
144 t = xcalloc(1, sizeof(*t));
145 t->repo = r;
146 strbuf_init(&t->path, 0);
147 strvec_init(&t->env);
148
149 /*
150 * Use a string starting with tmp_ so that the builtin/prune.c code
151 * can recognize any stale objdirs left behind by a crash and delete
152 * them.
153 */
154 strbuf_addf(&t->path, "%s/tmp_objdir-%s-XXXXXX",
155 repo_get_object_directory(r), prefix);
156
157 if (!is_absolute_path(t->path.buf))
158 chdir_notify_register(NULL, tmp_objdir_reparent, t);
159
160 if (!mkdtemp(t->path.buf)) {
161 /* free, not destroy, as we never touched the filesystem */
162 tmp_objdir_free(t);
163 return NULL;
164 }
165
166 the_tmp_objdir = t;
167 if (!installed_handlers) {
168 atexit(remove_tmp_objdir);
169 installed_handlers++;
170 }
171
172 if (setup_tmp_objdir(t->path.buf)) {
173 tmp_objdir_destroy(t);
174 return NULL;
175 }
176
177 env_append(&t->env, ALTERNATE_DB_ENVIRONMENT,
178 absolute_path(repo_get_object_directory(r)));
179 env_replace(&t->env, DB_ENVIRONMENT, absolute_path(t->path.buf));
180 env_replace(&t->env, GIT_QUARANTINE_ENVIRONMENT,
181 absolute_path(t->path.buf));
182
183 return t;
184}
185
186/*
187 * Make sure we copy packfiles and their associated metafiles in the correct

Callers 3

do_remerge_diffFunction · 0.85
unpackFunction · 0.85

Calls 13

xcallocFunction · 0.85
strbuf_initFunction · 0.85
strvec_initFunction · 0.85
strbuf_addfFunction · 0.85
is_absolute_pathFunction · 0.85
chdir_notify_registerFunction · 0.85
tmp_objdir_freeFunction · 0.85
setup_tmp_objdirFunction · 0.85
tmp_objdir_destroyFunction · 0.85
env_appendFunction · 0.85
absolute_pathFunction · 0.85

Tested by

no test coverage detected