| 1 | #ifndef REPLAY_H |
| 2 | #define REPLAY_H |
| 3 | |
| 4 | #include "hash.h" |
| 5 | |
| 6 | struct repository; |
| 7 | struct rev_info; |
| 8 | |
| 9 | /* |
| 10 | * Controls what happens when a replayed commit becomes empty (i.e. its tree |
| 11 | * is identical to its parent's tree after the replay). |
| 12 | */ |
| 13 | enum replay_empty_commit_action { |
| 14 | /* Silently discard the empty commit. */ |
| 15 | REPLAY_EMPTY_COMMIT_DROP, |
| 16 | /* Keep the empty commit as-is. */ |
| 17 | REPLAY_EMPTY_COMMIT_KEEP, |
| 18 | /* Abort with an error. */ |
| 19 | REPLAY_EMPTY_COMMIT_ABORT, |
| 20 | }; |
| 21 | |
| 22 | /* |
| 23 | * A set of options that can be passed to `replay_revisions()`. |
| 24 | */ |
| 25 | struct replay_revisions_options { |
| 26 | /* |
| 27 | * Starting point at which to create the new commits; must be a branch |
| 28 | * name. The branch will be updated to point to the rewritten commits. |
| 29 | * This option is mutually exclusive with `onto` and `revert`. |
| 30 | */ |
| 31 | const char *advance; |
| 32 | |
| 33 | /* |
| 34 | * Starting point at which to create the new commits; must be a |
| 35 | * committish. References pointing at descendants of `onto` will be |
| 36 | * updated to point to the new commits. |
| 37 | */ |
| 38 | const char *onto; |
| 39 | |
| 40 | /* |
| 41 | * Reference to update with the result of the replay. This will not |
| 42 | * update any refs from `onto`, `advance`, or `revert`. Ignores |
| 43 | * `contained`. |
| 44 | */ |
| 45 | const char *ref; |
| 46 | |
| 47 | /* |
| 48 | * Starting point at which to create revert commits; must be a branch |
| 49 | * name. The branch will be updated to point to the revert commits. |
| 50 | * This option is mutually exclusive with `onto` and `advance`. |
| 51 | */ |
| 52 | const char *revert; |
| 53 | |
| 54 | /* |
| 55 | * Update branches that point at commits in the given revision range. |
| 56 | * Requires `onto` to be set. |
| 57 | */ |
| 58 | int contained; |
| 59 | |
| 60 | /* |
| 61 | * Controls what to do when a replayed commit becomes empty. |
| 62 | * Defaults to REPLAY_EMPTY_COMMIT_DROP. |
| 63 | */ |
| 64 | enum replay_empty_commit_action empty; |
| 65 | |
| 66 | /* |
| 67 | * Whether to linearize the commits (i.e. drop merge commits). |
| 68 | */ |
| 69 | int linearize; |
| 70 | }; |
| 71 | |
| 72 | /* This struct is used as an out-parameter by `replay_revisions()`. */ |
| 73 | struct replay_result { |
| 74 | /* |
| 75 | * The set of reference updates that are caused by replaying the |
| 76 | * commits. |
| 77 | */ |
| 78 | struct replay_ref_update { |
| 79 | char *refname; |
| 80 | struct object_id old_oid; |
| 81 | struct object_id new_oid; |
| 82 | } *updates; |
| 83 | size_t updates_nr, updates_alloc; |
| 84 | }; |
| 85 | |
| 86 | void replay_result_release(struct replay_result *result); |
| 87 | |
| 88 | void replay_result_queue_update(struct replay_result *result, |
| 89 | const char *refname, |
| 90 | const struct object_id *old_oid, |
| 91 | const struct object_id *new_oid); |
| 92 | |
| 93 | /* |
| 94 | * Replay a set of commits onto a new location. Leaves both the working tree, |
| 95 | * index and references untouched. Reference updates caused by the replay will |
| 96 | * be recorded in the `updates` out pointer. |
| 97 | * |
| 98 | * Returns 0 on success, 1 on conflict and a negative error code otherwise. |
| 99 | */ |
| 100 | int replay_revisions(struct rev_info *revs, |
| 101 | struct replay_revisions_options *opts, |
| 102 | struct replay_result *out); |
| 103 | |
| 104 | #endif |