Git 2.35.8
[git.git] / tmp-objdir.h
blobcda5ec7677881c5a47bb5f2ebf3edc3a3140a73c
1 #ifndef TMP_OBJDIR_H
2 #define TMP_OBJDIR_H
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.
11 * Example:
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");
22 struct tmp_objdir;
25 * Create a new temporary object directory with the specified prefix;
26 * returns NULL on failure.
28 struct tmp_objdir *tmp_objdir_create(const char *prefix);
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.
35 const char **tmp_objdir_env(const struct tmp_objdir *);
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.
42 int tmp_objdir_migrate(struct tmp_objdir *);
45 * Destroy a temporary object directory, discarding any objects it contains.
47 int tmp_objdir_destroy(struct tmp_objdir *);
50 * Add the temporary object directory as an alternate object store in the
51 * current process.
53 void tmp_objdir_add_as_alternate(const struct tmp_objdir *);
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.
60 void tmp_objdir_replace_primary_odb(struct tmp_objdir *, int will_destroy);
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.
67 struct tmp_objdir *tmp_objdir_unapply_primary_odb(void);
70 * Reapplies the former primary temporary object database, after potentially
71 * changing its relative path.
73 void tmp_objdir_reapply_primary_odb(struct tmp_objdir *, const char *old_cwd,
74 const char *new_cwd);
77 #endif /* TMP_OBJDIR_H */