diff options
author | Jeff King <peff@peff.net> | 2016-10-03 16:49:11 -0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-10-10 13:54:02 -0700 |
commit | 2564d994c9c91aea58d59565d68d42bbc017f536 (patch) | |
tree | 862d782736c08245b5b90f0e25f86a4988f8d92d /tmp-objdir.h | |
parent | 526f108a271b331af9ae92796215e560e5ec4677 (diff) | |
download | git-2564d994c9c91aea58d59565d68d42bbc017f536.tar.gz |
tmp-objdir: introduce API for temporary object directories
Once objects are added to the object database by a process,
they cannot easily be deleted, as we don't know what other
processes may have started referencing them. We have to
clean them up with git-gc, which will apply the usual
reachability and grace-period checks.
This patch provides an alternative: it helps callers create
a temporary directory inside the object directory, and a
temporary environment which can be passed to sub-programs to
ask them to write there (the original object directory
remains accessible as an alternate of the temporary one).
See tmp-objdir.h for details on the API.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'tmp-objdir.h')
-rw-r--r-- | tmp-objdir.h | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/tmp-objdir.h b/tmp-objdir.h new file mode 100644 index 0000000000..b1e45b4c75 --- /dev/null +++ b/tmp-objdir.h @@ -0,0 +1,54 @@ +#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 tmp_objdir *t = tmp_objdir_create(); + * if (!run_command_v_opt_cd_env(cmd, 0, NULL, tmp_objdir_env(t)) && + * !tmp_objdir_migrate(t)) + * printf("success!\n"); + * else + * die("failed...tmp_objdir will clean up for us"); + * + */ + +struct tmp_objdir; + +/* + * Create a new temporary object directory; returns NULL on failure. + */ +struct tmp_objdir *tmp_objdir_create(void); + +/* + * 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 *); + +/* + * Add the temporary object directory as an alternate object store in the + * current process. + */ +void tmp_objdir_add_as_alternate(const struct tmp_objdir *); + +#endif /* TMP_OBJDIR_H */ |