The eleventh batch
[git/gitster.git] / tmp-objdir.h
blob237d96b66050c82340af3c18b531bd5c877c15ab
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 child_process child = CHILD_PROCESS_INIT;
14 * struct tmp_objdir *t = tmp_objdir_create("incoming");
15 * strvec_push(&child.args, cmd);
16 * strvec_pushv(&child.env, tmp_objdir_env(t));
17 * if (!run_command(&child)) && !tmp_objdir_migrate(t))
18 * printf("success!\n");
19 * else
20 * die("failed...tmp_objdir will clean up for us");
24 struct tmp_objdir;
27 * Create a new temporary object directory with the specified prefix;
28 * returns NULL on failure.
30 struct tmp_objdir *tmp_objdir_create(const char *prefix);
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.
37 const char **tmp_objdir_env(const struct tmp_objdir *);
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.
44 int tmp_objdir_migrate(struct tmp_objdir *);
47 * Destroy a temporary object directory, discarding any objects it contains.
49 int tmp_objdir_destroy(struct tmp_objdir *);
52 * Remove all objects from the temporary object directory, while leaving it
53 * around so more objects can be added.
55 void tmp_objdir_discard_objects(struct tmp_objdir *);
58 * Add the temporary object directory as an alternate object store in the
59 * current process.
61 void tmp_objdir_add_as_alternate(const struct tmp_objdir *);
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.
68 void tmp_objdir_replace_primary_odb(struct tmp_objdir *, int will_destroy);
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.
75 struct tmp_objdir *tmp_objdir_unapply_primary_odb(void);
78 * Reapplies the former primary temporary object database, after potentially
79 * changing its relative path.
81 void tmp_objdir_reapply_primary_odb(struct tmp_objdir *, const char *old_cwd,
82 const char *new_cwd);
85 #endif /* TMP_OBJDIR_H */