]> git.ipfire.org Git - thirdparty/git.git/blob - tmp-objdir.h
Merge branch 'js/ci-gcc-12-fixes'
[thirdparty/git.git] / tmp-objdir.h
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 *
13 * struct tmp_objdir *t = tmp_objdir_create("incoming");
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
22 struct tmp_objdir;
23
24 /*
25 * Create a new temporary object directory with the specified prefix;
26 * returns NULL on failure.
27 */
28 struct tmp_objdir *tmp_objdir_create(const char *prefix);
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 */
35 const 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 */
42 int tmp_objdir_migrate(struct tmp_objdir *);
43
44 /*
45 * Destroy a temporary object directory, discarding any objects it contains.
46 */
47 int tmp_objdir_destroy(struct tmp_objdir *);
48
49 /*
50 * Remove all objects from the temporary object directory, while leaving it
51 * around so more objects can be added.
52 */
53 void tmp_objdir_discard_objects(struct tmp_objdir *);
54
55 /*
56 * Add the temporary object directory as an alternate object store in the
57 * current process.
58 */
59 void tmp_objdir_add_as_alternate(const struct tmp_objdir *);
60
61 /*
62 * Replaces the writable object store in the current process with the temporary
63 * object directory and makes the former main object store an alternate.
64 * If will_destroy is nonzero, the object directory may not be migrated.
65 */
66 void tmp_objdir_replace_primary_odb(struct tmp_objdir *, int will_destroy);
67
68 /*
69 * If the primary object database was replaced by a temporary object directory,
70 * restore it to its original value while keeping the directory contents around.
71 * Returns NULL if the primary object database was not replaced.
72 */
73 struct tmp_objdir *tmp_objdir_unapply_primary_odb(void);
74
75 /*
76 * Reapplies the former primary temporary object database, after potentially
77 * changing its relative path.
78 */
79 void tmp_objdir_reapply_primary_odb(struct tmp_objdir *, const char *old_cwd,
80 const char *new_cwd);
81
82
83 #endif /* TMP_OBJDIR_H */