Jeff King | 2564d99 | 2016-10-03 16:49:11 -0400 | [diff] [blame] | 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(); |
| 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; returns NULL on failure. |
| 26 | */ |
| 27 | struct tmp_objdir *tmp_objdir_create(void); |
| 28 | |
| 29 | /* |
| 30 | * Return a list of environment strings, suitable for use with |
| 31 | * child_process.env, that can be passed to child programs to make use of the |
| 32 | * temporary object directory. |
| 33 | */ |
| 34 | const char **tmp_objdir_env(const struct tmp_objdir *); |
| 35 | |
| 36 | /* |
| 37 | * Finalize a temporary object directory by migrating its objects into the main |
| 38 | * object database, removing the temporary directory, and freeing any |
| 39 | * associated resources. |
| 40 | */ |
| 41 | int tmp_objdir_migrate(struct tmp_objdir *); |
| 42 | |
| 43 | /* |
| 44 | * Destroy a temporary object directory, discarding any objects it contains. |
| 45 | */ |
| 46 | int tmp_objdir_destroy(struct tmp_objdir *); |
| 47 | |
| 48 | /* |
| 49 | * Add the temporary object directory as an alternate object store in the |
| 50 | * current process. |
| 51 | */ |
| 52 | void tmp_objdir_add_as_alternate(const struct tmp_objdir *); |
| 53 | |
| 54 | #endif /* TMP_OBJDIR_H */ |