blob: 5867e26e17777483f3fc5df0084deb7a4dd135da [file] [log] [blame]
Johannes Schindelin16da1342006-07-30 20:25:18 +02001#ifndef UNPACK_TREES_H
2#define UNPACK_TREES_H
3
Elijah Newren73359a92023-04-11 03:00:40 +00004#include "convert.h"
Elijah Newren08c46a42023-05-16 06:33:56 +00005#include "read-cache-ll.h"
Jeff Kingdbbcd442020-07-28 16:23:39 -04006#include "strvec.h"
Elijah Newrenef3ca952018-08-15 10:54:05 -07007#include "string-list.h"
8#include "tree-walk.h"
Clemens Buchacher79808722010-11-15 20:52:19 +01009
Jeff Kingacd13d12023-08-31 02:19:16 -040010#define MAX_UNPACK_TREES 8
Junio C Hamanoca885a42008-03-13 22:07:18 -070011
Elijah Newrenef3ca952018-08-15 10:54:05 -070012struct cache_entry;
Johannes Schindelin16da1342006-07-30 20:25:18 +020013struct unpack_trees_options;
Derrick Stoleecaa3d552019-09-03 11:04:56 -070014struct pattern_list;
Johannes Schindelin16da1342006-07-30 20:25:18 +020015
René Scharfe5828e832013-06-02 17:46:56 +020016typedef int (*merge_fn_t)(const struct cache_entry * const *src,
Linus Torvalds34110cd2008-03-06 18:12:28 -080017 struct unpack_trees_options *options);
Johannes Schindelin16da1342006-07-30 20:25:18 +020018
Matthieu Moy08353eb2010-08-11 10:38:04 +020019enum unpack_trees_error_types {
20 ERROR_WOULD_OVERWRITE = 0,
21 ERROR_NOT_UPTODATE_FILE,
22 ERROR_NOT_UPTODATE_DIR,
Elijah Newrenb817e542021-12-09 05:08:27 +000023 ERROR_CWD_IN_THE_WAY,
Matthieu Moy08402b02010-08-11 10:38:06 +020024 ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN,
25 ERROR_WOULD_LOSE_UNTRACKED_REMOVED,
Matthieu Moy08353eb2010-08-11 10:38:04 +020026 ERROR_BIND_OVERLAP,
Stefan Bellera7bc8452017-03-14 14:46:39 -070027 ERROR_WOULD_LOSE_SUBMODULE,
Elijah Newren1ac83f42020-03-27 00:48:56 +000028
Elijah Newren6271d772020-03-27 00:48:57 +000029 NB_UNPACK_TREES_ERROR_TYPES,
30
Elijah Newren1ac83f42020-03-27 00:48:56 +000031 WARNING_SPARSE_NOT_UPTODATE_FILE,
Elijah Newrenebb568b2020-03-27 00:48:59 +000032 WARNING_SPARSE_UNMERGED_FILE,
Elijah Newren1ac83f42020-03-27 00:48:56 +000033 WARNING_SPARSE_ORPHANED_NOT_OVERWRITTEN,
34
Elijah Newren6271d772020-03-27 00:48:57 +000035 NB_UNPACK_TREES_WARNING_TYPES,
Junio C Hamano8ccba002008-05-17 12:03:49 -070036};
37
Matthieu Moydc1166e2010-09-02 13:57:33 +020038/*
39 * Sets the list of user-friendly error messages to be used by the
Matthieu Moy5e65ee32010-09-02 18:08:15 +020040 * command "cmd" (either merge or checkout), and show_all_errors to 1.
Matthieu Moydc1166e2010-09-02 13:57:33 +020041 */
Matthieu Moye2940302010-09-02 13:57:34 +020042void setup_unpack_trees_porcelain(struct unpack_trees_options *opts,
43 const char *cmd);
Matthieu Moydc1166e2010-09-02 13:57:33 +020044
Martin Ågren1c41d282018-05-21 16:54:28 +020045/*
46 * Frees resources allocated by setup_unpack_trees_porcelain().
47 */
48void clear_unpack_trees_porcelain(struct unpack_trees_options *opts);
49
Elijah Newren480d3d62021-09-27 16:33:44 +000050enum unpack_trees_reset_type {
51 UNPACK_RESET_NONE = 0, /* traditional "false" value; still valid */
52 UNPACK_RESET_INVALID = 1, /* "true" no longer valid; use below values */
53 UNPACK_RESET_PROTECT_UNTRACKED,
54 UNPACK_RESET_OVERWRITE_UNTRACKED
55};
56
Johannes Schindelin16da1342006-07-30 20:25:18 +020057struct unpack_trees_options {
Elijah Newren480d3d62021-09-27 16:33:44 +000058 unsigned int merge,
Stephen Boyd5a56da52009-06-25 22:14:10 -070059 update,
Elijah Newren04988c82021-09-27 16:33:41 +000060 preserve_ignored,
Duy Nguyenb8785792018-08-17 20:00:39 +020061 clone,
Stephen Boyd5a56da52009-06-25 22:14:10 -070062 index_only,
Stephen Boyd5a56da52009-06-25 22:14:10 -070063 trivial_merges_only,
64 verbose_update,
65 aggressive,
66 skip_unmerged,
67 initial_checkout,
68 diff_index_cached,
Nguyễn Thái Ngọc Duy08aefc92009-08-20 20:47:08 +070069 skip_sparse_checkout,
Nguyễn Thái Ngọc Duyb165fac2019-03-22 16:31:36 +070070 quiet,
Junio C Hamanob4194822011-05-31 10:06:44 -070071 exiting_early,
Victoria Dye68fcd482022-11-10 19:06:02 +000072 dry_run,
73 skip_cache_tree_update;
Elijah Newren480d3d62021-09-27 16:33:44 +000074 enum unpack_trees_reset_type reset;
Johannes Schindelin16da1342006-07-30 20:25:18 +020075 const char *prefix;
Ævar Arnfjörð Bjarmason4002ec32022-12-20 13:39:56 +010076 const char *super_prefix;
Junio C Hamano40e37252011-08-29 12:31:06 -070077 struct pathspec *pathspec;
Johannes Schindelin16da1342006-07-30 20:25:18 +020078 merge_fn_t fn;
79
80 int head_idx;
Johannes Schindelin16da1342006-07-30 20:25:18 +020081
Elijah Newrenf2974242023-02-27 15:28:20 +000082 struct cache_entry *df_conflict_entry; /* output only */
Linus Torvaldsd1f2d7e2008-01-19 17:27:12 -080083 void *unpack_data;
Linus Torvalds34110cd2008-03-06 18:12:28 -080084
85 struct index_state *dst_index;
Linus Torvalds32260ad2008-03-22 09:35:59 -070086 struct index_state *src_index;
Nguyễn Thái Ngọc Duy08aefc92009-08-20 20:47:08 +070087
brian m. carlson13e7ed62020-03-16 18:05:04 +000088 struct checkout_metadata meta;
Elijah Newren576de3d2023-02-27 15:28:16 +000089
90 struct unpack_trees_options_internal {
Elijah Newren13e1fd62023-02-27 15:28:17 +000091 unsigned int nontrivial_merge,
Elijah Newren1ca13dd2023-02-27 15:28:19 +000092 show_all_errors,
93 debug_unpack; /* used by read-tree debugging */
Elijah Newren13e1fd62023-02-27 15:28:17 +000094
Elijah Newren1ca13dd2023-02-27 15:28:19 +000095 int merge_size; /* used by read-tree debugging */
Elijah Newren13e1fd62023-02-27 15:28:17 +000096 int cache_bottom;
97 const char *msgs[NB_UNPACK_TREES_WARNING_TYPES];
98 struct strvec msgs_to_free;
99
100 /*
101 * Store error messages in an array, each case
102 * corresponding to a error message type
103 */
104 struct string_list unpack_rejects[NB_UNPACK_TREES_WARNING_TYPES];
105
106 struct index_state result;
107
Elijah Newren576de3d2023-02-27 15:28:16 +0000108 struct pattern_list *pl;
109 struct dir_struct *dir;
110 } internal;
Johannes Schindelin16da1342006-07-30 20:25:18 +0200111};
112
Nguyễn Thái Ngọc Duy340f4bc2018-08-13 18:14:25 +0200113int unpack_trees(unsigned n, struct tree_desc *t,
114 struct unpack_trees_options *options);
Johannes Schindelin16da1342006-07-30 20:25:18 +0200115
Elijah Newren7af7a252020-03-27 00:48:52 +0000116enum update_sparsity_result {
117 UPDATE_SPARSITY_SUCCESS = 0,
118 UPDATE_SPARSITY_WARNINGS = 1,
119 UPDATE_SPARSITY_INDEX_UPDATE_FAILURES = -1,
120 UPDATE_SPARSITY_WORKTREE_UPDATE_FAILURES = -2
121};
122
Elijah Newren1147c562023-02-27 15:28:14 +0000123enum update_sparsity_result update_sparsity(struct unpack_trees_options *options,
124 struct pattern_list *pl);
Elijah Newren7af7a252020-03-27 00:48:52 +0000125
Elijah Newren64b1abe2018-04-19 10:58:12 -0700126int verify_uptodate(const struct cache_entry *ce,
127 struct unpack_trees_options *o);
128
René Scharfe5828e832013-06-02 17:46:56 +0200129int threeway_merge(const struct cache_entry * const *stages,
130 struct unpack_trees_options *o);
131int twoway_merge(const struct cache_entry * const *src,
132 struct unpack_trees_options *o);
133int bind_merge(const struct cache_entry * const *src,
134 struct unpack_trees_options *o);
135int oneway_merge(const struct cache_entry * const *src,
136 struct unpack_trees_options *o);
Denton Liud3c7bf72021-03-03 03:16:42 -0800137int stash_worktree_untracked_merge(const struct cache_entry * const *src,
138 struct unpack_trees_options *o);
Johannes Schindelin076b0ad2006-07-30 20:26:15 +0200139
Johannes Schindelin16da1342006-07-30 20:25:18 +0200140#endif