Git fork
at reftables-rust 86 lines 2.8 kB view raw
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 child_process child = CHILD_PROCESS_INIT; 14 * struct tmp_objdir *t = tmp_objdir_create(repo, "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"); 21 * 22 */ 23 24struct repository; 25struct tmp_objdir; 26 27/* 28 * Create a new temporary object directory with the specified prefix; 29 * returns NULL on failure. 30 */ 31struct tmp_objdir *tmp_objdir_create(struct repository *r, const char *prefix); 32 33/* 34 * Return a list of environment strings, suitable for use with 35 * child_process.env, that can be passed to child programs to make use of the 36 * temporary object directory. 37 */ 38const char **tmp_objdir_env(const struct tmp_objdir *); 39 40/* 41 * Finalize a temporary object directory by migrating its objects into the main 42 * object database, removing the temporary directory, and freeing any 43 * associated resources. 44 */ 45int tmp_objdir_migrate(struct tmp_objdir *); 46 47/* 48 * Destroy a temporary object directory, discarding any objects it contains. 49 */ 50int tmp_objdir_destroy(struct tmp_objdir *); 51 52/* 53 * Remove all objects from the temporary object directory, while leaving it 54 * around so more objects can be added. 55 */ 56void tmp_objdir_discard_objects(struct tmp_objdir *); 57 58/* 59 * Add the temporary object directory as an alternate object store in the 60 * current process. 61 */ 62void tmp_objdir_add_as_alternate(const struct tmp_objdir *); 63 64/* 65 * Replaces the writable object store in the current process with the temporary 66 * object directory and makes the former main object store an alternate. 67 * If will_destroy is nonzero, the object directory may not be migrated. 68 */ 69void tmp_objdir_replace_primary_odb(struct tmp_objdir *, int will_destroy); 70 71/* 72 * If the primary object database was replaced by a temporary object directory, 73 * restore it to its original value while keeping the directory contents around. 74 * Returns NULL if the primary object database was not replaced. 75 */ 76struct tmp_objdir *tmp_objdir_unapply_primary_odb(void); 77 78/* 79 * Reapplies the former primary temporary object database, after potentially 80 * changing its relative path. 81 */ 82void tmp_objdir_reapply_primary_odb(struct tmp_objdir *, const char *old_cwd, 83 const char *new_cwd); 84 85 86#endif /* TMP_OBJDIR_H */