git
[Ported from github.com/git/git] Sync with Git 2.56.1
Brought by drakestapleton
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 child_process child = CHILD_PROCESS_INIT; |
| 14 | * struct tmp_objdir *t = tmp_objdir_create(repo, "incoming", 0); |
| 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 | |
| 24 | struct repository; |
| 25 | struct tmp_objdir; |
| 26 | |
| 27 | /* |
| 28 | * Create a new temporary object directory with the specified prefix and |
| 29 | * install the directory as the primary write target; returns NULL on failure. |
| 30 | */ |
| 31 | struct tmp_objdir *tmp_objdir_create(struct repository *r, const char *prefix, |
| 32 | int will_destroy); |
| 33 | |
| 34 | /* |
| 35 | * Return a list of environment strings, suitable for use with |
| 36 | * child_process.env, that can be passed to child programs to make use of the |
| 37 | * temporary object directory. |
| 38 | */ |
| 39 | const char **tmp_objdir_env(const struct tmp_objdir *); |
| 40 | |
| 41 | /* |
| 42 | * Finalize a temporary object directory by migrating its objects into the main |
| 43 | * object database, removing the temporary directory, and freeing any |
| 44 | * associated resources. |
| 45 | */ |
| 46 | int tmp_objdir_migrate(struct tmp_objdir *); |
| 47 | |
| 48 | /* |
| 49 | * Destroy a temporary object directory, discarding any objects it contains. |
| 50 | */ |
| 51 | int tmp_objdir_destroy(struct tmp_objdir *); |
| 52 | |
| 53 | /* |
| 54 | * Remove all objects from the temporary object directory, while leaving it |
| 55 | * around so more objects can be added. |
| 56 | */ |
| 57 | void tmp_objdir_discard_objects(struct tmp_objdir *); |
| 58 | |
| 59 | #endif /* TMP_OBJDIR_H */ |