at commit a0189536

1 #ifndef SEQUENCER_H
2 #define SEQUENCER_H
3
4 #include "strbuf.h"
5 #include "strvec.h"
6 #include "stash.h"
7 #include "wt-status.h"
8
9 struct commit;
10 struct index_state;
11 struct repository;
12
13 const char *git_path_commit_editmsg(void);
14 const char *rebase_path_todo(void);
15 const char *rebase_path_todo_backup(void);
16 const char *rebase_path_dropped(void);
17
18 extern const char *rebase_resolvemsg;
19
20 #define APPEND_SIGNOFF_DEDUP (1u << 0)
21
22 enum replay_action {
23 REPLAY_REVERT,
24 REPLAY_PICK,
25 REPLAY_INTERACTIVE_REBASE
26 };
27
28 enum commit_msg_cleanup_mode {
29 COMMIT_MSG_CLEANUP_SPACE,
30 COMMIT_MSG_CLEANUP_NONE,
31 COMMIT_MSG_CLEANUP_SCISSORS,
32 COMMIT_MSG_CLEANUP_ALL
33 };
34
35 struct replay_ctx;
36 struct replay_ctx* replay_ctx_new(void);
37
38 struct replay_opts {
39 enum replay_action action;
40
41 /* Tri-state options: unspecified, false, or true */
42 int edit;
43
44 /* Boolean options */
45 int record_origin;
46 int no_commit;
47 int signoff;
48 int allow_ff;
49 int allow_rerere_auto;
50 int allow_empty;
51 int allow_empty_message;
52 int drop_redundant_commits;
53 int keep_redundant_commits;
54 int verbose;
55 int quiet;
56 int reschedule_failed_exec;
57 int committer_date_is_author_date;
58 int ignore_date;
59 int commit_use_reference;
60
61 struct strvec trailer_args;
62
63 int mainline;
64
65 char *gpg_sign;
66 enum commit_msg_cleanup_mode default_msg_cleanup;
67 int explicit_cleanup;
68
69 /* Merge strategy */
70 char *default_strategy; /* from config options */
71 char *strategy;
72 struct strvec xopts;
73
74 /* Reflog */
75 char *reflog_action;
76
77 /* placeholder commit for -i --root */
78 struct object_id squash_onto;
79 int have_squash_onto;
80
81 /* Only used by REPLAY_NONE */
82 struct rev_info *revs;
83
84 /* Private use */
85 struct replay_ctx *ctx;
86 };
87 #define REPLAY_OPTS_INIT { \
88 .edit = -1, \
89 .action = -1, \
90 .trailer_args = STRVEC_INIT, \
91 .xopts = STRVEC_INIT, \
92 .ctx = replay_ctx_new(), \
93 }
94
95 /*
96 * Note that ordering matters in this enum. Not only must it match the mapping
97 * of todo_command_info (in sequencer.c), it is also divided into several
98 * sections that matter. When adding new commands, make sure you add it in the
99 * right section.
100 */
101 enum todo_command {
102 /* commands that handle commits */
103 TODO_PICK = 0,
104 TODO_REVERT,
105 TODO_EDIT,
106 TODO_REWORD,
107 TODO_FIXUP,
108 TODO_SQUASH,
109 /* commands that do something else than handling a single commit */
110 TODO_EXEC,
111 TODO_BREAK,
112 TODO_LABEL,
113 TODO_RESET,
114 TODO_MERGE,
115 TODO_UPDATE_REF,
116 /* commands that do nothing but are counted for reporting progress */
117 TODO_NOOP,
118 TODO_DROP,
119 /* comments (not counted for reporting progress) */
120 TODO_COMMENT
121 };
122
123 struct todo_item {
124 enum todo_command command;
125 struct commit *commit;
126 unsigned int flags;
127 int arg_len;
128 /* The offset of the command and its argument in the strbuf */
129 size_t offset_in_buf, arg_offset;
130 };
131
132 struct todo_list {
133 struct strbuf buf;
134 struct todo_item *items;
135 int nr, alloc, current;
136 int done_nr, total_nr;
137 };
138
139 #define TODO_LIST_INIT { \
140 .buf = STRBUF_INIT, \
141 }
142
143 int todo_list_parse_insn_buffer(struct repository *r, struct replay_opts *opts,
144 char *buf, struct todo_list *todo_list);
145 int todo_list_write_to_file(struct repository *r, struct todo_list *todo_list,
146 const char *file, const char *shortrevisions,
147 const char *shortonto, int num, unsigned flags);
148 void todo_list_release(struct todo_list *todo_list);
149 const char *todo_item_get_arg(struct todo_list *todo_list,
150 struct todo_item *item);
151
152 /*
153 * Parse the update-refs file for the current rebase, then remove the
154 * refs that do not appear in the todo_list (and have not had updated
155 * values stored) and add refs that are in the todo_list but not
156 * represented in the update-refs file.
157 *
158 * If there are changes to the update-refs list, then write the new state
159 * to disk.
160 */
161 void todo_list_filter_update_refs(struct repository *r,
162 struct todo_list *todo_list);
163
164 /* Call this to setup defaults before parsing command line options */
165 void sequencer_init_config(struct replay_opts *opts);
166 int sequencer_pick_revisions(struct repository *repo,
167 struct replay_opts *opts);
168 int sequencer_continue(struct repository *repo, struct replay_opts *opts);
169 int sequencer_rollback(struct repository *repo, struct replay_opts *opts);
170 int sequencer_skip(struct repository *repo, struct replay_opts *opts);
171 void replay_opts_release(struct replay_opts *opts);
172 int sequencer_remove_state(struct replay_opts *opts);
173
174 #define TODO_LIST_KEEP_EMPTY (1U << 0)
175 #define TODO_LIST_SHORTEN_IDS (1U << 1)
176 #define TODO_LIST_ABBREVIATE_CMDS (1U << 2)
177 #define TODO_LIST_REBASE_MERGES (1U << 3)
178 /*
179 * When rebasing merges, commits that do have the base commit as ancestor
180 * ("cousins") are *not* rebased onto the new base by default. If those
181 * commits should be rebased onto the new base, this flag needs to be passed.
182 */
183 #define TODO_LIST_REBASE_COUSINS (1U << 4)
184 #define TODO_LIST_APPEND_TODO_HELP (1U << 5)
185 /*
186 * When generating a script that rebases merges with `--root` *and* with
187 * `--onto`, we do not want to re-generate the root commits.
188 */
189 #define TODO_LIST_ROOT_WITH_ONTO (1U << 6)
190 #define TODO_LIST_REAPPLY_CHERRY_PICKS (1U << 7)
191 #define TODO_LIST_WARN_SKIPPED_CHERRY_PICKS (1U << 8)
192
193 int sequencer_make_script(struct repository *r, struct strbuf *out,
194 struct strvec *argv, unsigned flags);
195
196 int complete_action(struct repository *r, struct replay_opts *opts, unsigned flags,
197 const char *shortrevisions, const char *onto_name,
198 struct commit *onto, const struct object_id *orig_head,
199 struct string_list *commands, unsigned autosquash,
200 unsigned update_refs,
201 struct todo_list *todo_list);
202 int todo_list_rearrange_squash(struct todo_list *todo_list);
203
204 /*
205 * Append a signoff to the commit message in "msgbuf". The ignore_footer
206 * parameter specifies the number of bytes at the end of msgbuf that should
207 * not be considered at all. I.e., they are not checked for existing trailers,
208 * and the new signoff will be spliced into the buffer before those bytes.
209 */
210 void append_signoff(struct strbuf *msgbuf, size_t ignore_footer, unsigned flag);
211
212 void append_conflicts_hint(struct index_state *istate,
213 struct strbuf *msgbuf, enum commit_msg_cleanup_mode cleanup_mode);
214 enum commit_msg_cleanup_mode get_cleanup_mode(const char *cleanup_arg,
215 int use_editor);
216
217 void cleanup_message(struct strbuf *msgbuf,
218 enum commit_msg_cleanup_mode cleanup_mode, int verbose);
219
220 int message_is_empty(const struct strbuf *sb,
221 enum commit_msg_cleanup_mode cleanup_mode);
222 int template_untouched(const struct strbuf *sb, const char *template_file,
223 enum commit_msg_cleanup_mode cleanup_mode);
224 int update_head_with_reflog(const struct commit *old_head,
225 const struct object_id *new_head,
226 const char *action, const struct strbuf *msg,
227 struct strbuf *err);
228 void commit_post_rewrite(struct repository *r,
229 const struct commit *current_head,
230 const struct object_id *new_head);
231
232 void create_autostash(struct repository *r, const char *path);
233 void create_autostash_ref(struct repository *r, const char *refname,
234 const char *message, bool silent);
235 enum stash_apply_result save_autostash(const char *path);
236 enum stash_apply_result save_autostash_ref(struct repository *r,
237 const char *refname);
238 enum stash_apply_result apply_autostash(const char *path);
239 enum stash_apply_result apply_autostash_oid(const char *stash_oid);
240 enum stash_apply_result apply_autostash_ref(struct repository *r,
241 const char *refname,
242 const char *label_ours,
243 const char *label_theirs,
244 const char *label_base,
245 const char *stash_msg);
246
247 #define SUMMARY_INITIAL_COMMIT (1 << 0)
248 #define SUMMARY_SHOW_AUTHOR_DATE (1 << 1)
249 void print_commit_summary(struct repository *repo,
250 const char *prefix,
251 const struct object_id *oid,
252 unsigned int flags);
253
254 #define READ_ONELINER_SKIP_IF_EMPTY (1 << 0)
255 #define READ_ONELINER_WARN_MISSING (1 << 1)
256
257 /*
258 * Reads a file that was presumably written by a shell script, i.e. with an
259 * end-of-line marker that needs to be stripped.
260 *
261 * Note that only the last end-of-line marker is stripped, consistent with the
262 * behavior of "$(cat path)" in a shell script.
263 *
264 * Returns 1 if the file was read, 0 if it could not be read or does not exist.
265 */
266 int read_oneliner(struct strbuf *buf,
267 const char *path, unsigned flags);
268 int read_author_script(const char *path, char **name, char **email, char **date,
269 int allow_missing);
270 int write_basic_state(struct replay_opts *opts, const char *head_name,
271 struct commit *onto, const struct object_id *orig_head);
272 void sequencer_post_commit_cleanup(struct repository *r, int verbose);
273
274 /*
275 * Try to parse the todo command pointed to by *p. On success sets cmd,
276 * advances p and returns true. On failure returns false, leaves p and
277 * cmd unchanged.
278 */
279 bool sequencer_parse_todo_command(const char **p, enum todo_command *cmd);
280
281 int sequencer_get_last_command(struct repository* r,
282 enum replay_action *action);
283 int sequencer_determine_whence(struct repository *r, enum commit_whence *whence);
284
285 /**
286 * Append the set of ref-OID pairs that are currently stored for the 'git
287 * rebase --update-refs' feature if such a rebase is currently happening.
288 *
289 * Localized to a worktree's git dir.
290 */
291 int sequencer_get_update_refs_state(const char *wt_dir, struct string_list *refs);
292
293 /*
294 * Format a revert commit message with appropriate 'Revert "<subject>"' or
295 * 'Reapply "<subject>"' prefix and 'This reverts commit <ref>.' body.
296 * When use_commit_reference is set, <ref> is an abbreviated hash with
297 * subject and date; otherwise the full hex hash is used.
298 */
299 void sequencer_format_revert_message(struct repository *r,
300 const char *subject,
301 const struct commit *commit,
302 const struct commit *parent,
303 bool use_commit_reference,
304 struct strbuf *message);
305
306 #endif /* SEQUENCER_H */