Merge branch 'rj/launch-editor-error-message'
[alt-git.git] / wt-status.h
blob4e377ce62b8b2871bb73cf900acff0a9bab40c6c
1 #ifndef STATUS_H
2 #define STATUS_H
4 #include "string-list.h"
5 #include "color.h"
6 #include "pathspec.h"
7 #include "remote.h"
9 struct repository;
10 struct worktree;
12 enum color_wt_status {
13 WT_STATUS_HEADER = 0,
14 WT_STATUS_UPDATED,
15 WT_STATUS_CHANGED,
16 WT_STATUS_UNTRACKED,
17 WT_STATUS_NOBRANCH,
18 WT_STATUS_UNMERGED,
19 WT_STATUS_LOCAL_BRANCH,
20 WT_STATUS_REMOTE_BRANCH,
21 WT_STATUS_ONBRANCH,
22 WT_STATUS_MAXSLOT
25 enum untracked_status_type {
26 SHOW_UNTRACKED_FILES_ERROR = -1,
27 SHOW_NO_UNTRACKED_FILES = 0,
28 SHOW_NORMAL_UNTRACKED_FILES,
29 SHOW_ALL_UNTRACKED_FILES
32 enum show_ignored_type {
33 SHOW_NO_IGNORED,
34 SHOW_TRADITIONAL_IGNORED,
35 SHOW_MATCHING_IGNORED,
38 /* from where does this commit originate */
39 enum commit_whence {
40 FROM_COMMIT, /* normal */
41 FROM_MERGE, /* commit came from merge */
42 FROM_CHERRY_PICK_SINGLE, /* commit came from cherry-pick */
43 FROM_CHERRY_PICK_MULTI, /* commit came from a sequence of cherry-picks */
44 FROM_REBASE_PICK /* commit came from a pick/reword/edit */
47 static inline int is_from_cherry_pick(enum commit_whence whence)
49 return whence == FROM_CHERRY_PICK_SINGLE ||
50 whence == FROM_CHERRY_PICK_MULTI;
53 static inline int is_from_rebase(enum commit_whence whence)
55 return whence == FROM_REBASE_PICK;
58 struct wt_status_change_data {
59 int worktree_status;
60 int index_status;
61 int stagemask;
62 int mode_head, mode_index, mode_worktree;
63 struct object_id oid_head, oid_index;
64 int rename_status;
65 int rename_score;
66 char *rename_source;
67 unsigned dirty_submodule : 2;
68 unsigned new_submodule_commits : 1;
71 enum wt_status_format {
72 STATUS_FORMAT_NONE = 0,
73 STATUS_FORMAT_LONG,
74 STATUS_FORMAT_SHORT,
75 STATUS_FORMAT_PORCELAIN,
76 STATUS_FORMAT_PORCELAIN_V2,
78 STATUS_FORMAT_UNSPECIFIED
81 #define SPARSE_CHECKOUT_DISABLED -1
82 #define SPARSE_CHECKOUT_SPARSE_INDEX -2
84 struct wt_status_state {
85 int merge_in_progress;
86 int am_in_progress;
87 int am_empty_patch;
88 int rebase_in_progress;
89 int rebase_interactive_in_progress;
90 int cherry_pick_in_progress;
91 int bisect_in_progress;
92 int revert_in_progress;
93 int detached_at;
94 int sparse_checkout_percentage; /* SPARSE_CHECKOUT_DISABLED if not sparse */
95 char *branch;
96 char *onto;
97 char *detached_from;
98 char *bisecting_from;
99 struct object_id detached_oid;
100 struct object_id revert_head_oid;
101 struct object_id cherry_pick_head_oid;
104 struct wt_status {
105 struct repository *repo;
106 int is_initial;
107 char *branch;
108 const char *reference;
109 struct pathspec pathspec;
110 int verbose;
111 int amend;
112 enum commit_whence whence;
113 int nowarn;
114 int use_color;
115 int no_gettext;
116 int display_comment_prefix;
117 int relative_paths;
118 int submodule_summary;
119 enum show_ignored_type show_ignored_mode;
120 enum untracked_status_type show_untracked_files;
121 const char *ignore_submodule_arg;
122 char color_palette[WT_STATUS_MAXSLOT][COLOR_MAXLEN];
123 unsigned colopts;
124 int null_termination;
125 int commit_template;
126 int show_branch;
127 int show_stash;
128 int hints;
129 enum ahead_behind_flags ahead_behind_flags;
130 int detect_rename;
131 int rename_score;
132 int rename_limit;
133 enum wt_status_format status_format;
134 unsigned char added_cut_line; /* boolean */
135 struct wt_status_state state;
136 struct object_id oid_commit; /* when not Initial */
138 /* These are computed during processing of the individual sections */
139 int committable;
140 int workdir_dirty;
141 const char *index_file;
142 FILE *fp;
143 const char *prefix;
144 struct string_list change;
145 struct string_list untracked;
146 struct string_list ignored;
147 uint32_t untracked_in_ms;
150 size_t wt_status_locate_end(const char *s, size_t len);
151 void wt_status_append_cut_line(struct strbuf *buf);
152 void wt_status_add_cut_line(struct wt_status *s);
153 void wt_status_prepare(struct repository *r, struct wt_status *s);
154 void wt_status_print(struct wt_status *s);
155 void wt_status_collect(struct wt_status *s);
157 * Frees the buffers allocated by wt_status_collect.
159 void wt_status_collect_free_buffers(struct wt_status *s);
161 * Frees the buffers of the wt_status_state.
163 void wt_status_state_free_buffers(struct wt_status_state *s);
164 void wt_status_get_state(struct repository *repo,
165 struct wt_status_state *state,
166 int get_detached_from);
167 int wt_status_check_rebase(const struct worktree *wt,
168 struct wt_status_state *state);
169 int wt_status_check_bisect(const struct worktree *wt,
170 struct wt_status_state *state);
172 __attribute__((format (printf, 3, 4)))
173 void status_printf_ln(struct wt_status *s, const char *color, const char *fmt, ...);
174 __attribute__((format (printf, 3, 4)))
175 void status_printf(struct wt_status *s, const char *color, const char *fmt, ...);
177 /* The following functions expect that the caller took care of reading the index. */
178 int has_unstaged_changes(struct repository *repo,
179 int ignore_submodules);
180 int has_uncommitted_changes(struct repository *repo,
181 int ignore_submodules);
182 int require_clean_work_tree(struct repository *repo,
183 const char *action,
184 const char *hint,
185 int ignore_submodules,
186 int gently);
188 #endif /* STATUS_H */