When creating transactions via the "tmp-objdir" subsystem callers are expected to first call `tmp_objdir_create()` to create the quarantine directory and then `tmp_objdir_replace_primary_odb()` to activate that quarantine directory as the primary object database source so that all newly written objects are written into it. This dance is performed by all users of temporary object directories, so that makes the setup unnecessarily involved. Merge the logic to replace the primary object database source into `tmp_objdir_create()` to simplify the dance. Note that with the quarantine directory being installed by `tmp_objdir_create()`, users of this function no longer get a pointer to the underlying quarantine directory. So instead of repreparing only that directory, we now reprepare the whole source instead, and as we know that the source has wired up the quarantine directory already, this will cause us to reprepare the quarantine directory, too. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
60 lines
1.8 KiB
C
60 lines
1.8 KiB
C
#ifndef TMP_OBJDIR_H
|
|
#define TMP_OBJDIR_H
|
|
|
|
/*
|
|
* This API allows you to create a temporary object directory, advertise it to
|
|
* sub-processes via GIT_OBJECT_DIRECTORY and GIT_ALTERNATE_OBJECT_DIRECTORIES,
|
|
* and then either migrate its object into the main object directory, or remove
|
|
* it. The library handles unexpected signal/exit death by cleaning up the
|
|
* temporary directory.
|
|
*
|
|
* Example:
|
|
*
|
|
* struct child_process child = CHILD_PROCESS_INIT;
|
|
* struct tmp_objdir *t = tmp_objdir_create(repo, "incoming", 0);
|
|
* strvec_push(&child.args, cmd);
|
|
* strvec_pushv(&child.env, tmp_objdir_env(t));
|
|
* if (!run_command(&child)) && !tmp_objdir_migrate(t))
|
|
* printf("success!\n");
|
|
* else
|
|
* die("failed...tmp_objdir will clean up for us");
|
|
*
|
|
*/
|
|
|
|
struct repository;
|
|
struct tmp_objdir;
|
|
|
|
/*
|
|
* Create a new temporary object directory with the specified prefix and
|
|
* install the directory as the primary write target; returns NULL on failure.
|
|
*/
|
|
struct tmp_objdir *tmp_objdir_create(struct repository *r, const char *prefix,
|
|
int will_destroy);
|
|
|
|
/*
|
|
* Return a list of environment strings, suitable for use with
|
|
* child_process.env, that can be passed to child programs to make use of the
|
|
* temporary object directory.
|
|
*/
|
|
const char **tmp_objdir_env(const struct tmp_objdir *);
|
|
|
|
/*
|
|
* Finalize a temporary object directory by migrating its objects into the main
|
|
* object database, removing the temporary directory, and freeing any
|
|
* associated resources.
|
|
*/
|
|
int tmp_objdir_migrate(struct tmp_objdir *);
|
|
|
|
/*
|
|
* Destroy a temporary object directory, discarding any objects it contains.
|
|
*/
|
|
int tmp_objdir_destroy(struct tmp_objdir *);
|
|
|
|
/*
|
|
* Remove all objects from the temporary object directory, while leaving it
|
|
* around so more objects can be added.
|
|
*/
|
|
void tmp_objdir_discard_objects(struct tmp_objdir *);
|
|
|
|
#endif /* TMP_OBJDIR_H */
|