]> git.ipfire.org Git - thirdparty/git.git/blame - tmp-objdir.h
Sync with maint-2.34
[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 *
b3cecf49 13 * struct tmp_objdir *t = tmp_objdir_create("incoming");
2564d994
JK
14 * if (!run_command_v_opt_cd_env(cmd, 0, NULL, tmp_objdir_env(t)) &&
15 * !tmp_objdir_migrate(t))
16 * printf("success!\n");
17 * else
18 * die("failed...tmp_objdir will clean up for us");
19 *
20 */
21
22struct tmp_objdir;
23
24/*
b3cecf49
NS
25 * Create a new temporary object directory with the specified prefix;
26 * returns NULL on failure.
2564d994 27 */
b3cecf49 28struct tmp_objdir *tmp_objdir_create(const char *prefix);
2564d994
JK
29
30/*
31 * Return a list of environment strings, suitable for use with
32 * child_process.env, that can be passed to child programs to make use of the
33 * temporary object directory.
34 */
35const char **tmp_objdir_env(const struct tmp_objdir *);
36
37/*
38 * Finalize a temporary object directory by migrating its objects into the main
39 * object database, removing the temporary directory, and freeing any
40 * associated resources.
41 */
42int tmp_objdir_migrate(struct tmp_objdir *);
43
44/*
45 * Destroy a temporary object directory, discarding any objects it contains.
46 */
47int tmp_objdir_destroy(struct tmp_objdir *);
48
49/*
50 * Add the temporary object directory as an alternate object store in the
51 * current process.
52 */
53void tmp_objdir_add_as_alternate(const struct tmp_objdir *);
54
b3cecf49
NS
55/*
56 * Replaces the writable object store in the current process with the temporary
57 * object directory and makes the former main object store an alternate.
58 * If will_destroy is nonzero, the object directory may not be migrated.
59 */
60void tmp_objdir_replace_primary_odb(struct tmp_objdir *, int will_destroy);
61
62/*
63 * If the primary object database was replaced by a temporary object directory,
64 * restore it to its original value while keeping the directory contents around.
65 * Returns NULL if the primary object database was not replaced.
66 */
67struct tmp_objdir *tmp_objdir_unapply_primary_odb(void);
68
69/*
70 * Reapplies the former primary temporary object database, after potentially
71 * changing its relative path.
72 */
73void tmp_objdir_reapply_primary_odb(struct tmp_objdir *, const char *old_cwd,
74 const char *new_cwd);
75
76
2564d994 77#endif /* TMP_OBJDIR_H */