interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / sequencer.h

336 lines · 10977 bytes Raw Blame History
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
9struct commit;
10struct index_state;
11struct repository;
12
13const char *git_path_commit_editmsg(void);
14const char *rebase_path_todo(void);
15const char *rebase_path_todo_backup(void);
16const char *rebase_path_dropped(void);
17
18extern const char *rebase_resolvemsg;
19
20#define APPEND_SIGNOFF_DEDUP (1u << 0)
21
22enum replay_action {
23 REPLAY_REVERT,
24 REPLAY_PICK,
25 REPLAY_INTERACTIVE_REBASE
26};
27
28enum 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
35struct replay_ctx;
36struct replay_ctx* replay_ctx_new(void);
37
38struct 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 */
101enum 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/* Bits for the "flags" member of struct todo_item */
124enum todo_item_flags {
125 TODO_EDIT_MERGE_MSG = (1 << 0),
126 TODO_REPLACE_FIXUP_MSG = (1 << 1),
127 TODO_EDIT_FIXUP_MSG = (1 << 2),
128};
129
130struct todo_item {
131 enum todo_command command;
132 struct commit *commit;
133 unsigned int flags;
134 int arg_len;
135 /* The offset of the command and its argument in the strbuf */
136 size_t offset_in_buf, arg_offset;
137};
138
139struct todo_list {
140 struct strbuf buf;
141 struct todo_item *items;
142 int nr, alloc, current;
143 int done_nr, total_nr;
144};
145
146#define TODO_LIST_INIT { \
147 .buf = STRBUF_INIT, \
148}
149
150int todo_list_parse_insn_buffer(struct repository *r, struct replay_opts *opts,
151 char *buf, struct todo_list *todo_list);
152int todo_list_write_to_file(struct repository *r, struct todo_list *todo_list,
153 const char *file, const char *shortrevisions,
154 const char *shortonto, int num, unsigned flags);
155void todo_list_release(struct todo_list *todo_list);
156const char *todo_item_get_arg(struct todo_list *todo_list,
157 struct todo_item *item);
158
159/*
160 * Parse the update-refs file for the current rebase, then remove the
161 * refs that do not appear in the todo_list (and have not had updated
162 * values stored) and add refs that are in the todo_list but not
163 * represented in the update-refs file.
164 *
165 * If there are changes to the update-refs list, then write the new state
166 * to disk.
167 */
168void todo_list_filter_update_refs(struct repository *r,
169 struct todo_list *todo_list);
170
171/* Call this to setup defaults before parsing command line options */
172void sequencer_init_config(struct replay_opts *opts);
173int sequencer_pick_revisions(struct repository *repo,
174 struct replay_opts *opts);
175int sequencer_continue(struct repository *repo, struct replay_opts *opts);
176int sequencer_rollback(struct repository *repo, struct replay_opts *opts);
177int sequencer_skip(struct repository *repo, struct replay_opts *opts);
178void replay_opts_release(struct replay_opts *opts);
179int sequencer_remove_state(struct replay_opts *opts);
180
181#define TODO_LIST_KEEP_EMPTY (1U << 0)
182#define TODO_LIST_SHORTEN_IDS (1U << 1)
183#define TODO_LIST_ABBREVIATE_CMDS (1U << 2)
184#define TODO_LIST_REBASE_MERGES (1U << 3)
185/*
186 * When rebasing merges, commits that do have the base commit as ancestor
187 * ("cousins") are *not* rebased onto the new base by default. If those
188 * commits should be rebased onto the new base, this flag needs to be passed.
189 */
190#define TODO_LIST_REBASE_COUSINS (1U << 4)
191#define TODO_LIST_APPEND_TODO_HELP (1U << 5)
192/*
193 * When generating a script that rebases merges with `--root` *and* with
194 * `--onto`, we do not want to re-generate the root commits.
195 */
196#define TODO_LIST_ROOT_WITH_ONTO (1U << 6)
197#define TODO_LIST_REAPPLY_CHERRY_PICKS (1U << 7)
198#define TODO_LIST_WARN_SKIPPED_CHERRY_PICKS (1U << 8)
199
200int sequencer_make_script(struct repository *r, struct strbuf *out,
201 struct strvec *argv, unsigned flags);
202
203int complete_action(struct repository *r, struct replay_opts *opts, unsigned flags,
204 const char *shortrevisions, const char *onto_name,
205 struct commit *onto, const struct object_id *orig_head,
206 struct string_list *commands, unsigned autosquash,
207 unsigned update_refs,
208 struct todo_list *todo_list);
209int todo_list_rearrange_squash(struct todo_list *todo_list);
210
211/*
212 * Append a signoff to the commit message in "msgbuf". The ignore_footer
213 * parameter specifies the number of bytes at the end of msgbuf that should
214 * not be considered at all. I.e., they are not checked for existing trailers,
215 * and the new signoff will be spliced into the buffer before those bytes.
216 */
217void append_signoff(struct strbuf *msgbuf, size_t ignore_footer, unsigned flag);
218
219/*
220 * Append the "This is a combination of N commits." banner that "git rebase
221 * -i" writes at the top of a squashed commit's message, commented out with
222 * the comment character.
223 */
224void add_squash_combination_header(struct strbuf *buf, int n);
225
226/*
227 * Append the header (1-based N) that "git rebase -i" writes above each message
228 * when squashing, commented out with the comment character. With SKIP it reads
229 * "The ... commit message will be skipped" for a message that is dropped (a
230 * fixup), otherwise "This is the ... commit message".
231 */
232void add_squash_message_header(struct strbuf *buf, int n, int skip);
233
234/*
235 * Return the length of the leading subject of BODY when it should be commented
236 * out in a squash message, or 0 otherwise. An "amend!" subject always
237 * qualifies; "squash!" and "fixup!" subjects only when SQUASHING, since a
238 * plain fixup chain keeps them.
239 */
240size_t squash_subject_comment_len(const char *body, int squashing);
241
242void append_conflicts_hint(struct index_state *istate,
243 struct strbuf *msgbuf, enum commit_msg_cleanup_mode cleanup_mode);
244enum commit_msg_cleanup_mode get_cleanup_mode(const char *cleanup_arg,
245 int use_editor);
246
247void cleanup_message(struct strbuf *msgbuf,
248 enum commit_msg_cleanup_mode cleanup_mode, int verbose);
249
250int message_is_empty(const struct strbuf *sb,
251 enum commit_msg_cleanup_mode cleanup_mode);
252int template_untouched(const struct strbuf *sb, const char *template_file,
253 enum commit_msg_cleanup_mode cleanup_mode);
254int update_head_with_reflog(const struct commit *old_head,
255 const struct object_id *new_head,
256 const char *action, const struct strbuf *msg,
257 struct strbuf *err);
258void commit_post_rewrite(struct repository *r,
259 const struct commit *current_head,
260 const struct object_id *new_head);
261
262void create_autostash(struct repository *r, const char *path);
263void create_autostash_ref(struct repository *r, const char *refname,
264 const char *message, bool silent);
265enum stash_apply_result save_autostash(const char *path);
266enum stash_apply_result save_autostash_ref(struct repository *r,
267 const char *refname);
268enum stash_apply_result apply_autostash(const char *path);
269enum stash_apply_result apply_autostash_oid(const char *stash_oid);
270enum stash_apply_result apply_autostash_ref(struct repository *r,
271 const char *refname,
272 const char *label_ours,
273 const char *label_theirs,
274 const char *label_base,
275 const char *stash_msg);
276
277#define SUMMARY_INITIAL_COMMIT (1 << 0)
278#define SUMMARY_SHOW_AUTHOR_DATE (1 << 1)
279void print_commit_summary(struct repository *repo,
280 const char *prefix,
281 const struct object_id *oid,
282 unsigned int flags);
283
284#define READ_ONELINER_SKIP_IF_EMPTY (1 << 0)
285#define READ_ONELINER_WARN_MISSING (1 << 1)
286
287/*
288 * Reads a file that was presumably written by a shell script, i.e. with an
289 * end-of-line marker that needs to be stripped.
290 *
291 * Note that only the last end-of-line marker is stripped, consistent with the
292 * behavior of "$(cat path)" in a shell script.
293 *
294 * Returns 1 if the file was read, 0 if it could not be read or does not exist.
295 */
296int read_oneliner(struct strbuf *buf,
297 const char *path, unsigned flags);
298int read_author_script(const char *path, char **name, char **email, char **date,
299 int allow_missing);
300int write_basic_state(struct replay_opts *opts, const char *head_name,
301 struct commit *onto, const struct object_id *orig_head);
302void sequencer_post_commit_cleanup(struct repository *r, int verbose);
303
304/*
305 * Try to parse the todo command pointed to by *p. On success sets cmd,
306 * advances p and returns true. On failure returns false, leaves p and
307 * cmd unchanged.
308 */
309bool sequencer_parse_todo_command(const char **p, enum todo_command *cmd);
310
311int sequencer_get_last_command(struct repository* r,
312 enum replay_action *action);
313int sequencer_determine_whence(struct repository *r, enum commit_whence *whence);
314
315/**
316 * Append the set of ref-OID pairs that are currently stored for the 'git
317 * rebase --update-refs' feature if such a rebase is currently happening.
318 *
319 * Localized to a worktree's git dir.
320 */
321int sequencer_get_update_refs_state(const char *wt_dir, struct string_list *refs);
322
323/*
324 * Format a revert commit message with appropriate 'Revert "<subject>"' or
325 * 'Reapply "<subject>"' prefix and 'This reverts commit <ref>.' body.
326 * When use_commit_reference is set, <ref> is an abbreviated hash with
327 * subject and date; otherwise the full hex hash is used.
328 */
329void sequencer_format_revert_message(struct repository *r,
330 const char *subject,
331 const struct commit *commit,
332 const struct commit *parent,
333 bool use_commit_reference,
334 struct strbuf *message);
335
336#endif /* SEQUENCER_H */