Jeff King | c91f0d9 | 2006-09-08 04:05:34 -0400 | [diff] [blame] | 1 | #ifndef STATUS_H |
| 2 | #define STATUS_H |
| 3 | |
Junio C Hamano | 50b7e70 | 2009-08-04 23:49:33 -0700 | [diff] [blame] | 4 | #include "string-list.h" |
Junio C Hamano | 23900a9 | 2009-08-09 23:08:40 -0700 | [diff] [blame] | 5 | #include "color.h" |
SZEDER Gábor | 7aa9b9b | 2015-08-20 16:06:27 +0200 | [diff] [blame] | 6 | #include "pathspec.h" |
Jeff Hostetler | fd9b544 | 2018-01-09 18:50:16 +0000 | [diff] [blame] | 7 | #include "remote.h" |
Kristian Høgsberg | f26a001 | 2007-09-17 20:06:42 -0400 | [diff] [blame] | 8 | |
Nguyễn Thái Ngọc Duy | 5b02ca3 | 2018-11-10 06:48:49 +0100 | [diff] [blame] | 9 | struct repository; |
Nguyễn Thái Ngọc Duy | 81eff27 | 2016-04-22 20:01:31 +0700 | [diff] [blame] | 10 | struct worktree; |
| 11 | |
Jeff King | c91f0d9 | 2006-09-08 04:05:34 -0400 | [diff] [blame] | 12 | enum color_wt_status { |
Junio C Hamano | 23900a9 | 2009-08-09 23:08:40 -0700 | [diff] [blame] | 13 | WT_STATUS_HEADER = 0, |
Jeff King | c91f0d9 | 2006-09-08 04:05:34 -0400 | [diff] [blame] | 14 | WT_STATUS_UPDATED, |
| 15 | WT_STATUS_CHANGED, |
| 16 | WT_STATUS_UNTRACKED, |
Chris Parsons | 950ce2e | 2008-05-22 08:50:02 -0400 | [diff] [blame] | 17 | WT_STATUS_NOBRANCH, |
Junio C Hamano | 4d4d572 | 2009-08-05 00:04:51 -0700 | [diff] [blame] | 18 | WT_STATUS_UNMERGED, |
Daniel Knittl-Frank | 05a59a0 | 2010-05-25 15:45:51 +0200 | [diff] [blame] | 19 | WT_STATUS_LOCAL_BRANCH, |
Aleksi Aalto | 1d28232 | 2010-11-18 01:40:05 +0200 | [diff] [blame] | 20 | WT_STATUS_REMOTE_BRANCH, |
| 21 | WT_STATUS_ONBRANCH, |
| 22 | WT_STATUS_MAXSLOT |
Jeff King | c91f0d9 | 2006-09-08 04:05:34 -0400 | [diff] [blame] | 23 | }; |
| 24 | |
Marius Storm-Olsen | 4bfee30 | 2008-06-05 10:31:19 +0200 | [diff] [blame] | 25 | enum untracked_status_type { |
Marius Storm-Olsen | 6c2ce04 | 2008-06-05 14:22:56 +0200 | [diff] [blame] | 26 | SHOW_NO_UNTRACKED_FILES, |
| 27 | SHOW_NORMAL_UNTRACKED_FILES, |
Marius Storm-Olsen | 4bfee30 | 2008-06-05 10:31:19 +0200 | [diff] [blame] | 28 | SHOW_ALL_UNTRACKED_FILES |
| 29 | }; |
Marius Storm-Olsen | 4bfee30 | 2008-06-05 10:31:19 +0200 | [diff] [blame] | 30 | |
Jameson Miller | eec0f7f | 2017-10-30 13:21:37 -0400 | [diff] [blame] | 31 | enum show_ignored_type { |
| 32 | SHOW_NO_IGNORED, |
| 33 | SHOW_TRADITIONAL_IGNORED, |
| 34 | SHOW_MATCHING_IGNORED, |
| 35 | }; |
| 36 | |
Jay Soffian | 37f7a85 | 2011-02-19 23:12:29 -0500 | [diff] [blame] | 37 | /* from where does this commit originate */ |
| 38 | enum commit_whence { |
| 39 | FROM_COMMIT, /* normal */ |
| 40 | FROM_MERGE, /* commit came from merge */ |
Phillip Wood | 8d57f75 | 2019-12-06 16:06:10 +0000 | [diff] [blame] | 41 | FROM_CHERRY_PICK_SINGLE, /* commit came from cherry-pick */ |
Phillip Wood | 430b75f | 2019-12-06 16:06:12 +0000 | [diff] [blame] | 42 | FROM_CHERRY_PICK_MULTI, /* commit came from a sequence of cherry-picks */ |
| 43 | FROM_REBASE_PICK /* commit came from a pick/reword/edit */ |
Jay Soffian | 37f7a85 | 2011-02-19 23:12:29 -0500 | [diff] [blame] | 44 | }; |
| 45 | |
Phillip Wood | 8d57f75 | 2019-12-06 16:06:10 +0000 | [diff] [blame] | 46 | static inline int is_from_cherry_pick(enum commit_whence whence) |
| 47 | { |
| 48 | return whence == FROM_CHERRY_PICK_SINGLE || |
| 49 | whence == FROM_CHERRY_PICK_MULTI; |
| 50 | } |
| 51 | |
Phillip Wood | 430b75f | 2019-12-06 16:06:12 +0000 | [diff] [blame] | 52 | static inline int is_from_rebase(enum commit_whence whence) |
| 53 | { |
| 54 | return whence == FROM_REBASE_PICK; |
| 55 | } |
| 56 | |
Junio C Hamano | 50b7e70 | 2009-08-04 23:49:33 -0700 | [diff] [blame] | 57 | struct wt_status_change_data { |
| 58 | int worktree_status; |
| 59 | int index_status; |
| 60 | int stagemask; |
Jeff Hostetler | 1ecdecc | 2016-08-11 10:45:57 -0400 | [diff] [blame] | 61 | int mode_head, mode_index, mode_worktree; |
| 62 | struct object_id oid_head, oid_index; |
Nguyễn Thái Ngọc Duy | 5134ccd | 2017-12-27 17:18:38 +0700 | [diff] [blame] | 63 | int rename_status; |
| 64 | int rename_score; |
| 65 | char *rename_source; |
Jens Lehmann | 9297f77e6 | 2010-03-08 13:53:19 +0100 | [diff] [blame] | 66 | unsigned dirty_submodule : 2; |
| 67 | unsigned new_submodule_commits : 1; |
Junio C Hamano | 50b7e70 | 2009-08-04 23:49:33 -0700 | [diff] [blame] | 68 | }; |
| 69 | |
Jeff Hostetler | be7e795 | 2016-08-05 18:00:27 -0400 | [diff] [blame] | 70 | enum wt_status_format { |
| 71 | STATUS_FORMAT_NONE = 0, |
| 72 | STATUS_FORMAT_LONG, |
| 73 | STATUS_FORMAT_SHORT, |
| 74 | STATUS_FORMAT_PORCELAIN, |
Jeff Hostetler | 1ecdecc | 2016-08-11 10:45:57 -0400 | [diff] [blame] | 75 | STATUS_FORMAT_PORCELAIN_V2, |
Jeff Hostetler | be7e795 | 2016-08-05 18:00:27 -0400 | [diff] [blame] | 76 | |
| 77 | STATUS_FORMAT_UNSPECIFIED |
| 78 | }; |
| 79 | |
Elijah Newren | 051df3c | 2020-06-18 20:49:57 +0000 | [diff] [blame] | 80 | #define SPARSE_CHECKOUT_DISABLED -1 |
Derrick Stolee | bf48e5a | 2021-07-14 13:12:36 +0000 | [diff] [blame] | 81 | #define SPARSE_CHECKOUT_SPARSE_INDEX -2 |
Matthew DeVore | 28438e8 | 2019-06-18 15:29:15 -0700 | [diff] [blame] | 82 | |
Stephen P. Smith | 73ba5d7 | 2018-09-30 07:12:45 -0700 | [diff] [blame] | 83 | struct wt_status_state { |
| 84 | int merge_in_progress; |
| 85 | int am_in_progress; |
| 86 | int am_empty_patch; |
| 87 | int rebase_in_progress; |
| 88 | int rebase_interactive_in_progress; |
| 89 | int cherry_pick_in_progress; |
| 90 | int bisect_in_progress; |
| 91 | int revert_in_progress; |
| 92 | int detached_at; |
Elijah Newren | 051df3c | 2020-06-18 20:49:57 +0000 | [diff] [blame] | 93 | int sparse_checkout_percentage; /* SPARSE_CHECKOUT_DISABLED if not sparse */ |
Stephen P. Smith | 73ba5d7 | 2018-09-30 07:12:45 -0700 | [diff] [blame] | 94 | char *branch; |
| 95 | char *onto; |
| 96 | char *detached_from; |
| 97 | struct object_id detached_oid; |
| 98 | struct object_id revert_head_oid; |
| 99 | struct object_id cherry_pick_head_oid; |
| 100 | }; |
| 101 | |
Jeff King | c91f0d9 | 2006-09-08 04:05:34 -0400 | [diff] [blame] | 102 | struct wt_status { |
Nguyễn Thái Ngọc Duy | 5b02ca3 | 2018-11-10 06:48:49 +0100 | [diff] [blame] | 103 | struct repository *repo; |
Jeff King | c91f0d9 | 2006-09-08 04:05:34 -0400 | [diff] [blame] | 104 | int is_initial; |
| 105 | char *branch; |
| 106 | const char *reference; |
Nguyễn Thái Ngọc Duy | 15b55ae | 2013-07-14 15:35:39 +0700 | [diff] [blame] | 107 | struct pathspec pathspec; |
Jeff King | c91f0d9 | 2006-09-08 04:05:34 -0400 | [diff] [blame] | 108 | int verbose; |
| 109 | int amend; |
Jay Soffian | 37f7a85 | 2011-02-19 23:12:29 -0500 | [diff] [blame] | 110 | enum commit_whence whence; |
Junio C Hamano | 37d07f8 | 2007-12-12 19:09:16 -0800 | [diff] [blame] | 111 | int nowarn; |
Junio C Hamano | d249b09 | 2009-08-09 21:59:30 -0700 | [diff] [blame] | 112 | int use_color; |
Matthieu Moy | 7a76c28 | 2014-03-20 13:12:41 +0100 | [diff] [blame] | 113 | int no_gettext; |
Matthieu Moy | 2556b99 | 2013-09-06 19:43:07 +0200 | [diff] [blame] | 114 | int display_comment_prefix; |
Junio C Hamano | d249b09 | 2009-08-09 21:59:30 -0700 | [diff] [blame] | 115 | int relative_paths; |
| 116 | int submodule_summary; |
Jameson Miller | eec0f7f | 2017-10-30 13:21:37 -0400 | [diff] [blame] | 117 | enum show_ignored_type show_ignored_mode; |
Junio C Hamano | d249b09 | 2009-08-09 21:59:30 -0700 | [diff] [blame] | 118 | enum untracked_status_type show_untracked_files; |
Jens Lehmann | 46a958b | 2010-06-25 16:56:47 +0200 | [diff] [blame] | 119 | const char *ignore_submodule_arg; |
Aleksi Aalto | 1d28232 | 2010-11-18 01:40:05 +0200 | [diff] [blame] | 120 | char color_palette[WT_STATUS_MAXSLOT][COLOR_MAXLEN]; |
Jeff King | 4d2292e | 2012-05-07 15:35:03 -0400 | [diff] [blame] | 121 | unsigned colopts; |
Jeff King | 3207a3a | 2012-05-07 15:44:44 -0400 | [diff] [blame] | 122 | int null_termination; |
Kaartic Sivaraam | 4ddb135 | 2017-06-21 23:46:14 +0530 | [diff] [blame] | 123 | int commit_template; |
Jeff King | d4a6bf1 | 2012-05-07 17:09:04 -0400 | [diff] [blame] | 124 | int show_branch; |
Liam Beguin | c1b5d01 | 2017-06-17 18:30:51 -0400 | [diff] [blame] | 125 | int show_stash; |
Matthieu Moy | 6a964f5 | 2013-09-12 12:50:05 +0200 | [diff] [blame] | 126 | int hints; |
Jeff Hostetler | fd9b544 | 2018-01-09 18:50:16 +0000 | [diff] [blame] | 127 | enum ahead_behind_flags ahead_behind_flags; |
Ben Peart | e8b2dc2 | 2018-05-11 15:38:58 +0000 | [diff] [blame] | 128 | int detect_rename; |
| 129 | int rename_score; |
| 130 | int rename_limit; |
Jeff Hostetler | be7e795 | 2016-08-05 18:00:27 -0400 | [diff] [blame] | 131 | enum wt_status_format status_format; |
Stephen P. Smith | 73ba5d7 | 2018-09-30 07:12:45 -0700 | [diff] [blame] | 132 | struct wt_status_state state; |
brian m. carlson | e0cb7cd | 2019-08-18 20:04:21 +0000 | [diff] [blame] | 133 | struct object_id oid_commit; /* when not Initial */ |
Jeff Hostetler | be7e795 | 2016-08-05 18:00:27 -0400 | [diff] [blame] | 134 | |
Jürgen Rühle | 2a3a3c2 | 2007-01-10 23:25:03 +0100 | [diff] [blame] | 135 | /* These are computed during processing of the individual sections */ |
Stephen P. Smith | 6fa9019 | 2018-09-05 17:53:27 -0700 | [diff] [blame] | 136 | int committable; |
Jürgen Rühle | 2a3a3c2 | 2007-01-10 23:25:03 +0100 | [diff] [blame] | 137 | int workdir_dirty; |
Kristian Høgsberg | 0f729f2 | 2007-09-17 20:06:43 -0400 | [diff] [blame] | 138 | const char *index_file; |
Kristian Høgsberg | f26a001 | 2007-09-17 20:06:42 -0400 | [diff] [blame] | 139 | FILE *fp; |
Johannes Schindelin | 367c988 | 2007-11-11 17:35:41 +0000 | [diff] [blame] | 140 | const char *prefix; |
Junio C Hamano | 50b7e70 | 2009-08-04 23:49:33 -0700 | [diff] [blame] | 141 | struct string_list change; |
Junio C Hamano | 7637868 | 2009-08-10 00:36:33 -0700 | [diff] [blame] | 142 | struct string_list untracked; |
Junio C Hamano | 6cb3f6b | 2010-04-10 00:11:53 -0700 | [diff] [blame] | 143 | struct string_list ignored; |
Nguyễn Thái Ngọc Duy | 6a38ef2 | 2013-03-13 19:59:16 +0700 | [diff] [blame] | 144 | uint32_t untracked_in_ms; |
Jeff King | c91f0d9 | 2006-09-08 04:05:34 -0400 | [diff] [blame] | 145 | }; |
| 146 | |
Brian Malehorn | d76650b | 2017-05-15 23:06:49 -0700 | [diff] [blame] | 147 | size_t wt_status_locate_end(const char *s, size_t len); |
Denton Liu | d540b70 | 2019-04-17 11:23:27 +0100 | [diff] [blame] | 148 | void wt_status_append_cut_line(struct strbuf *buf); |
Nguyễn Thái Ngọc Duy | fcef931 | 2014-02-17 19:15:31 +0700 | [diff] [blame] | 149 | void wt_status_add_cut_line(FILE *fp); |
Nguyễn Thái Ngọc Duy | 5b02ca3 | 2018-11-10 06:48:49 +0100 | [diff] [blame] | 150 | void wt_status_prepare(struct repository *r, struct wt_status *s); |
Jeff Hostetler | be7e795 | 2016-08-05 18:00:27 -0400 | [diff] [blame] | 151 | void wt_status_print(struct wt_status *s); |
Junio C Hamano | 7637868 | 2009-08-10 00:36:33 -0700 | [diff] [blame] | 152 | void wt_status_collect(struct wt_status *s); |
Martin Ågren | 962dd7e | 2020-09-27 15:15:43 +0200 | [diff] [blame] | 153 | /* |
| 154 | * Frees the buffers allocated by wt_status_collect. |
| 155 | */ |
Stephen P. Smith | 73ba5d7 | 2018-09-30 07:12:45 -0700 | [diff] [blame] | 156 | void wt_status_collect_free_buffers(struct wt_status *s); |
Martin Ågren | 962dd7e | 2020-09-27 15:15:43 +0200 | [diff] [blame] | 157 | /* |
| 158 | * Frees the buffers of the wt_status_state. |
| 159 | */ |
| 160 | void wt_status_state_free_buffers(struct wt_status_state *s); |
Nguyễn Thái Ngọc Duy | 7884545 | 2018-11-10 06:48:50 +0100 | [diff] [blame] | 161 | void wt_status_get_state(struct repository *repo, |
| 162 | struct wt_status_state *state, |
| 163 | int get_detached_from); |
Nguyễn Thái Ngọc Duy | 81eff27 | 2016-04-22 20:01:31 +0700 | [diff] [blame] | 164 | int wt_status_check_rebase(const struct worktree *wt, |
| 165 | struct wt_status_state *state); |
Nguyễn Thái Ngọc Duy | f5d067a | 2016-04-22 20:01:34 +0700 | [diff] [blame] | 166 | int wt_status_check_bisect(const struct worktree *wt, |
| 167 | struct wt_status_state *state); |
Jeff King | c91f0d9 | 2006-09-08 04:05:34 -0400 | [diff] [blame] | 168 | |
Jeff King | 8dd0ee8 | 2013-07-09 20:23:28 -0400 | [diff] [blame] | 169 | __attribute__((format (printf, 3, 4))) |
| 170 | void status_printf_ln(struct wt_status *s, const char *color, const char *fmt, ...); |
| 171 | __attribute__((format (printf, 3, 4))) |
| 172 | void status_printf(struct wt_status *s, const char *color, const char *fmt, ...); |
Jonathan Nieder | becbdae | 2011-02-25 23:09:41 -0600 | [diff] [blame] | 173 | |
Johannes Schindelin | 41a5dd6 | 2016-10-07 18:08:56 +0200 | [diff] [blame] | 174 | /* The following functions expect that the caller took care of reading the index. */ |
Nguyễn Thái Ngọc Duy | 5b02ca3 | 2018-11-10 06:48:49 +0100 | [diff] [blame] | 175 | int has_unstaged_changes(struct repository *repo, |
| 176 | int ignore_submodules); |
| 177 | int has_uncommitted_changes(struct repository *repo, |
| 178 | int ignore_submodules); |
| 179 | int require_clean_work_tree(struct repository *repo, |
| 180 | const char *action, |
| 181 | const char *hint, |
| 182 | int ignore_submodules, |
| 183 | int gently); |
Johannes Schindelin | fd84986 | 2016-10-07 18:08:38 +0200 | [diff] [blame] | 184 | |
Jeff King | c91f0d9 | 2006-09-08 04:05:34 -0400 | [diff] [blame] | 185 | #endif /* STATUS_H */ |