Raw
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 /* This struct is used as an out-parameter by `replay_revisions()`. */
68 struct replay_result {
69 /*
70 * The set of reference updates that are caused by replaying the
71 * commits.
72 */
73 struct replay_ref_update {
74 char *refname;
75 struct object_id old_oid;
76 struct object_id new_oid;
77 } *updates;
78 size_t updates_nr, updates_alloc;
79 };
80
81 void replay_result_release(struct replay_result *result);
82
83 /*
84 * Replay a set of commits onto a new location. Leaves both the working tree,
85 * index and references untouched. Reference updates caused by the replay will
86 * be recorded in the `updates` out pointer.
87 *
88 * Returns 0 on success, 1 on conflict and a negative error code otherwise.
89 */
90 int replay_revisions(struct rev_info *revs,
91 struct replay_revisions_options *opts,
92 struct replay_result *out);
93
94 #endif