Johannes Schindelin | 16da134 | 2006-07-30 20:25:18 +0200 | [diff] [blame] | 1 | #ifndef UNPACK_TREES_H |
| 2 | #define UNPACK_TREES_H |
| 3 | |
Elijah Newren | 73359a9 | 2023-04-11 03:00:40 +0000 | [diff] [blame] | 4 | #include "convert.h" |
Elijah Newren | 08c46a4 | 2023-05-16 06:33:56 +0000 | [diff] [blame] | 5 | #include "read-cache-ll.h" |
Jeff King | dbbcd44 | 2020-07-28 16:23:39 -0400 | [diff] [blame] | 6 | #include "strvec.h" |
Elijah Newren | ef3ca95 | 2018-08-15 10:54:05 -0700 | [diff] [blame] | 7 | #include "string-list.h" |
| 8 | #include "tree-walk.h" |
Clemens Buchacher | 7980872 | 2010-11-15 20:52:19 +0100 | [diff] [blame] | 9 | |
Jeff King | acd13d1 | 2023-08-31 02:19:16 -0400 | [diff] [blame] | 10 | #define MAX_UNPACK_TREES 8 |
Junio C Hamano | ca885a4 | 2008-03-13 22:07:18 -0700 | [diff] [blame] | 11 | |
Elijah Newren | ef3ca95 | 2018-08-15 10:54:05 -0700 | [diff] [blame] | 12 | struct cache_entry; |
Johannes Schindelin | 16da134 | 2006-07-30 20:25:18 +0200 | [diff] [blame] | 13 | struct unpack_trees_options; |
Derrick Stolee | caa3d55 | 2019-09-03 11:04:56 -0700 | [diff] [blame] | 14 | struct pattern_list; |
Johannes Schindelin | 16da134 | 2006-07-30 20:25:18 +0200 | [diff] [blame] | 15 | |
René Scharfe | 5828e83 | 2013-06-02 17:46:56 +0200 | [diff] [blame] | 16 | typedef int (*merge_fn_t)(const struct cache_entry * const *src, |
Linus Torvalds | 34110cd | 2008-03-06 18:12:28 -0800 | [diff] [blame] | 17 | struct unpack_trees_options *options); |
Johannes Schindelin | 16da134 | 2006-07-30 20:25:18 +0200 | [diff] [blame] | 18 | |
Matthieu Moy | 08353eb | 2010-08-11 10:38:04 +0200 | [diff] [blame] | 19 | enum unpack_trees_error_types { |
| 20 | ERROR_WOULD_OVERWRITE = 0, |
| 21 | ERROR_NOT_UPTODATE_FILE, |
| 22 | ERROR_NOT_UPTODATE_DIR, |
Elijah Newren | b817e54 | 2021-12-09 05:08:27 +0000 | [diff] [blame] | 23 | ERROR_CWD_IN_THE_WAY, |
Matthieu Moy | 08402b0 | 2010-08-11 10:38:06 +0200 | [diff] [blame] | 24 | ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN, |
| 25 | ERROR_WOULD_LOSE_UNTRACKED_REMOVED, |
Matthieu Moy | 08353eb | 2010-08-11 10:38:04 +0200 | [diff] [blame] | 26 | ERROR_BIND_OVERLAP, |
Stefan Beller | a7bc845 | 2017-03-14 14:46:39 -0700 | [diff] [blame] | 27 | ERROR_WOULD_LOSE_SUBMODULE, |
Elijah Newren | 1ac83f4 | 2020-03-27 00:48:56 +0000 | [diff] [blame] | 28 | |
Elijah Newren | 6271d77 | 2020-03-27 00:48:57 +0000 | [diff] [blame] | 29 | NB_UNPACK_TREES_ERROR_TYPES, |
| 30 | |
Elijah Newren | 1ac83f4 | 2020-03-27 00:48:56 +0000 | [diff] [blame] | 31 | WARNING_SPARSE_NOT_UPTODATE_FILE, |
Elijah Newren | ebb568b | 2020-03-27 00:48:59 +0000 | [diff] [blame] | 32 | WARNING_SPARSE_UNMERGED_FILE, |
Elijah Newren | 1ac83f4 | 2020-03-27 00:48:56 +0000 | [diff] [blame] | 33 | WARNING_SPARSE_ORPHANED_NOT_OVERWRITTEN, |
| 34 | |
Elijah Newren | 6271d77 | 2020-03-27 00:48:57 +0000 | [diff] [blame] | 35 | NB_UNPACK_TREES_WARNING_TYPES, |
Junio C Hamano | 8ccba00 | 2008-05-17 12:03:49 -0700 | [diff] [blame] | 36 | }; |
| 37 | |
Matthieu Moy | dc1166e | 2010-09-02 13:57:33 +0200 | [diff] [blame] | 38 | /* |
| 39 | * Sets the list of user-friendly error messages to be used by the |
Matthieu Moy | 5e65ee3 | 2010-09-02 18:08:15 +0200 | [diff] [blame] | 40 | * command "cmd" (either merge or checkout), and show_all_errors to 1. |
Matthieu Moy | dc1166e | 2010-09-02 13:57:33 +0200 | [diff] [blame] | 41 | */ |
Matthieu Moy | e294030 | 2010-09-02 13:57:34 +0200 | [diff] [blame] | 42 | void setup_unpack_trees_porcelain(struct unpack_trees_options *opts, |
| 43 | const char *cmd); |
Matthieu Moy | dc1166e | 2010-09-02 13:57:33 +0200 | [diff] [blame] | 44 | |
Martin Ågren | 1c41d28 | 2018-05-21 16:54:28 +0200 | [diff] [blame] | 45 | /* |
| 46 | * Frees resources allocated by setup_unpack_trees_porcelain(). |
| 47 | */ |
| 48 | void clear_unpack_trees_porcelain(struct unpack_trees_options *opts); |
| 49 | |
Elijah Newren | 480d3d6 | 2021-09-27 16:33:44 +0000 | [diff] [blame] | 50 | enum 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 Schindelin | 16da134 | 2006-07-30 20:25:18 +0200 | [diff] [blame] | 57 | struct unpack_trees_options { |
Elijah Newren | 480d3d6 | 2021-09-27 16:33:44 +0000 | [diff] [blame] | 58 | unsigned int merge, |
Stephen Boyd | 5a56da5 | 2009-06-25 22:14:10 -0700 | [diff] [blame] | 59 | update, |
Elijah Newren | 04988c8 | 2021-09-27 16:33:41 +0000 | [diff] [blame] | 60 | preserve_ignored, |
Duy Nguyen | b878579 | 2018-08-17 20:00:39 +0200 | [diff] [blame] | 61 | clone, |
Stephen Boyd | 5a56da5 | 2009-06-25 22:14:10 -0700 | [diff] [blame] | 62 | index_only, |
Stephen Boyd | 5a56da5 | 2009-06-25 22:14:10 -0700 | [diff] [blame] | 63 | trivial_merges_only, |
| 64 | verbose_update, |
| 65 | aggressive, |
| 66 | skip_unmerged, |
| 67 | initial_checkout, |
| 68 | diff_index_cached, |
Nguyễn Thái Ngọc Duy | 08aefc9 | 2009-08-20 20:47:08 +0700 | [diff] [blame] | 69 | skip_sparse_checkout, |
Nguyễn Thái Ngọc Duy | b165fac | 2019-03-22 16:31:36 +0700 | [diff] [blame] | 70 | quiet, |
Junio C Hamano | b419482 | 2011-05-31 10:06:44 -0700 | [diff] [blame] | 71 | exiting_early, |
Victoria Dye | 68fcd48 | 2022-11-10 19:06:02 +0000 | [diff] [blame] | 72 | dry_run, |
| 73 | skip_cache_tree_update; |
Elijah Newren | 480d3d6 | 2021-09-27 16:33:44 +0000 | [diff] [blame] | 74 | enum unpack_trees_reset_type reset; |
Johannes Schindelin | 16da134 | 2006-07-30 20:25:18 +0200 | [diff] [blame] | 75 | const char *prefix; |
Ævar Arnfjörð Bjarmason | 4002ec3 | 2022-12-20 13:39:56 +0100 | [diff] [blame] | 76 | const char *super_prefix; |
Junio C Hamano | 40e3725 | 2011-08-29 12:31:06 -0700 | [diff] [blame] | 77 | struct pathspec *pathspec; |
Johannes Schindelin | 16da134 | 2006-07-30 20:25:18 +0200 | [diff] [blame] | 78 | merge_fn_t fn; |
| 79 | |
| 80 | int head_idx; |
Johannes Schindelin | 16da134 | 2006-07-30 20:25:18 +0200 | [diff] [blame] | 81 | |
Elijah Newren | f297424 | 2023-02-27 15:28:20 +0000 | [diff] [blame] | 82 | struct cache_entry *df_conflict_entry; /* output only */ |
Linus Torvalds | d1f2d7e | 2008-01-19 17:27:12 -0800 | [diff] [blame] | 83 | void *unpack_data; |
Linus Torvalds | 34110cd | 2008-03-06 18:12:28 -0800 | [diff] [blame] | 84 | |
| 85 | struct index_state *dst_index; |
Linus Torvalds | 32260ad | 2008-03-22 09:35:59 -0700 | [diff] [blame] | 86 | struct index_state *src_index; |
Nguyễn Thái Ngọc Duy | 08aefc9 | 2009-08-20 20:47:08 +0700 | [diff] [blame] | 87 | |
brian m. carlson | 13e7ed6 | 2020-03-16 18:05:04 +0000 | [diff] [blame] | 88 | struct checkout_metadata meta; |
Elijah Newren | 576de3d | 2023-02-27 15:28:16 +0000 | [diff] [blame] | 89 | |
| 90 | struct unpack_trees_options_internal { |
Elijah Newren | 13e1fd6 | 2023-02-27 15:28:17 +0000 | [diff] [blame] | 91 | unsigned int nontrivial_merge, |
Elijah Newren | 1ca13dd | 2023-02-27 15:28:19 +0000 | [diff] [blame] | 92 | show_all_errors, |
| 93 | debug_unpack; /* used by read-tree debugging */ |
Elijah Newren | 13e1fd6 | 2023-02-27 15:28:17 +0000 | [diff] [blame] | 94 | |
Elijah Newren | 1ca13dd | 2023-02-27 15:28:19 +0000 | [diff] [blame] | 95 | int merge_size; /* used by read-tree debugging */ |
Elijah Newren | 13e1fd6 | 2023-02-27 15:28:17 +0000 | [diff] [blame] | 96 | 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 Newren | 576de3d | 2023-02-27 15:28:16 +0000 | [diff] [blame] | 108 | struct pattern_list *pl; |
| 109 | struct dir_struct *dir; |
| 110 | } internal; |
Johannes Schindelin | 16da134 | 2006-07-30 20:25:18 +0200 | [diff] [blame] | 111 | }; |
| 112 | |
Nguyễn Thái Ngọc Duy | 340f4bc | 2018-08-13 18:14:25 +0200 | [diff] [blame] | 113 | int unpack_trees(unsigned n, struct tree_desc *t, |
| 114 | struct unpack_trees_options *options); |
Johannes Schindelin | 16da134 | 2006-07-30 20:25:18 +0200 | [diff] [blame] | 115 | |
Elijah Newren | 7af7a25 | 2020-03-27 00:48:52 +0000 | [diff] [blame] | 116 | enum 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 Newren | 1147c56 | 2023-02-27 15:28:14 +0000 | [diff] [blame] | 123 | enum update_sparsity_result update_sparsity(struct unpack_trees_options *options, |
| 124 | struct pattern_list *pl); |
Elijah Newren | 7af7a25 | 2020-03-27 00:48:52 +0000 | [diff] [blame] | 125 | |
Elijah Newren | 64b1abe | 2018-04-19 10:58:12 -0700 | [diff] [blame] | 126 | int verify_uptodate(const struct cache_entry *ce, |
| 127 | struct unpack_trees_options *o); |
| 128 | |
René Scharfe | 5828e83 | 2013-06-02 17:46:56 +0200 | [diff] [blame] | 129 | int threeway_merge(const struct cache_entry * const *stages, |
| 130 | struct unpack_trees_options *o); |
| 131 | int twoway_merge(const struct cache_entry * const *src, |
| 132 | struct unpack_trees_options *o); |
| 133 | int bind_merge(const struct cache_entry * const *src, |
| 134 | struct unpack_trees_options *o); |
| 135 | int oneway_merge(const struct cache_entry * const *src, |
| 136 | struct unpack_trees_options *o); |
Denton Liu | d3c7bf7 | 2021-03-03 03:16:42 -0800 | [diff] [blame] | 137 | int stash_worktree_untracked_merge(const struct cache_entry * const *src, |
| 138 | struct unpack_trees_options *o); |
Johannes Schindelin | 076b0ad | 2006-07-30 20:26:15 +0200 | [diff] [blame] | 139 | |
Johannes Schindelin | 16da134 | 2006-07-30 20:25:18 +0200 | [diff] [blame] | 140 | #endif |