]> git.ipfire.org Git - thirdparty/git.git/blame - tmp-objdir.h
Git 2.45-rc0
[thirdparty/git.git] / tmp-objdir.h
CommitLineData
2564d994
JK
1#ifndef TMP_OBJDIR_H
2#define TMP_OBJDIR_H
3
4/*
5 * This API allows you to create a temporary object directory, advertise it to
6 * sub-processes via GIT_OBJECT_DIRECTORY and GIT_ALTERNATE_OBJECT_DIRECTORIES,
7 * and then either migrate its object into the main object directory, or remove
8 * it. The library handles unexpected signal/exit death by cleaning up the
9 * temporary directory.
10 *
11 * Example:
12 *
eb5b6b57 13 * struct child_process child = CHILD_PROCESS_INIT;
b3cecf49 14 * struct tmp_objdir *t = tmp_objdir_create("incoming");
eb5b6b57
RS
15 * strvec_push(&child.args, cmd);
16 * strvec_pushv(&child.env, tmp_objdir_env(t));
17 * if (!run_command(&child)) && !tmp_objdir_migrate(t))
2564d994
JK
18 * printf("success!\n");
19 * else
20 * die("failed...tmp_objdir will clean up for us");
21 *
22 */
23
24struct tmp_objdir;
25
26/*
b3cecf49
NS
27 * Create a new temporary object directory with the specified prefix;
28 * returns NULL on failure.
2564d994 29 */
b3cecf49 30struct tmp_objdir *tmp_objdir_create(const char *prefix);
2564d994
JK
31
32/*
33 * Return a list of environment strings, suitable for use with
34 * child_process.env, that can be passed to child programs to make use of the
35 * temporary object directory.
36 */
37const char **tmp_objdir_env(const struct tmp_objdir *);
38
39/*
40 * Finalize a temporary object directory by migrating its objects into the main
41 * object database, removing the temporary directory, and freeing any
42 * associated resources.
43 */
44int tmp_objdir_migrate(struct tmp_objdir *);
45
46/*
47 * Destroy a temporary object directory, discarding any objects it contains.
48 */
49int tmp_objdir_destroy(struct tmp_objdir *);
7b90ab46
EN
50
51/*
52 * Remove all objects from the temporary object directory, while leaving it
53 * around so more objects can be added.
54 */
55void tmp_objdir_discard_objects(struct tmp_objdir *);
2564d994
JK
56
57/*
58 * Add the temporary object directory as an alternate object store in the
59 * current process.
60 */
61void tmp_objdir_add_as_alternate(const struct tmp_objdir *);
62
b3cecf49
NS
63/*
64 * Replaces the writable object store in the current process with the temporary
65 * object directory and makes the former main object store an alternate.
66 * If will_destroy is nonzero, the object directory may not be migrated.
67 */
68void tmp_objdir_replace_primary_odb(struct tmp_objdir *, int will_destroy);
69
70/*
71 * If the primary object database was replaced by a temporary object directory,
72 * restore it to its original value while keeping the directory contents around.
73 * Returns NULL if the primary object database was not replaced.
74 */
75struct tmp_objdir *tmp_objdir_unapply_primary_odb(void);
76
77/*
78 * Reapplies the former primary temporary object database, after potentially
79 * changing its relative path.
80 */
81void tmp_objdir_reapply_primary_odb(struct tmp_objdir *, const char *old_cwd,
82 const char *new_cwd);
83
84
2564d994 85#endif /* TMP_OBJDIR_H */