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 | ef3ca95 | 2018-08-15 10:54:05 -0700 | [diff] [blame] | 4 | #include "cache.h" |
Jeff King | dbbcd44 | 2020-07-28 16:23:39 -0400 | [diff] [blame] | 5 | #include "strvec.h" |
Elijah Newren | ef3ca95 | 2018-08-15 10:54:05 -0700 | [diff] [blame] | 6 | #include "string-list.h" |
| 7 | #include "tree-walk.h" |
Clemens Buchacher | 7980872 | 2010-11-15 20:52:19 +0100 | [diff] [blame] | 8 | |
Jeff King | 5290d45 | 2020-02-01 06:39:22 -0500 | [diff] [blame] | 9 | #define MAX_UNPACK_TREES MAX_TRAVERSE_TREES |
Junio C Hamano | ca885a4 | 2008-03-13 22:07:18 -0700 | [diff] [blame] | 10 | |
Elijah Newren | ef3ca95 | 2018-08-15 10:54:05 -0700 | [diff] [blame] | 11 | struct cache_entry; |
Johannes Schindelin | 16da134 | 2006-07-30 20:25:18 +0200 | [diff] [blame] | 12 | struct unpack_trees_options; |
Derrick Stolee | caa3d55 | 2019-09-03 11:04:56 -0700 | [diff] [blame] | 13 | struct pattern_list; |
Johannes Schindelin | 16da134 | 2006-07-30 20:25:18 +0200 | [diff] [blame] | 14 | |
René Scharfe | 5828e83 | 2013-06-02 17:46:56 +0200 | [diff] [blame] | 15 | typedef int (*merge_fn_t)(const struct cache_entry * const *src, |
Linus Torvalds | 34110cd | 2008-03-06 18:12:28 -0800 | [diff] [blame] | 16 | struct unpack_trees_options *options); |
Johannes Schindelin | 16da134 | 2006-07-30 20:25:18 +0200 | [diff] [blame] | 17 | |
Matthieu Moy | 08353eb | 2010-08-11 10:38:04 +0200 | [diff] [blame] | 18 | enum unpack_trees_error_types { |
| 19 | ERROR_WOULD_OVERWRITE = 0, |
| 20 | ERROR_NOT_UPTODATE_FILE, |
| 21 | ERROR_NOT_UPTODATE_DIR, |
Matthieu Moy | 08402b0 | 2010-08-11 10:38:06 +0200 | [diff] [blame] | 22 | ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN, |
| 23 | ERROR_WOULD_LOSE_UNTRACKED_REMOVED, |
Matthieu Moy | 08353eb | 2010-08-11 10:38:04 +0200 | [diff] [blame] | 24 | ERROR_BIND_OVERLAP, |
Stefan Beller | a7bc845 | 2017-03-14 14:46:39 -0700 | [diff] [blame] | 25 | ERROR_WOULD_LOSE_SUBMODULE, |
Elijah Newren | 1ac83f4 | 2020-03-27 00:48:56 +0000 | [diff] [blame] | 26 | |
Elijah Newren | 6271d77 | 2020-03-27 00:48:57 +0000 | [diff] [blame] | 27 | NB_UNPACK_TREES_ERROR_TYPES, |
| 28 | |
Elijah Newren | 1ac83f4 | 2020-03-27 00:48:56 +0000 | [diff] [blame] | 29 | WARNING_SPARSE_NOT_UPTODATE_FILE, |
Elijah Newren | ebb568b | 2020-03-27 00:48:59 +0000 | [diff] [blame] | 30 | WARNING_SPARSE_UNMERGED_FILE, |
Elijah Newren | 1ac83f4 | 2020-03-27 00:48:56 +0000 | [diff] [blame] | 31 | WARNING_SPARSE_ORPHANED_NOT_OVERWRITTEN, |
| 32 | |
Elijah Newren | 6271d77 | 2020-03-27 00:48:57 +0000 | [diff] [blame] | 33 | NB_UNPACK_TREES_WARNING_TYPES, |
Junio C Hamano | 8ccba00 | 2008-05-17 12:03:49 -0700 | [diff] [blame] | 34 | }; |
| 35 | |
Matthieu Moy | dc1166e | 2010-09-02 13:57:33 +0200 | [diff] [blame] | 36 | /* |
| 37 | * 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] | 38 | * command "cmd" (either merge or checkout), and show_all_errors to 1. |
Matthieu Moy | dc1166e | 2010-09-02 13:57:33 +0200 | [diff] [blame] | 39 | */ |
Matthieu Moy | e294030 | 2010-09-02 13:57:34 +0200 | [diff] [blame] | 40 | void setup_unpack_trees_porcelain(struct unpack_trees_options *opts, |
| 41 | const char *cmd); |
Matthieu Moy | dc1166e | 2010-09-02 13:57:33 +0200 | [diff] [blame] | 42 | |
Martin Ågren | 1c41d28 | 2018-05-21 16:54:28 +0200 | [diff] [blame] | 43 | /* |
| 44 | * Frees resources allocated by setup_unpack_trees_porcelain(). |
| 45 | */ |
| 46 | void clear_unpack_trees_porcelain(struct unpack_trees_options *opts); |
| 47 | |
Elijah Newren | 480d3d6 | 2021-09-27 16:33:44 +0000 | [diff] [blame] | 48 | enum unpack_trees_reset_type { |
| 49 | UNPACK_RESET_NONE = 0, /* traditional "false" value; still valid */ |
| 50 | UNPACK_RESET_INVALID = 1, /* "true" no longer valid; use below values */ |
| 51 | UNPACK_RESET_PROTECT_UNTRACKED, |
| 52 | UNPACK_RESET_OVERWRITE_UNTRACKED |
| 53 | }; |
| 54 | |
Johannes Schindelin | 16da134 | 2006-07-30 20:25:18 +0200 | [diff] [blame] | 55 | struct unpack_trees_options { |
Elijah Newren | 480d3d6 | 2021-09-27 16:33:44 +0000 | [diff] [blame] | 56 | unsigned int merge, |
Stephen Boyd | 5a56da5 | 2009-06-25 22:14:10 -0700 | [diff] [blame] | 57 | update, |
Elijah Newren | 04988c8 | 2021-09-27 16:33:41 +0000 | [diff] [blame] | 58 | preserve_ignored, |
Duy Nguyen | b878579 | 2018-08-17 20:00:39 +0200 | [diff] [blame] | 59 | clone, |
Stephen Boyd | 5a56da5 | 2009-06-25 22:14:10 -0700 | [diff] [blame] | 60 | index_only, |
| 61 | nontrivial_merge, |
| 62 | trivial_merges_only, |
| 63 | verbose_update, |
| 64 | aggressive, |
| 65 | skip_unmerged, |
| 66 | initial_checkout, |
| 67 | diff_index_cached, |
Junio C Hamano | ba655da | 2009-09-14 02:22:00 -0700 | [diff] [blame] | 68 | debug_unpack, |
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, |
Jens Lehmann | 2c9078d | 2011-05-25 22:07:51 +0200 | [diff] [blame] | 72 | show_all_errors, |
Elijah Newren | fa0bde4 | 2020-03-27 00:48:47 +0000 | [diff] [blame] | 73 | dry_run; |
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; |
Junio C Hamano | da165f4 | 2010-01-07 14:59:54 -0800 | [diff] [blame] | 76 | int cache_bottom; |
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; |
Elijah Newren | 6271d77 | 2020-03-27 00:48:57 +0000 | [diff] [blame] | 79 | const char *msgs[NB_UNPACK_TREES_WARNING_TYPES]; |
Jeff King | c972bf4 | 2020-07-28 16:25:12 -0400 | [diff] [blame] | 80 | struct strvec msgs_to_free; |
Matthieu Moy | e6c111b | 2010-08-11 10:38:07 +0200 | [diff] [blame] | 81 | /* |
| 82 | * Store error messages in an array, each case |
| 83 | * corresponding to a error message type |
| 84 | */ |
Elijah Newren | 6271d77 | 2020-03-27 00:48:57 +0000 | [diff] [blame] | 85 | struct string_list unpack_rejects[NB_UNPACK_TREES_WARNING_TYPES]; |
Johannes Schindelin | 16da134 | 2006-07-30 20:25:18 +0200 | [diff] [blame] | 86 | |
| 87 | int head_idx; |
| 88 | int merge_size; |
| 89 | |
| 90 | struct cache_entry *df_conflict_entry; |
Linus Torvalds | d1f2d7e | 2008-01-19 17:27:12 -0800 | [diff] [blame] | 91 | void *unpack_data; |
Linus Torvalds | 34110cd | 2008-03-06 18:12:28 -0800 | [diff] [blame] | 92 | |
| 93 | struct index_state *dst_index; |
Linus Torvalds | 32260ad | 2008-03-22 09:35:59 -0700 | [diff] [blame] | 94 | struct index_state *src_index; |
Linus Torvalds | 34110cd | 2008-03-06 18:12:28 -0800 | [diff] [blame] | 95 | struct index_state result; |
Nguyễn Thái Ngọc Duy | 08aefc9 | 2009-08-20 20:47:08 +0700 | [diff] [blame] | 96 | |
Derrick Stolee | caa3d55 | 2019-09-03 11:04:56 -0700 | [diff] [blame] | 97 | struct pattern_list *pl; /* for internal use */ |
Elijah Newren | c42e0b6 | 2021-09-27 16:33:42 +0000 | [diff] [blame] | 98 | struct dir_struct *dir; /* for internal use only */ |
brian m. carlson | 13e7ed6 | 2020-03-16 18:05:04 +0000 | [diff] [blame] | 99 | struct checkout_metadata meta; |
Johannes Schindelin | 16da134 | 2006-07-30 20:25:18 +0200 | [diff] [blame] | 100 | }; |
| 101 | |
Nguyễn Thái Ngọc Duy | 340f4bc | 2018-08-13 18:14:25 +0200 | [diff] [blame] | 102 | int unpack_trees(unsigned n, struct tree_desc *t, |
| 103 | struct unpack_trees_options *options); |
Johannes Schindelin | 16da134 | 2006-07-30 20:25:18 +0200 | [diff] [blame] | 104 | |
Elijah Newren | 7af7a25 | 2020-03-27 00:48:52 +0000 | [diff] [blame] | 105 | enum update_sparsity_result { |
| 106 | UPDATE_SPARSITY_SUCCESS = 0, |
| 107 | UPDATE_SPARSITY_WARNINGS = 1, |
| 108 | UPDATE_SPARSITY_INDEX_UPDATE_FAILURES = -1, |
| 109 | UPDATE_SPARSITY_WORKTREE_UPDATE_FAILURES = -2 |
| 110 | }; |
| 111 | |
| 112 | enum update_sparsity_result update_sparsity(struct unpack_trees_options *options); |
| 113 | |
Elijah Newren | 64b1abe | 2018-04-19 10:58:12 -0700 | [diff] [blame] | 114 | int verify_uptodate(const struct cache_entry *ce, |
| 115 | struct unpack_trees_options *o); |
| 116 | |
René Scharfe | 5828e83 | 2013-06-02 17:46:56 +0200 | [diff] [blame] | 117 | int threeway_merge(const struct cache_entry * const *stages, |
| 118 | struct unpack_trees_options *o); |
| 119 | int twoway_merge(const struct cache_entry * const *src, |
| 120 | struct unpack_trees_options *o); |
| 121 | int bind_merge(const struct cache_entry * const *src, |
| 122 | struct unpack_trees_options *o); |
| 123 | int oneway_merge(const struct cache_entry * const *src, |
| 124 | struct unpack_trees_options *o); |
Denton Liu | d3c7bf7 | 2021-03-03 03:16:42 -0800 | [diff] [blame] | 125 | int stash_worktree_untracked_merge(const struct cache_entry * const *src, |
| 126 | struct unpack_trees_options *o); |
Johannes Schindelin | 076b0ad | 2006-07-30 20:26:15 +0200 | [diff] [blame] | 127 | |
Johannes Schindelin | 16da134 | 2006-07-30 20:25:18 +0200 | [diff] [blame] | 128 | #endif |