wt-status.h 4.8 KB

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