| 1 | #ifndef UNPACK_TREES_H |
| 2 | #define UNPACK_TREES_H |
| 3 | |
| 4 | #include "convert.h" |
| 5 | #include "read-cache-ll.h" |
| 6 | #include "strvec.h" |
| 7 | #include "string-list.h" |
| 8 | #include "tree-walk.h" |
| 9 | |
| 10 | #define MAX_UNPACK_TREES 8 |
| 11 | |
| 12 | struct cache_entry; |
| 13 | struct unpack_trees_options; |
| 14 | struct pattern_list; |
| 15 | |
| 16 | typedef int (*merge_fn_t)(const struct cache_entry * const *src, |
| 17 | struct unpack_trees_options *options); |
| 18 | |
| 19 | enum unpack_trees_error_types { |
| 20 | ERROR_WOULD_OVERWRITE = 0, |
| 21 | ERROR_NOT_UPTODATE_FILE, |
| 22 | ERROR_NOT_UPTODATE_DIR, |
| 23 | ERROR_CWD_IN_THE_WAY, |
| 24 | ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN, |
| 25 | ERROR_WOULD_LOSE_UNTRACKED_REMOVED, |
| 26 | ERROR_BIND_OVERLAP, |
| 27 | ERROR_WOULD_LOSE_SUBMODULE, |
| 28 | |
| 29 | NB_UNPACK_TREES_ERROR_TYPES, |
| 30 | |
| 31 | WARNING_SPARSE_NOT_UPTODATE_FILE, |
| 32 | WARNING_SPARSE_UNMERGED_FILE, |
| 33 | WARNING_SPARSE_ORPHANED_NOT_OVERWRITTEN, |
| 34 | |
| 35 | NB_UNPACK_TREES_WARNING_TYPES, |
| 36 | }; |
| 37 | |
| 38 | /* |
| 39 | * Sets the list of user-friendly error messages to be used by the |
| 40 | * command "cmd" (either merge or checkout), and show_all_errors to 1. |
| 41 | */ |
| 42 | void setup_unpack_trees_porcelain(struct unpack_trees_options *opts, |
| 43 | const char *cmd); |
| 44 | |
| 45 | /* |
| 46 | * Frees resources allocated by setup_unpack_trees_porcelain(). |
| 47 | */ |
| 48 | void clear_unpack_trees_porcelain(struct unpack_trees_options *opts); |
| 49 | |
| 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 | |
| 57 | struct unpack_trees_options { |
| 58 | unsigned int merge, |
| 59 | update, |
| 60 | preserve_ignored, |
| 61 | clone, |
| 62 | index_only, |
| 63 | trivial_merges_only, |
| 64 | verbose_update, |
| 65 | aggressive, |
| 66 | skip_unmerged, |
| 67 | initial_checkout, |
| 68 | diff_index_cached, |
| 69 | skip_sparse_checkout, |
| 70 | quiet, |
| 71 | exiting_early, |
| 72 | dry_run, |
| 73 | skip_cache_tree_update; |
| 74 | enum unpack_trees_reset_type reset; |
| 75 | const char *prefix; |
| 76 | const char *super_prefix; |
| 77 | struct pathspec *pathspec; |
| 78 | merge_fn_t fn; |
| 79 | |
| 80 | int head_idx; |
| 81 | |
| 82 | struct cache_entry *df_conflict_entry; /* output only */ |
| 83 | void *unpack_data; |
| 84 | |
| 85 | struct index_state *dst_index; |
| 86 | struct index_state *src_index; |
| 87 | |
| 88 | struct checkout_metadata meta; |
| 89 | |
| 90 | struct unpack_trees_options_internal { |
| 91 | unsigned int nontrivial_merge, |
| 92 | show_all_errors, |
| 93 | debug_unpack; /* used by read-tree debugging */ |
| 94 | |
| 95 | int merge_size; /* used by read-tree debugging */ |
| 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 | |
| 108 | struct pattern_list *pl; |
| 109 | struct dir_struct *dir; |
| 110 | } internal; |
| 111 | }; |
| 112 | |
| 113 | int unpack_trees(unsigned n, struct tree_desc *t, |
| 114 | struct unpack_trees_options *options); |
| 115 | |
| 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 | |
| 123 | enum update_sparsity_result update_sparsity(struct unpack_trees_options *options, |
| 124 | struct pattern_list *pl); |
| 125 | |
| 126 | int verify_uptodate(const struct cache_entry *ce, |
| 127 | struct unpack_trees_options *o); |
| 128 | |
| 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); |
| 137 | int stash_worktree_untracked_merge(const struct cache_entry * const *src, |
| 138 | struct unpack_trees_options *o); |
| 139 | |
| 140 | #endif |