blob: 71ffb7eeb0c0d1df8539cdff4d6383116d4ff1b4 [file] [log] [blame]
Johannes Schindelin16da1342006-07-30 20:25:18 +02001#ifndef UNPACK_TREES_H
2#define UNPACK_TREES_H
3
Elijah Newrenef3ca952018-08-15 10:54:05 -07004#include "cache.h"
Jeff Kingdbbcd442020-07-28 16:23:39 -04005#include "strvec.h"
Elijah Newrenef3ca952018-08-15 10:54:05 -07006#include "string-list.h"
7#include "tree-walk.h"
Clemens Buchacher79808722010-11-15 20:52:19 +01008
Jeff King5290d452020-02-01 06:39:22 -05009#define MAX_UNPACK_TREES MAX_TRAVERSE_TREES
Junio C Hamanoca885a42008-03-13 22:07:18 -070010
Elijah Newrenef3ca952018-08-15 10:54:05 -070011struct cache_entry;
Johannes Schindelin16da1342006-07-30 20:25:18 +020012struct unpack_trees_options;
Derrick Stoleecaa3d552019-09-03 11:04:56 -070013struct pattern_list;
Johannes Schindelin16da1342006-07-30 20:25:18 +020014
René Scharfe5828e832013-06-02 17:46:56 +020015typedef int (*merge_fn_t)(const struct cache_entry * const *src,
Linus Torvalds34110cd2008-03-06 18:12:28 -080016 struct unpack_trees_options *options);
Johannes Schindelin16da1342006-07-30 20:25:18 +020017
Matthieu Moy08353eb2010-08-11 10:38:04 +020018enum unpack_trees_error_types {
19 ERROR_WOULD_OVERWRITE = 0,
20 ERROR_NOT_UPTODATE_FILE,
21 ERROR_NOT_UPTODATE_DIR,
Matthieu Moy08402b02010-08-11 10:38:06 +020022 ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN,
23 ERROR_WOULD_LOSE_UNTRACKED_REMOVED,
Matthieu Moy08353eb2010-08-11 10:38:04 +020024 ERROR_BIND_OVERLAP,
Stefan Bellera7bc8452017-03-14 14:46:39 -070025 ERROR_WOULD_LOSE_SUBMODULE,
Elijah Newren1ac83f42020-03-27 00:48:56 +000026
Elijah Newren6271d772020-03-27 00:48:57 +000027 NB_UNPACK_TREES_ERROR_TYPES,
28
Elijah Newren1ac83f42020-03-27 00:48:56 +000029 WARNING_SPARSE_NOT_UPTODATE_FILE,
Elijah Newrenebb568b2020-03-27 00:48:59 +000030 WARNING_SPARSE_UNMERGED_FILE,
Elijah Newren1ac83f42020-03-27 00:48:56 +000031 WARNING_SPARSE_ORPHANED_NOT_OVERWRITTEN,
32
Elijah Newren6271d772020-03-27 00:48:57 +000033 NB_UNPACK_TREES_WARNING_TYPES,
Junio C Hamano8ccba002008-05-17 12:03:49 -070034};
35
Matthieu Moydc1166e2010-09-02 13:57:33 +020036/*
37 * Sets the list of user-friendly error messages to be used by the
Matthieu Moy5e65ee32010-09-02 18:08:15 +020038 * command "cmd" (either merge or checkout), and show_all_errors to 1.
Matthieu Moydc1166e2010-09-02 13:57:33 +020039 */
Matthieu Moye2940302010-09-02 13:57:34 +020040void setup_unpack_trees_porcelain(struct unpack_trees_options *opts,
41 const char *cmd);
Matthieu Moydc1166e2010-09-02 13:57:33 +020042
Martin Ågren1c41d282018-05-21 16:54:28 +020043/*
44 * Frees resources allocated by setup_unpack_trees_porcelain().
45 */
46void clear_unpack_trees_porcelain(struct unpack_trees_options *opts);
47
Elijah Newren480d3d62021-09-27 16:33:44 +000048enum 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 Schindelin16da1342006-07-30 20:25:18 +020055struct unpack_trees_options {
Elijah Newren480d3d62021-09-27 16:33:44 +000056 unsigned int merge,
Stephen Boyd5a56da52009-06-25 22:14:10 -070057 update,
Elijah Newren04988c82021-09-27 16:33:41 +000058 preserve_ignored,
Duy Nguyenb8785792018-08-17 20:00:39 +020059 clone,
Stephen Boyd5a56da52009-06-25 22:14:10 -070060 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 Hamanoba655da2009-09-14 02:22:00 -070068 debug_unpack,
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,
Jens Lehmann2c9078d2011-05-25 22:07:51 +020072 show_all_errors,
Elijah Newrenfa0bde42020-03-27 00:48:47 +000073 dry_run;
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;
Junio C Hamanoda165f42010-01-07 14:59:54 -080076 int cache_bottom;
Junio C Hamano40e37252011-08-29 12:31:06 -070077 struct pathspec *pathspec;
Johannes Schindelin16da1342006-07-30 20:25:18 +020078 merge_fn_t fn;
Elijah Newren6271d772020-03-27 00:48:57 +000079 const char *msgs[NB_UNPACK_TREES_WARNING_TYPES];
Jeff Kingc972bf42020-07-28 16:25:12 -040080 struct strvec msgs_to_free;
Matthieu Moye6c111b2010-08-11 10:38:07 +020081 /*
82 * Store error messages in an array, each case
83 * corresponding to a error message type
84 */
Elijah Newren6271d772020-03-27 00:48:57 +000085 struct string_list unpack_rejects[NB_UNPACK_TREES_WARNING_TYPES];
Johannes Schindelin16da1342006-07-30 20:25:18 +020086
87 int head_idx;
88 int merge_size;
89
90 struct cache_entry *df_conflict_entry;
Linus Torvaldsd1f2d7e2008-01-19 17:27:12 -080091 void *unpack_data;
Linus Torvalds34110cd2008-03-06 18:12:28 -080092
93 struct index_state *dst_index;
Linus Torvalds32260ad2008-03-22 09:35:59 -070094 struct index_state *src_index;
Linus Torvalds34110cd2008-03-06 18:12:28 -080095 struct index_state result;
Nguyễn Thái Ngọc Duy08aefc92009-08-20 20:47:08 +070096
Derrick Stoleecaa3d552019-09-03 11:04:56 -070097 struct pattern_list *pl; /* for internal use */
Elijah Newrenc42e0b62021-09-27 16:33:42 +000098 struct dir_struct *dir; /* for internal use only */
brian m. carlson13e7ed62020-03-16 18:05:04 +000099 struct checkout_metadata meta;
Johannes Schindelin16da1342006-07-30 20:25:18 +0200100};
101
Nguyễn Thái Ngọc Duy340f4bc2018-08-13 18:14:25 +0200102int unpack_trees(unsigned n, struct tree_desc *t,
103 struct unpack_trees_options *options);
Johannes Schindelin16da1342006-07-30 20:25:18 +0200104
Elijah Newren7af7a252020-03-27 00:48:52 +0000105enum 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
112enum update_sparsity_result update_sparsity(struct unpack_trees_options *options);
113
Elijah Newren64b1abe2018-04-19 10:58:12 -0700114int verify_uptodate(const struct cache_entry *ce,
115 struct unpack_trees_options *o);
116
René Scharfe5828e832013-06-02 17:46:56 +0200117int threeway_merge(const struct cache_entry * const *stages,
118 struct unpack_trees_options *o);
119int twoway_merge(const struct cache_entry * const *src,
120 struct unpack_trees_options *o);
121int bind_merge(const struct cache_entry * const *src,
122 struct unpack_trees_options *o);
123int oneway_merge(const struct cache_entry * const *src,
124 struct unpack_trees_options *o);
Denton Liud3c7bf72021-03-03 03:16:42 -0800125int stash_worktree_untracked_merge(const struct cache_entry * const *src,
126 struct unpack_trees_options *o);
Johannes Schindelin076b0ad2006-07-30 20:26:15 +0200127
Johannes Schindelin16da1342006-07-30 20:25:18 +0200128#endif