blob: ab9cc9d8f032b77fbf6bfd5882c45a801a28fa09 [file] [log] [blame]
Jeff Kingc91f0d92006-09-08 04:05:34 -04001#ifndef STATUS_H
2#define STATUS_H
3
Junio C Hamano50b7e702009-08-04 23:49:33 -07004#include "string-list.h"
Junio C Hamano23900a92009-08-09 23:08:40 -07005#include "color.h"
SZEDER Gábor7aa9b9b2015-08-20 16:06:27 +02006#include "pathspec.h"
Jeff Hostetlerfd9b5442018-01-09 18:50:16 +00007#include "remote.h"
Kristian Høgsbergf26a0012007-09-17 20:06:42 -04008
Nguyễn Thái Ngọc Duy5b02ca32018-11-10 06:48:49 +01009struct repository;
Nguyễn Thái Ngọc Duy81eff272016-04-22 20:01:31 +070010struct worktree;
11
Jeff Kingc91f0d92006-09-08 04:05:34 -040012enum color_wt_status {
Junio C Hamano23900a92009-08-09 23:08:40 -070013 WT_STATUS_HEADER = 0,
Jeff Kingc91f0d92006-09-08 04:05:34 -040014 WT_STATUS_UPDATED,
15 WT_STATUS_CHANGED,
16 WT_STATUS_UNTRACKED,
Chris Parsons950ce2e2008-05-22 08:50:02 -040017 WT_STATUS_NOBRANCH,
Junio C Hamano4d4d5722009-08-05 00:04:51 -070018 WT_STATUS_UNMERGED,
Daniel Knittl-Frank05a59a02010-05-25 15:45:51 +020019 WT_STATUS_LOCAL_BRANCH,
Aleksi Aalto1d282322010-11-18 01:40:05 +020020 WT_STATUS_REMOTE_BRANCH,
21 WT_STATUS_ONBRANCH,
22 WT_STATUS_MAXSLOT
Jeff Kingc91f0d92006-09-08 04:05:34 -040023};
24
Marius Storm-Olsen4bfee302008-06-05 10:31:19 +020025enum untracked_status_type {
Marius Storm-Olsen6c2ce042008-06-05 14:22:56 +020026 SHOW_NO_UNTRACKED_FILES,
27 SHOW_NORMAL_UNTRACKED_FILES,
Marius Storm-Olsen4bfee302008-06-05 10:31:19 +020028 SHOW_ALL_UNTRACKED_FILES
29};
Marius Storm-Olsen4bfee302008-06-05 10:31:19 +020030
Jameson Millereec0f7f2017-10-30 13:21:37 -040031enum show_ignored_type {
32 SHOW_NO_IGNORED,
33 SHOW_TRADITIONAL_IGNORED,
34 SHOW_MATCHING_IGNORED,
35};
36
Jay Soffian37f7a852011-02-19 23:12:29 -050037/* from where does this commit originate */
38enum commit_whence {
39 FROM_COMMIT, /* normal */
40 FROM_MERGE, /* commit came from merge */
Phillip Wood8d57f752019-12-06 16:06:10 +000041 FROM_CHERRY_PICK_SINGLE, /* commit came from cherry-pick */
Phillip Wood430b75f2019-12-06 16:06:12 +000042 FROM_CHERRY_PICK_MULTI, /* commit came from a sequence of cherry-picks */
43 FROM_REBASE_PICK /* commit came from a pick/reword/edit */
Jay Soffian37f7a852011-02-19 23:12:29 -050044};
45
Phillip Wood8d57f752019-12-06 16:06:10 +000046static 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 Wood430b75f2019-12-06 16:06:12 +000052static inline int is_from_rebase(enum commit_whence whence)
53{
54 return whence == FROM_REBASE_PICK;
55}
56
Junio C Hamano50b7e702009-08-04 23:49:33 -070057struct wt_status_change_data {
58 int worktree_status;
59 int index_status;
60 int stagemask;
Jeff Hostetler1ecdecc2016-08-11 10:45:57 -040061 int mode_head, mode_index, mode_worktree;
62 struct object_id oid_head, oid_index;
Nguyễn Thái Ngọc Duy5134ccd2017-12-27 17:18:38 +070063 int rename_status;
64 int rename_score;
65 char *rename_source;
Jens Lehmann9297f77e62010-03-08 13:53:19 +010066 unsigned dirty_submodule : 2;
67 unsigned new_submodule_commits : 1;
Junio C Hamano50b7e702009-08-04 23:49:33 -070068};
69
Jeff Hostetlerbe7e7952016-08-05 18:00:27 -040070enum wt_status_format {
71 STATUS_FORMAT_NONE = 0,
72 STATUS_FORMAT_LONG,
73 STATUS_FORMAT_SHORT,
74 STATUS_FORMAT_PORCELAIN,
Jeff Hostetler1ecdecc2016-08-11 10:45:57 -040075 STATUS_FORMAT_PORCELAIN_V2,
Jeff Hostetlerbe7e7952016-08-05 18:00:27 -040076
77 STATUS_FORMAT_UNSPECIFIED
78};
79
Elijah Newren051df3c2020-06-18 20:49:57 +000080#define SPARSE_CHECKOUT_DISABLED -1
Derrick Stoleebf48e5a2021-07-14 13:12:36 +000081#define SPARSE_CHECKOUT_SPARSE_INDEX -2
Matthew DeVore28438e82019-06-18 15:29:15 -070082
Stephen P. Smith73ba5d72018-09-30 07:12:45 -070083struct 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 Newren051df3c2020-06-18 20:49:57 +000093 int sparse_checkout_percentage; /* SPARSE_CHECKOUT_DISABLED if not sparse */
Stephen P. Smith73ba5d72018-09-30 07:12:45 -070094 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 Kingc91f0d92006-09-08 04:05:34 -0400102struct wt_status {
Nguyễn Thái Ngọc Duy5b02ca32018-11-10 06:48:49 +0100103 struct repository *repo;
Jeff Kingc91f0d92006-09-08 04:05:34 -0400104 int is_initial;
105 char *branch;
106 const char *reference;
Nguyễn Thái Ngọc Duy15b55ae2013-07-14 15:35:39 +0700107 struct pathspec pathspec;
Jeff Kingc91f0d92006-09-08 04:05:34 -0400108 int verbose;
109 int amend;
Jay Soffian37f7a852011-02-19 23:12:29 -0500110 enum commit_whence whence;
Junio C Hamano37d07f82007-12-12 19:09:16 -0800111 int nowarn;
Junio C Hamanod249b092009-08-09 21:59:30 -0700112 int use_color;
Matthieu Moy7a76c282014-03-20 13:12:41 +0100113 int no_gettext;
Matthieu Moy2556b992013-09-06 19:43:07 +0200114 int display_comment_prefix;
Junio C Hamanod249b092009-08-09 21:59:30 -0700115 int relative_paths;
116 int submodule_summary;
Jameson Millereec0f7f2017-10-30 13:21:37 -0400117 enum show_ignored_type show_ignored_mode;
Junio C Hamanod249b092009-08-09 21:59:30 -0700118 enum untracked_status_type show_untracked_files;
Jens Lehmann46a958b2010-06-25 16:56:47 +0200119 const char *ignore_submodule_arg;
Aleksi Aalto1d282322010-11-18 01:40:05 +0200120 char color_palette[WT_STATUS_MAXSLOT][COLOR_MAXLEN];
Jeff King4d2292e2012-05-07 15:35:03 -0400121 unsigned colopts;
Jeff King3207a3a2012-05-07 15:44:44 -0400122 int null_termination;
Kaartic Sivaraam4ddb1352017-06-21 23:46:14 +0530123 int commit_template;
Jeff Kingd4a6bf12012-05-07 17:09:04 -0400124 int show_branch;
Liam Beguinc1b5d012017-06-17 18:30:51 -0400125 int show_stash;
Matthieu Moy6a964f52013-09-12 12:50:05 +0200126 int hints;
Jeff Hostetlerfd9b5442018-01-09 18:50:16 +0000127 enum ahead_behind_flags ahead_behind_flags;
Ben Pearte8b2dc22018-05-11 15:38:58 +0000128 int detect_rename;
129 int rename_score;
130 int rename_limit;
Jeff Hostetlerbe7e7952016-08-05 18:00:27 -0400131 enum wt_status_format status_format;
Stephen P. Smith73ba5d72018-09-30 07:12:45 -0700132 struct wt_status_state state;
brian m. carlsone0cb7cd2019-08-18 20:04:21 +0000133 struct object_id oid_commit; /* when not Initial */
Jeff Hostetlerbe7e7952016-08-05 18:00:27 -0400134
Jürgen Rühle2a3a3c22007-01-10 23:25:03 +0100135 /* These are computed during processing of the individual sections */
Stephen P. Smith6fa90192018-09-05 17:53:27 -0700136 int committable;
Jürgen Rühle2a3a3c22007-01-10 23:25:03 +0100137 int workdir_dirty;
Kristian Høgsberg0f729f22007-09-17 20:06:43 -0400138 const char *index_file;
Kristian Høgsbergf26a0012007-09-17 20:06:42 -0400139 FILE *fp;
Johannes Schindelin367c9882007-11-11 17:35:41 +0000140 const char *prefix;
Junio C Hamano50b7e702009-08-04 23:49:33 -0700141 struct string_list change;
Junio C Hamano76378682009-08-10 00:36:33 -0700142 struct string_list untracked;
Junio C Hamano6cb3f6b2010-04-10 00:11:53 -0700143 struct string_list ignored;
Nguyễn Thái Ngọc Duy6a38ef22013-03-13 19:59:16 +0700144 uint32_t untracked_in_ms;
Jeff Kingc91f0d92006-09-08 04:05:34 -0400145};
146
Brian Malehornd76650b2017-05-15 23:06:49 -0700147size_t wt_status_locate_end(const char *s, size_t len);
Denton Liud540b702019-04-17 11:23:27 +0100148void wt_status_append_cut_line(struct strbuf *buf);
Nguyễn Thái Ngọc Duyfcef9312014-02-17 19:15:31 +0700149void wt_status_add_cut_line(FILE *fp);
Nguyễn Thái Ngọc Duy5b02ca32018-11-10 06:48:49 +0100150void wt_status_prepare(struct repository *r, struct wt_status *s);
Jeff Hostetlerbe7e7952016-08-05 18:00:27 -0400151void wt_status_print(struct wt_status *s);
Junio C Hamano76378682009-08-10 00:36:33 -0700152void wt_status_collect(struct wt_status *s);
Martin Ågren962dd7e2020-09-27 15:15:43 +0200153/*
154 * Frees the buffers allocated by wt_status_collect.
155 */
Stephen P. Smith73ba5d72018-09-30 07:12:45 -0700156void wt_status_collect_free_buffers(struct wt_status *s);
Martin Ågren962dd7e2020-09-27 15:15:43 +0200157/*
158 * Frees the buffers of the wt_status_state.
159 */
160void wt_status_state_free_buffers(struct wt_status_state *s);
Nguyễn Thái Ngọc Duy78845452018-11-10 06:48:50 +0100161void wt_status_get_state(struct repository *repo,
162 struct wt_status_state *state,
163 int get_detached_from);
Nguyễn Thái Ngọc Duy81eff272016-04-22 20:01:31 +0700164int wt_status_check_rebase(const struct worktree *wt,
165 struct wt_status_state *state);
Nguyễn Thái Ngọc Duyf5d067a2016-04-22 20:01:34 +0700166int wt_status_check_bisect(const struct worktree *wt,
167 struct wt_status_state *state);
Jeff Kingc91f0d92006-09-08 04:05:34 -0400168
Jeff King8dd0ee82013-07-09 20:23:28 -0400169__attribute__((format (printf, 3, 4)))
170void status_printf_ln(struct wt_status *s, const char *color, const char *fmt, ...);
171__attribute__((format (printf, 3, 4)))
172void status_printf(struct wt_status *s, const char *color, const char *fmt, ...);
Jonathan Niederbecbdae2011-02-25 23:09:41 -0600173
Johannes Schindelin41a5dd62016-10-07 18:08:56 +0200174/* The following functions expect that the caller took care of reading the index. */
Nguyễn Thái Ngọc Duy5b02ca32018-11-10 06:48:49 +0100175int has_unstaged_changes(struct repository *repo,
176 int ignore_submodules);
177int has_uncommitted_changes(struct repository *repo,
178 int ignore_submodules);
179int require_clean_work_tree(struct repository *repo,
180 const char *action,
181 const char *hint,
182 int ignore_submodules,
183 int gently);
Johannes Schindelinfd849862016-10-07 18:08:38 +0200184
Jeff Kingc91f0d92006-09-08 04:05:34 -0400185#endif /* STATUS_H */