Blame


1 86c3caaf 2018-03-09 stsp /*
2 5d56da81 2019-01-13 stsp * Copyright (c) 2018, 2019 Stefan Sperling <stsp@openbsd.org>
3 86c3caaf 2018-03-09 stsp *
4 86c3caaf 2018-03-09 stsp * Permission to use, copy, modify, and distribute this software for any
5 86c3caaf 2018-03-09 stsp * purpose with or without fee is hereby granted, provided that the above
6 86c3caaf 2018-03-09 stsp * copyright notice and this permission notice appear in all copies.
7 86c3caaf 2018-03-09 stsp *
8 86c3caaf 2018-03-09 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 86c3caaf 2018-03-09 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 86c3caaf 2018-03-09 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 86c3caaf 2018-03-09 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 86c3caaf 2018-03-09 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 86c3caaf 2018-03-09 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 86c3caaf 2018-03-09 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 86c3caaf 2018-03-09 stsp */
16 86c3caaf 2018-03-09 stsp
17 86c3caaf 2018-03-09 stsp struct got_worktree;
18 8656d6c4 2019-05-20 stsp struct got_commitable;
19 818c7501 2019-07-11 stsp struct got_commit_object;
20 3e3a69f1 2019-07-25 stsp struct got_fileindex;
21 86c3caaf 2018-03-09 stsp
22 eecfbcd1 2018-12-29 stsp /* status codes */
23 f8d1f275 2019-02-04 stsp #define GOT_STATUS_NO_CHANGE ' '
24 eecfbcd1 2018-12-29 stsp #define GOT_STATUS_ADD 'A'
25 eecfbcd1 2018-12-29 stsp #define GOT_STATUS_EXISTS 'E'
26 507dc3bb 2018-12-29 stsp #define GOT_STATUS_UPDATE 'U'
27 512f0d0e 2019-01-02 stsp #define GOT_STATUS_DELETE 'D'
28 276262e8 2019-02-08 stsp #define GOT_STATUS_MODIFY 'M'
29 1ebedb77 2019-10-19 stsp #define GOT_STATUS_MODE_CHANGE 'm'
30 6353ad76 2019-02-08 stsp #define GOT_STATUS_CONFLICT 'C'
31 6353ad76 2019-02-08 stsp #define GOT_STATUS_MERGE 'G'
32 f8d1f275 2019-02-04 stsp #define GOT_STATUS_MISSING '!'
33 f8d1f275 2019-02-04 stsp #define GOT_STATUS_UNVERSIONED '?'
34 0dbc2271 2019-02-05 stsp #define GOT_STATUS_OBSTRUCTED '~'
35 2a06fe5f 2019-08-24 stsp #define GOT_STATUS_NONEXISTENT 'N'
36 a129376b 2019-03-28 stsp #define GOT_STATUS_REVERT 'R'
37 2b92fad7 2019-06-02 stsp #define GOT_STATUS_CANNOT_DELETE 'd'
38 a484d721 2019-06-10 stsp #define GOT_STATUS_BUMP_BASE 'b'
39 7f47418f 2019-12-20 stsp #define GOT_STATUS_BASE_REF_ERR 'B'
40 5036ab18 2020-04-18 stsp #define GOT_STATUS_CANNOT_UPDATE '#'
41 eecfbcd1 2018-12-29 stsp
42 0c60ce5a 2018-04-02 stsp /*
43 0c60ce5a 2018-04-02 stsp * Attempt to initialize a new work tree on disk.
44 0c60ce5a 2018-04-02 stsp * The first argument is the path to a directory where the work tree
45 0c60ce5a 2018-04-02 stsp * will be created. The path itself must not yet exist, but the dirname(3)
46 0c60ce5a 2018-04-02 stsp * of the path must already exist.
47 93a30277 2018-12-24 stsp * The reference provided will be used to determine the new worktree's
48 93a30277 2018-12-24 stsp * base commit. The third argument speficies the work tree's path prefix.
49 0c60ce5a 2018-04-02 stsp */
50 86c3caaf 2018-03-09 stsp const struct got_error *got_worktree_init(const char *, struct got_reference *,
51 577ec78f 2018-03-11 stsp const char *, struct got_repository *);
52 0c60ce5a 2018-04-02 stsp
53 0c60ce5a 2018-04-02 stsp /*
54 247140b2 2019-02-05 stsp * Attempt to open a worktree at or above the specified path.
55 0c60ce5a 2018-04-02 stsp * The caller must dispose of it with got_worktree_close().
56 0c60ce5a 2018-04-02 stsp */
57 86c3caaf 2018-03-09 stsp const struct got_error *got_worktree_open(struct got_worktree **, const char *);
58 0c60ce5a 2018-04-02 stsp
59 0c60ce5a 2018-04-02 stsp /* Dispose of an open work tree. */
60 3a6ce05a 2019-02-11 stsp const struct got_error *got_worktree_close(struct got_worktree *);
61 0c60ce5a 2018-04-02 stsp
62 0c60ce5a 2018-04-02 stsp /*
63 c7f4312f 2019-02-05 stsp * Get the path to the root directory of a worktree.
64 c7f4312f 2019-02-05 stsp */
65 c7f4312f 2019-02-05 stsp const char *got_worktree_get_root_path(struct got_worktree *);
66 c7f4312f 2019-02-05 stsp
67 c7f4312f 2019-02-05 stsp /*
68 0c60ce5a 2018-04-02 stsp * Get the path to the repository associated with a worktree.
69 0c60ce5a 2018-04-02 stsp */
70 2fbdb5ae 2018-12-29 stsp const char *got_worktree_get_repo_path(struct got_worktree *);
71 0c60ce5a 2018-04-02 stsp
72 0c60ce5a 2018-04-02 stsp /*
73 49520a32 2018-12-29 stsp * Get the path prefix associated with a worktree.
74 49520a32 2018-12-29 stsp */
75 49520a32 2018-12-29 stsp const char *got_worktree_get_path_prefix(struct got_worktree *);
76 b2118c49 2020-07-28 stsp
77 b2118c49 2020-07-28 stsp /*
78 b2118c49 2020-07-28 stsp * Get the UUID of a work tree as a string.
79 b2118c49 2020-07-28 stsp * The caller must dispose of the returned UUID string with free(3).
80 b2118c49 2020-07-28 stsp */
81 b2118c49 2020-07-28 stsp const struct got_error *got_worktree_get_uuid(char **, struct got_worktree *);
82 49520a32 2018-12-29 stsp
83 49520a32 2018-12-29 stsp /*
84 e5dc7198 2018-12-29 stsp * Check if a user-provided path prefix matches that of the worktree.
85 e5dc7198 2018-12-29 stsp */
86 e5dc7198 2018-12-29 stsp const struct got_error *got_worktree_match_path_prefix(int *,
87 e5dc7198 2018-12-29 stsp struct got_worktree *, const char *);
88 e5dc7198 2018-12-29 stsp
89 e5dc7198 2018-12-29 stsp /*
90 0c60ce5a 2018-04-02 stsp * Get the name of a work tree's HEAD reference.
91 0c60ce5a 2018-04-02 stsp */
92 bc70eb79 2019-05-09 stsp const char *got_worktree_get_head_ref_name(struct got_worktree *);
93 0c60ce5a 2018-04-02 stsp
94 507dc3bb 2018-12-29 stsp /*
95 024e9686 2019-05-14 stsp * Set the branch head reference of the work tree.
96 024e9686 2019-05-14 stsp */
97 024e9686 2019-05-14 stsp const struct got_error *got_worktree_set_head_ref(struct got_worktree *,
98 024e9686 2019-05-14 stsp struct got_reference *);
99 024e9686 2019-05-14 stsp
100 024e9686 2019-05-14 stsp /*
101 507dc3bb 2018-12-29 stsp * Get the current base commit ID of a worktree.
102 507dc3bb 2018-12-29 stsp */
103 b72f483a 2019-02-05 stsp struct got_object_id *got_worktree_get_base_commit_id(struct got_worktree *);
104 507dc3bb 2018-12-29 stsp
105 507dc3bb 2018-12-29 stsp /*
106 507dc3bb 2018-12-29 stsp * Set the base commit Id of a worktree.
107 507dc3bb 2018-12-29 stsp */
108 507dc3bb 2018-12-29 stsp const struct got_error *got_worktree_set_base_commit_id(struct got_worktree *,
109 507dc3bb 2018-12-29 stsp struct got_repository *, struct got_object_id *);
110 50b0790e 2020-09-11 stsp
111 50b0790e 2020-09-11 stsp /*
112 50b0790e 2020-09-11 stsp * Obtain a parsed representation of this worktree's got.conf file.
113 50b0790e 2020-09-11 stsp * Return NULL if this configuration file could not be read.
114 50b0790e 2020-09-11 stsp */
115 50b0790e 2020-09-11 stsp const struct got_gotconfig *got_worktree_get_gotconfig(struct got_worktree *);
116 507dc3bb 2018-12-29 stsp
117 0c60ce5a 2018-04-02 stsp /* A callback function which is invoked when a path is checked out. */
118 1ee397ad 2019-07-12 stsp typedef const struct got_error *(*got_worktree_checkout_cb)(void *,
119 1ee397ad 2019-07-12 stsp unsigned char, const char *);
120 f2a9dc41 2019-12-13 tracey
121 f2a9dc41 2019-12-13 tracey /* A callback function which is invoked when a path is removed. */
122 f2a9dc41 2019-12-13 tracey typedef const struct got_error *(*got_worktree_delete_cb)(void *,
123 f2a9dc41 2019-12-13 tracey unsigned char, unsigned char, const char *);
124 0c60ce5a 2018-04-02 stsp
125 0c60ce5a 2018-04-02 stsp /*
126 0c60ce5a 2018-04-02 stsp * Attempt to check out files into a work tree from its associated repository
127 0c60ce5a 2018-04-02 stsp * and path prefix, and update the work tree's file index accordingly.
128 0c60ce5a 2018-04-02 stsp * File content is obtained from blobs within the work tree's path prefix
129 93a30277 2018-12-24 stsp * inside the tree corresponding to the work tree's base commit.
130 0c60ce5a 2018-04-02 stsp * The checkout progress callback will be invoked with the provided
131 0c60ce5a 2018-04-02 stsp * void * argument, and the path of each checked out file.
132 c4cdcb68 2019-04-03 stsp *
133 f2ea84fa 2019-07-27 stsp * It is possible to restrict the checkout operation to specific paths in
134 f2ea84fa 2019-07-27 stsp * the work tree, in which case all files outside those paths will remain at
135 c4cdcb68 2019-04-03 stsp * their currently recorded base commit. Inconsistent base commits can be
136 c4cdcb68 2019-04-03 stsp * repaired later by running another update operation across the entire work
137 c4cdcb68 2019-04-03 stsp * tree. Inconsistent base-commits may also occur if this function runs into
138 c4cdcb68 2019-04-03 stsp * an error or if the checkout operation is cancelled by the cancel callback.
139 f2ea84fa 2019-07-27 stsp * Allspecified paths are relative to the work tree's root. Pass a pathlist
140 f2ea84fa 2019-07-27 stsp * with a single empty path "" to check out files across the entire work tree.
141 c4cdcb68 2019-04-03 stsp *
142 c4cdcb68 2019-04-03 stsp * Some operations may refuse to run while the work tree contains files from
143 c4cdcb68 2019-04-03 stsp * multiple base commits.
144 0c60ce5a 2018-04-02 stsp */
145 86c3caaf 2018-03-09 stsp const struct got_error *got_worktree_checkout_files(struct got_worktree *,
146 f2ea84fa 2019-07-27 stsp struct got_pathlist_head *, struct got_repository *,
147 e6209546 2019-08-22 stsp got_worktree_checkout_cb, void *, got_cancel_cb, void *);
148 507dc3bb 2018-12-29 stsp
149 234035bc 2019-06-01 stsp /* Merge the differences between two commits into a work tree. */
150 234035bc 2019-06-01 stsp const struct got_error *
151 234035bc 2019-06-01 stsp got_worktree_merge_files(struct got_worktree *,
152 234035bc 2019-06-01 stsp struct got_object_id *, struct got_object_id *,
153 234035bc 2019-06-01 stsp struct got_repository *, got_worktree_checkout_cb, void *,
154 e6209546 2019-08-22 stsp got_cancel_cb, void *);
155 234035bc 2019-06-01 stsp
156 12463d8b 2019-12-13 stsp /*
157 12463d8b 2019-12-13 stsp * A callback function which is invoked to report a file's status.
158 12463d8b 2019-12-13 stsp *
159 12463d8b 2019-12-13 stsp * If a valid directory file descriptor and a directory entry name are passed,
160 12463d8b 2019-12-13 stsp * these should be used to open the file instead of opening the file by path.
161 12463d8b 2019-12-13 stsp * This prevents race conditions if the filesystem is modified concurrently.
162 12463d8b 2019-12-13 stsp * If the directory descriptor is not available then its value will be -1.
163 12463d8b 2019-12-13 stsp */
164 b72f483a 2019-02-05 stsp typedef const struct got_error *(*got_worktree_status_cb)(void *,
165 88d0e355 2019-08-03 stsp unsigned char, unsigned char, const char *, struct got_object_id *,
166 12463d8b 2019-12-13 stsp struct got_object_id *, struct got_object_id *, int, const char *);
167 f8d1f275 2019-02-04 stsp
168 f8d1f275 2019-02-04 stsp /*
169 f8d1f275 2019-02-04 stsp * Report the status of paths in the work tree.
170 f8d1f275 2019-02-04 stsp * The status callback will be invoked with the provided void * argument,
171 f8d1f275 2019-02-04 stsp * a path, and a corresponding status code.
172 f8d1f275 2019-02-04 stsp */
173 6c34b1aa 2019-03-18 stsp const struct got_error *got_worktree_status(struct got_worktree *,
174 f6343036 2021-06-22 stsp struct got_pathlist_head *, struct got_repository *, int no_ignores,
175 e6209546 2019-08-22 stsp got_worktree_status_cb, void *, got_cancel_cb cancel_cb, void *);
176 6c7ab921 2019-03-18 stsp
177 6c7ab921 2019-03-18 stsp /*
178 6c7ab921 2019-03-18 stsp * Try to resolve a user-provided path to an on-disk path in the work tree.
179 6c7ab921 2019-03-18 stsp * The caller must dispose of the resolved path with free(3).
180 6c7ab921 2019-03-18 stsp */
181 6c7ab921 2019-03-18 stsp const struct got_error *got_worktree_resolve_path(char **,
182 6c7ab921 2019-03-18 stsp struct got_worktree *, const char *);
183 d00136be 2019-03-26 stsp
184 1dd54920 2019-05-11 stsp /* Schedule files at on-disk paths for addition in the next commit. */
185 031a5338 2019-03-26 stsp const struct got_error *got_worktree_schedule_add(struct got_worktree *,
186 4e68cba3 2019-11-23 stsp struct got_pathlist_head *, got_worktree_checkout_cb, void *,
187 022fae89 2019-12-06 tracey struct got_repository *, int);
188 2ec1f75b 2019-03-26 stsp
189 2ec1f75b 2019-03-26 stsp /*
190 17ed4618 2019-06-02 stsp * Remove files from disk and schedule them to be deleted in the next commit.
191 2ec1f75b 2019-03-26 stsp * Don't allow deleting files with uncommitted modifications, unless the
192 2ec1f75b 2019-03-26 stsp * parameter 'delete_local_mods' is set.
193 2ec1f75b 2019-03-26 stsp */
194 2ec1f75b 2019-03-26 stsp const struct got_error *
195 17ed4618 2019-06-02 stsp got_worktree_schedule_delete(struct got_worktree *,
196 766841c2 2020-08-13 stsp struct got_pathlist_head *, int, const char *,
197 4e12cd97 2022-01-25 stsp got_worktree_delete_cb, void *, struct got_repository *, int, int);
198 a129376b 2019-03-28 stsp
199 33aa809d 2019-08-08 stsp /* A callback function which is used to select or reject a patch. */
200 33aa809d 2019-08-08 stsp typedef const struct got_error *(*got_worktree_patch_cb)(int *, void *,
201 33aa809d 2019-08-08 stsp unsigned char, const char *, FILE *, int, int);
202 33aa809d 2019-08-08 stsp
203 33aa809d 2019-08-08 stsp /* Values for result output parameter of got_wortree_patch_cb. */
204 33aa809d 2019-08-08 stsp #define GOT_PATCH_CHOICE_NONE 0
205 33aa809d 2019-08-08 stsp #define GOT_PATCH_CHOICE_YES 1
206 33aa809d 2019-08-08 stsp #define GOT_PATCH_CHOICE_NO 2
207 33aa809d 2019-08-08 stsp #define GOT_PATCH_CHOICE_QUIT 3
208 33aa809d 2019-08-08 stsp
209 a129376b 2019-03-28 stsp /*
210 a129376b 2019-03-28 stsp * Revert a file at the specified path such that it matches its
211 a129376b 2019-03-28 stsp * original state in the worktree's base commit.
212 33aa809d 2019-08-08 stsp * If the patch callback is not NULL, call it to select patch hunks to
213 33aa809d 2019-08-08 stsp * revert. Otherwise, revert the whole file found at each path.
214 a129376b 2019-03-28 stsp */
215 a129376b 2019-03-28 stsp const struct got_error *got_worktree_revert(struct got_worktree *,
216 e20a8b6f 2019-06-04 stsp struct got_pathlist_head *, got_worktree_checkout_cb, void *,
217 33aa809d 2019-08-08 stsp got_worktree_patch_cb patch_cb, void *patch_arg,
218 e20a8b6f 2019-06-04 stsp struct got_repository *);
219 c4296144 2019-05-09 stsp
220 c4296144 2019-05-09 stsp /*
221 33ad4cbe 2019-05-12 jcs * A callback function which is invoked when a commit message is requested.
222 8656d6c4 2019-05-20 stsp * Passes a pathlist with a struct got_commitable * in the data pointer of
223 8656d6c4 2019-05-20 stsp * each element, a pointer to the log message that must be set by the
224 8656d6c4 2019-05-20 stsp * callback and will be freed after committing, and an argument passed
225 8656d6c4 2019-05-20 stsp * through to the callback.
226 33ad4cbe 2019-05-12 jcs */
227 33ad4cbe 2019-05-12 jcs typedef const struct got_error *(*got_worktree_commit_msg_cb)(
228 33ad4cbe 2019-05-12 jcs struct got_pathlist_head *, char **, void *);
229 33ad4cbe 2019-05-12 jcs
230 33ad4cbe 2019-05-12 jcs /*
231 c4296144 2019-05-09 stsp * Create a new commit from changes in the work tree.
232 c4296144 2019-05-09 stsp * Return the ID of the newly created commit.
233 c4296144 2019-05-09 stsp * The worktree's base commit will be set to this new commit.
234 c4296144 2019-05-09 stsp * Files unaffected by this commit operation will retain their
235 c4296144 2019-05-09 stsp * current base commit.
236 de18fc63 2019-05-09 stsp * An author and a non-empty log message must be specified.
237 de18fc63 2019-05-09 stsp * The name of the committer is optional (may be NULL).
238 35213c7c 2020-07-23 stsp * If a path to be committed contains a symlink which points outside
239 35213c7c 2020-07-23 stsp * of the path space under version control, raise an error unless
240 35213c7c 2020-07-23 stsp * committing of such paths is being forced by the caller.
241 c4296144 2019-05-09 stsp */
242 de18fc63 2019-05-09 stsp const struct got_error *got_worktree_commit(struct got_object_id **,
243 5c1e53bc 2019-07-28 stsp struct got_worktree *, struct got_pathlist_head *, const char *,
244 35213c7c 2020-07-23 stsp const char *, int, got_worktree_commit_msg_cb, void *,
245 33ad4cbe 2019-05-12 jcs got_worktree_status_cb, void *, struct got_repository *);
246 8656d6c4 2019-05-20 stsp
247 8656d6c4 2019-05-20 stsp /* Get the path of a commitable worktree item. */
248 8656d6c4 2019-05-20 stsp const char *got_commitable_get_path(struct got_commitable *);
249 8656d6c4 2019-05-20 stsp
250 8656d6c4 2019-05-20 stsp /* Get the status of a commitable worktree item. */
251 8656d6c4 2019-05-20 stsp unsigned int got_commitable_get_status(struct got_commitable *);
252 818c7501 2019-07-11 stsp
253 818c7501 2019-07-11 stsp /*
254 818c7501 2019-07-11 stsp * Prepare for rebasing a branch onto the work tree's current branch.
255 818c7501 2019-07-11 stsp * This function creates references to a temporary branch, the branch
256 818c7501 2019-07-11 stsp * being rebased, and the work tree's current branch, under the
257 818c7501 2019-07-11 stsp * "got/worktree/rebase/" namespace. These references are used to
258 818c7501 2019-07-11 stsp * keep track of rebase operation state and are used as input and/or
259 818c7501 2019-07-11 stsp * output arguments with other rebase-related functions.
260 3e3a69f1 2019-07-25 stsp * The function also returns a pointer to a fileindex which must be
261 3e3a69f1 2019-07-25 stsp * passed back to other rebase-related functions.
262 818c7501 2019-07-11 stsp */
263 818c7501 2019-07-11 stsp const struct got_error *got_worktree_rebase_prepare(struct got_reference **,
264 3e3a69f1 2019-07-25 stsp struct got_reference **, struct got_fileindex **, struct got_worktree *,
265 3e3a69f1 2019-07-25 stsp struct got_reference *, struct got_repository *);
266 818c7501 2019-07-11 stsp
267 818c7501 2019-07-11 stsp /*
268 818c7501 2019-07-11 stsp * Continue an interrupted rebase operation.
269 818c7501 2019-07-11 stsp * This function returns existing references created when rebase was prepared,
270 818c7501 2019-07-11 stsp * and the ID of the commit currently being rebased. This should be called
271 818c7501 2019-07-11 stsp * before either resuming or aborting a rebase operation.
272 3e3a69f1 2019-07-25 stsp * The function also returns a pointer to a fileindex which must be
273 3e3a69f1 2019-07-25 stsp * passed back to other rebase-related functions.
274 818c7501 2019-07-11 stsp */
275 818c7501 2019-07-11 stsp const struct got_error *got_worktree_rebase_continue(struct got_object_id **,
276 818c7501 2019-07-11 stsp struct got_reference **, struct got_reference **, struct got_reference **,
277 3e3a69f1 2019-07-25 stsp struct got_fileindex **, struct got_worktree *, struct got_repository *);
278 818c7501 2019-07-11 stsp
279 818c7501 2019-07-11 stsp /* Check whether a, potentially interrupted, rebase operation is in progress. */
280 818c7501 2019-07-11 stsp const struct got_error *got_worktree_rebase_in_progress(int *,
281 818c7501 2019-07-11 stsp struct got_worktree *);
282 818c7501 2019-07-11 stsp
283 818c7501 2019-07-11 stsp /*
284 818c7501 2019-07-11 stsp * Merge changes from the commit currently being rebased into the work tree.
285 818c7501 2019-07-11 stsp * Report affected files, including merge conflicts, via the specified
286 01757395 2019-07-12 stsp * progress callback. Also populate a list of affected paths which should
287 01757395 2019-07-12 stsp * be passed to got_worktree_rebase_commit() after a conflict-free merge.
288 01757395 2019-07-12 stsp * This list must be initialized with TAILQ_INIT() and disposed of with
289 01757395 2019-07-12 stsp * got_worktree_rebase_pathlist_free().
290 818c7501 2019-07-11 stsp */
291 818c7501 2019-07-11 stsp const struct got_error *got_worktree_rebase_merge_files(
292 3e3a69f1 2019-07-25 stsp struct got_pathlist_head *, struct got_worktree *, struct got_fileindex *,
293 01757395 2019-07-12 stsp struct got_object_id *, struct got_object_id *, struct got_repository *,
294 e6209546 2019-08-22 stsp got_worktree_checkout_cb, void *, got_cancel_cb, void *);
295 818c7501 2019-07-11 stsp
296 818c7501 2019-07-11 stsp /*
297 01757395 2019-07-12 stsp * Commit changes merged by got_worktree_rebase_merge_files() to a temporary
298 01757395 2019-07-12 stsp * branch and return the ID of the newly created commit. An optional list of
299 01757395 2019-07-12 stsp * merged paths can be provided; otherwise this function will perform a status
300 01757395 2019-07-12 stsp * crawl across the entire work tree to find paths to commit.
301 818c7501 2019-07-11 stsp */
302 818c7501 2019-07-11 stsp const struct got_error *got_worktree_rebase_commit(struct got_object_id **,
303 3e3a69f1 2019-07-25 stsp struct got_pathlist_head *, struct got_worktree *, struct got_fileindex *,
304 598eac43 2022-07-22 stsp struct got_reference *, const char *, struct got_commit_object *,
305 818c7501 2019-07-11 stsp struct got_object_id *, struct got_repository *);
306 818c7501 2019-07-11 stsp
307 01757395 2019-07-12 stsp /* Free a list of merged paths from got_worktree_merge_files. */
308 01757395 2019-07-12 stsp void got_worktree_rebase_pathlist_free(struct got_pathlist_head *);
309 01757395 2019-07-12 stsp
310 818c7501 2019-07-11 stsp /* Postpone the rebase operation. Should be called after a merge conflict. */
311 3e3a69f1 2019-07-25 stsp const struct got_error *got_worktree_rebase_postpone(struct got_worktree *,
312 3e3a69f1 2019-07-25 stsp struct got_fileindex *);
313 818c7501 2019-07-11 stsp
314 818c7501 2019-07-11 stsp /*
315 818c7501 2019-07-11 stsp * Complete the current rebase operation. This should be called once all
316 818c7501 2019-07-11 stsp * commits have been rebased successfully.
317 e600f124 2021-03-21 stsp * The create_backup parameter controls whether the rebased branch will
318 e600f124 2021-03-21 stsp * be backed up via a reference in refs/got/backup/rebase/.
319 818c7501 2019-07-11 stsp */
320 818c7501 2019-07-11 stsp const struct got_error *got_worktree_rebase_complete(struct got_worktree *,
321 3e3a69f1 2019-07-25 stsp struct got_fileindex *, struct got_reference *, struct got_reference *,
322 e600f124 2021-03-21 stsp struct got_reference *, struct got_repository *, int create_backup);
323 818c7501 2019-07-11 stsp
324 818c7501 2019-07-11 stsp /*
325 818c7501 2019-07-11 stsp * Abort the current rebase operation.
326 818c7501 2019-07-11 stsp * Report reverted files via the specified progress callback.
327 818c7501 2019-07-11 stsp */
328 818c7501 2019-07-11 stsp const struct got_error *got_worktree_rebase_abort(struct got_worktree *,
329 3e3a69f1 2019-07-25 stsp struct got_fileindex *, struct got_repository *, struct got_reference *,
330 0ebf8283 2019-07-24 stsp got_worktree_checkout_cb, void *);
331 0ebf8283 2019-07-24 stsp
332 0ebf8283 2019-07-24 stsp /*
333 0ebf8283 2019-07-24 stsp * Prepare for editing the history of the work tree's current branch.
334 0ebf8283 2019-07-24 stsp * This function creates references to a temporary branch, and the
335 0ebf8283 2019-07-24 stsp * work tree's current branch, under the "got/worktree/histedit/" namespace.
336 0ebf8283 2019-07-24 stsp * These references are used to keep track of histedit operation state and
337 0ebf8283 2019-07-24 stsp * are used as input and/or output arguments with other histedit-related
338 0ebf8283 2019-07-24 stsp * functions.
339 0ebf8283 2019-07-24 stsp */
340 0ebf8283 2019-07-24 stsp const struct got_error *got_worktree_histedit_prepare(struct got_reference **,
341 3e3a69f1 2019-07-25 stsp struct got_reference **, struct got_object_id **, struct got_fileindex **,
342 3e3a69f1 2019-07-25 stsp struct got_worktree *, struct got_repository *);
343 0ebf8283 2019-07-24 stsp
344 0ebf8283 2019-07-24 stsp /*
345 0ebf8283 2019-07-24 stsp * Continue an interrupted histedit operation.
346 0ebf8283 2019-07-24 stsp * This function returns existing references created when histedit was
347 0ebf8283 2019-07-24 stsp * prepared and the ID of the commit currently being edited.
348 0ebf8283 2019-07-24 stsp * It should be called before resuming or aborting a histedit operation.
349 0ebf8283 2019-07-24 stsp */
350 0ebf8283 2019-07-24 stsp const struct got_error *got_worktree_histedit_continue(struct got_object_id **,
351 0ebf8283 2019-07-24 stsp struct got_reference **, struct got_reference **, struct got_object_id **,
352 3e3a69f1 2019-07-25 stsp struct got_fileindex **, struct got_worktree *, struct got_repository *);
353 0ebf8283 2019-07-24 stsp
354 0ebf8283 2019-07-24 stsp /* Check whether a histedit operation is in progress. */
355 0ebf8283 2019-07-24 stsp const struct got_error *got_worktree_histedit_in_progress(int *,
356 0ebf8283 2019-07-24 stsp struct got_worktree *);
357 0ebf8283 2019-07-24 stsp
358 0ebf8283 2019-07-24 stsp /*
359 0ebf8283 2019-07-24 stsp * Merge changes from the commit currently being edited into the work tree.
360 0ebf8283 2019-07-24 stsp * Report affected files, including merge conflicts, via the specified
361 0ebf8283 2019-07-24 stsp * progress callback. Also populate a list of affected paths which should
362 0ebf8283 2019-07-24 stsp * be passed to got_worktree_histedit_commit() after a conflict-free merge.
363 0ebf8283 2019-07-24 stsp * This list must be initialized with TAILQ_INIT() and disposed of with
364 0ebf8283 2019-07-24 stsp * got_worktree_rebase_pathlist_free().
365 0ebf8283 2019-07-24 stsp */
366 0ebf8283 2019-07-24 stsp const struct got_error *got_worktree_histedit_merge_files(
367 3e3a69f1 2019-07-25 stsp struct got_pathlist_head *, struct got_worktree *, struct got_fileindex *,
368 0ebf8283 2019-07-24 stsp struct got_object_id *, struct got_object_id *, struct got_repository *,
369 e6209546 2019-08-22 stsp got_worktree_checkout_cb, void *, got_cancel_cb, void *);
370 0ebf8283 2019-07-24 stsp
371 0ebf8283 2019-07-24 stsp /*
372 0ebf8283 2019-07-24 stsp * Commit changes merged by got_worktree_histedit_merge_files() to a temporary
373 0ebf8283 2019-07-24 stsp * branch and return the ID of the newly created commit. An optional list of
374 0ebf8283 2019-07-24 stsp * merged paths can be provided; otherwise this function will perform a status
375 0ebf8283 2019-07-24 stsp * crawl across the entire work tree to find paths to commit.
376 0ebf8283 2019-07-24 stsp * An optional log message can be provided which will be used instead of the
377 0ebf8283 2019-07-24 stsp * commit's original message.
378 0ebf8283 2019-07-24 stsp */
379 0ebf8283 2019-07-24 stsp const struct got_error *got_worktree_histedit_commit(struct got_object_id **,
380 3e3a69f1 2019-07-25 stsp struct got_pathlist_head *, struct got_worktree *, struct got_fileindex *,
381 598eac43 2022-07-22 stsp struct got_reference *, const char *, struct got_commit_object *,
382 0ebf8283 2019-07-24 stsp struct got_object_id *, const char *, struct got_repository *);
383 0ebf8283 2019-07-24 stsp
384 0ebf8283 2019-07-24 stsp /*
385 0ebf8283 2019-07-24 stsp * Record the specified commit as skipped during histedit.
386 0ebf8283 2019-07-24 stsp * This should be called for commits which get dropped or get folded into
387 0ebf8283 2019-07-24 stsp * a subsequent commit.
388 0ebf8283 2019-07-24 stsp */
389 0ebf8283 2019-07-24 stsp const struct got_error *got_worktree_histedit_skip_commit(struct got_worktree *,
390 0ebf8283 2019-07-24 stsp struct got_object_id *, struct got_repository *);
391 0ebf8283 2019-07-24 stsp
392 0ebf8283 2019-07-24 stsp /* Postpone the histedit operation. */
393 3e3a69f1 2019-07-25 stsp const struct got_error *got_worktree_histedit_postpone(struct got_worktree *,
394 3e3a69f1 2019-07-25 stsp struct got_fileindex *);
395 0ebf8283 2019-07-24 stsp
396 0ebf8283 2019-07-24 stsp /*
397 0ebf8283 2019-07-24 stsp * Complete the current histedit operation. This should be called once all
398 0ebf8283 2019-07-24 stsp * commits have been edited successfully.
399 0ebf8283 2019-07-24 stsp */
400 0ebf8283 2019-07-24 stsp const struct got_error *got_worktree_histedit_complete(struct got_worktree *,
401 3e3a69f1 2019-07-25 stsp struct got_fileindex *, struct got_reference *, struct got_reference *,
402 3e3a69f1 2019-07-25 stsp struct got_repository *);
403 0ebf8283 2019-07-24 stsp
404 0ebf8283 2019-07-24 stsp /*
405 0ebf8283 2019-07-24 stsp * Abort the current histedit operation.
406 0ebf8283 2019-07-24 stsp * Report reverted files via the specified progress callback.
407 0ebf8283 2019-07-24 stsp */
408 0ebf8283 2019-07-24 stsp const struct got_error *got_worktree_histedit_abort(struct got_worktree *,
409 3e3a69f1 2019-07-25 stsp struct got_fileindex *, struct got_repository *, struct got_reference *,
410 3e3a69f1 2019-07-25 stsp struct got_object_id *, got_worktree_checkout_cb, void *);
411 0ebf8283 2019-07-24 stsp
412 c3022ba5 2019-07-27 stsp /* Get the path to this work tree's histedit script file. */
413 c3022ba5 2019-07-27 stsp const struct got_error *got_worktree_get_histedit_script_path(char **,
414 0ebf8283 2019-07-24 stsp struct got_worktree *);
415 dc424a06 2019-08-07 stsp
416 2822a352 2019-10-15 stsp /*
417 2822a352 2019-10-15 stsp * Prepare a work tree for integrating a branch.
418 2822a352 2019-10-15 stsp * Return pointers to a fileindex and locked references which must be
419 2822a352 2019-10-15 stsp * passed back to other integrate-related functions.
420 2822a352 2019-10-15 stsp */
421 2822a352 2019-10-15 stsp const struct got_error *
422 2822a352 2019-10-15 stsp got_worktree_integrate_prepare(struct got_fileindex **,
423 abc59930 2021-09-05 naddy struct got_reference **, struct got_reference **,
424 2822a352 2019-10-15 stsp struct got_worktree *, const char *, struct got_repository *);
425 dc424a06 2019-08-07 stsp
426 fdfa9bf2 2019-08-03 stsp /*
427 2822a352 2019-10-15 stsp * Carry out a prepared branch integration operation.
428 2822a352 2019-10-15 stsp * Report affected files via the specified progress callback.
429 2822a352 2019-10-15 stsp */
430 2822a352 2019-10-15 stsp const struct got_error *got_worktree_integrate_continue(
431 2822a352 2019-10-15 stsp struct got_worktree *, struct got_fileindex *, struct got_repository *,
432 2822a352 2019-10-15 stsp struct got_reference *, struct got_reference *,
433 2822a352 2019-10-15 stsp got_worktree_checkout_cb, void *, got_cancel_cb, void *);
434 2822a352 2019-10-15 stsp
435 2822a352 2019-10-15 stsp /* Abort a prepared branch integration operation. */
436 2822a352 2019-10-15 stsp const struct got_error *got_worktree_integrate_abort(struct got_worktree *,
437 2822a352 2019-10-15 stsp struct got_fileindex *, struct got_repository *,
438 2822a352 2019-10-15 stsp struct got_reference *, struct got_reference *);
439 f259c4c1 2021-09-24 stsp
440 f259c4c1 2021-09-24 stsp /* Postpone the merge operation. Should be called after a merge conflict. */
441 f259c4c1 2021-09-24 stsp const struct got_error *got_worktree_merge_postpone(struct got_worktree *,
442 f259c4c1 2021-09-24 stsp struct got_fileindex *);
443 f259c4c1 2021-09-24 stsp
444 f259c4c1 2021-09-24 stsp /* Merge changes from the merge source branch into the worktree. */
445 f259c4c1 2021-09-24 stsp const struct got_error *
446 f259c4c1 2021-09-24 stsp got_worktree_merge_branch(struct got_worktree *worktree,
447 f259c4c1 2021-09-24 stsp struct got_fileindex *fileindex,
448 f259c4c1 2021-09-24 stsp struct got_object_id *yca_commit_id,
449 f259c4c1 2021-09-24 stsp struct got_object_id *branch_tip,
450 f259c4c1 2021-09-24 stsp struct got_repository *repo, got_worktree_checkout_cb progress_cb,
451 f259c4c1 2021-09-24 stsp void *progress_arg, got_cancel_cb cancel_cb, void *cancel_arg);
452 f259c4c1 2021-09-24 stsp
453 f259c4c1 2021-09-24 stsp /* Attempt to commit merged changes. */
454 f259c4c1 2021-09-24 stsp const struct got_error *
455 f259c4c1 2021-09-24 stsp got_worktree_merge_commit(struct got_object_id **new_commit_id,
456 f259c4c1 2021-09-24 stsp struct got_worktree *worktree, struct got_fileindex *fileindex,
457 f259c4c1 2021-09-24 stsp const char *author, const char *committer, int allow_bad_symlinks,
458 f259c4c1 2021-09-24 stsp struct got_object_id *branch_tip, const char *branch_name,
459 0ff8d236 2021-09-28 stsp struct got_repository *repo,
460 0ff8d236 2021-09-28 stsp got_worktree_status_cb status_cb, void *status_arg);
461 f259c4c1 2021-09-24 stsp
462 f259c4c1 2021-09-24 stsp /*
463 f259c4c1 2021-09-24 stsp * Complete the merge operation.
464 f259c4c1 2021-09-24 stsp * This should be called once changes have been successfully committed.
465 f259c4c1 2021-09-24 stsp */
466 f259c4c1 2021-09-24 stsp const struct got_error *got_worktree_merge_complete(
467 f259c4c1 2021-09-24 stsp struct got_worktree *worktree, struct got_fileindex *fileindex,
468 f259c4c1 2021-09-24 stsp struct got_repository *repo);
469 f259c4c1 2021-09-24 stsp
470 f259c4c1 2021-09-24 stsp /* Check whether a merge operation is in progress. */
471 f259c4c1 2021-09-24 stsp const struct got_error *got_worktree_merge_in_progress(int *,
472 f259c4c1 2021-09-24 stsp struct got_worktree *, struct got_repository *);
473 f259c4c1 2021-09-24 stsp
474 f259c4c1 2021-09-24 stsp /*
475 f259c4c1 2021-09-24 stsp * Prepare for merging a branch into the work tree's current branch.
476 f259c4c1 2021-09-24 stsp * This function creates a reference to the branch being merged, and to
477 f259c4c1 2021-09-24 stsp * this branch's current tip commit, in the "got/worktree/merge/" namespace.
478 f259c4c1 2021-09-24 stsp * These references are used to keep track of merge operation state and are
479 f259c4c1 2021-09-24 stsp * used as input and/or output arguments with other merge-related functions.
480 f259c4c1 2021-09-24 stsp * The function also returns a pointer to a fileindex which must be
481 f259c4c1 2021-09-24 stsp * passed back to other merge-related functions.
482 f259c4c1 2021-09-24 stsp */
483 f259c4c1 2021-09-24 stsp const struct got_error *got_worktree_merge_prepare(struct got_fileindex **,
484 f259c4c1 2021-09-24 stsp struct got_worktree *, struct got_reference *, struct got_repository *);
485 2822a352 2019-10-15 stsp
486 2822a352 2019-10-15 stsp /*
487 f259c4c1 2021-09-24 stsp * Continue an interrupted merge operation.
488 f259c4c1 2021-09-24 stsp * This function returns name of the branch being merged, and the ID of the
489 f259c4c1 2021-09-24 stsp * tip commit being merged.
490 f259c4c1 2021-09-24 stsp * This function should be called before either resuming or aborting a
491 f259c4c1 2021-09-24 stsp * merge operation.
492 f259c4c1 2021-09-24 stsp * The function also returns a pointer to a fileindex which must be
493 f259c4c1 2021-09-24 stsp * passed back to other merge-related functions.
494 f259c4c1 2021-09-24 stsp */
495 f259c4c1 2021-09-24 stsp const struct got_error *got_worktree_merge_continue(char **,
496 f259c4c1 2021-09-24 stsp struct got_object_id **, struct got_fileindex **,
497 f259c4c1 2021-09-24 stsp struct got_worktree *, struct got_repository *);
498 f259c4c1 2021-09-24 stsp
499 f259c4c1 2021-09-24 stsp /*
500 f259c4c1 2021-09-24 stsp * Abort the current rebase operation.
501 f259c4c1 2021-09-24 stsp * Report reverted files via the specified progress callback.
502 f259c4c1 2021-09-24 stsp */
503 f259c4c1 2021-09-24 stsp const struct got_error *got_worktree_merge_abort(struct got_worktree *,
504 f259c4c1 2021-09-24 stsp struct got_fileindex *, struct got_repository *,
505 f259c4c1 2021-09-24 stsp got_worktree_checkout_cb, void *);
506 f259c4c1 2021-09-24 stsp
507 f259c4c1 2021-09-24 stsp /*
508 fdfa9bf2 2019-08-03 stsp * Stage the specified paths for commit.
509 dc424a06 2019-08-07 stsp * If the patch callback is not NULL, call it to select patch hunks for
510 dc424a06 2019-08-07 stsp * staging. Otherwise, stage the full file content found at each path.
511 35213c7c 2020-07-23 stsp * If a path being staged contains a symlink which points outside
512 35213c7c 2020-07-23 stsp * of the path space under version control, raise an error unless
513 35213c7c 2020-07-23 stsp * staging of such paths is being forced by the caller.
514 35213c7c 2020-07-23 stsp */
515 1e71573e 2019-08-03 stsp const struct got_error *got_worktree_stage(struct got_worktree *,
516 1e71573e 2019-08-03 stsp struct got_pathlist_head *, got_worktree_status_cb, void *,
517 35213c7c 2020-07-23 stsp got_worktree_patch_cb, void *, int, struct got_repository *);
518 ad493afc 2019-08-03 stsp
519 ad493afc 2019-08-03 stsp /*
520 ad493afc 2019-08-03 stsp * Merge staged changes for the specified paths back into the work tree
521 ad493afc 2019-08-03 stsp * and mark the paths as non-staged again.
522 ad493afc 2019-08-03 stsp */
523 ad493afc 2019-08-03 stsp const struct got_error *got_worktree_unstage(struct got_worktree *,
524 ad493afc 2019-08-03 stsp struct got_pathlist_head *, got_worktree_checkout_cb, void *,
525 2e1f37b0 2019-08-08 stsp got_worktree_patch_cb, void *, struct got_repository *);
526 b2118c49 2020-07-28 stsp
527 b2118c49 2020-07-28 stsp /* A callback function which is invoked with per-path info. */
528 b2118c49 2020-07-28 stsp typedef const struct got_error *(*got_worktree_path_info_cb)(void *,
529 b2118c49 2020-07-28 stsp const char *path, mode_t mode, time_t mtime,
530 b2118c49 2020-07-28 stsp struct got_object_id *blob_id, struct got_object_id *staged_blob_id,
531 b2118c49 2020-07-28 stsp struct got_object_id *commit_id);
532 b2118c49 2020-07-28 stsp
533 5e91dae4 2022-08-30 stsp /*
534 b2118c49 2020-07-28 stsp * Report work-tree meta data for paths in the work tree.
535 b2118c49 2020-07-28 stsp * The info callback will be invoked with the provided void * argument,
536 b2118c49 2020-07-28 stsp * a path, and meta-data arguments (see got_worktree_path_info_cb).
537 b2118c49 2020-07-28 stsp */
538 b2118c49 2020-07-28 stsp const struct got_error *
539 b2118c49 2020-07-28 stsp got_worktree_path_info(struct got_worktree *, struct got_pathlist_head *,
540 b2118c49 2020-07-28 stsp got_worktree_path_info_cb, void *, got_cancel_cb , void *);
541 e600f124 2021-03-21 stsp
542 e600f124 2021-03-21 stsp /* References pointing at pre-rebase commit backups. */
543 e600f124 2021-03-21 stsp #define GOT_WORKTREE_REBASE_BACKUP_REF_PREFIX "refs/got/backup/rebase"
544 e600f124 2021-03-21 stsp
545 e600f124 2021-03-21 stsp /* References pointing at pre-histedit commit backups. */
546 e600f124 2021-03-21 stsp #define GOT_WORKTREE_HISTEDIT_BACKUP_REF_PREFIX "refs/got/backup/histedit"
547 78f5ac24 2022-03-19 op
548 78f5ac24 2022-03-19 op /*
549 78f5ac24 2022-03-19 op * Prepare for applying a patch.
550 78f5ac24 2022-03-19 op */
551 78f5ac24 2022-03-19 op const struct got_error *
552 f2dd7807 2022-05-17 op got_worktree_patch_prepare(struct got_fileindex **, char **,
553 f2dd7807 2022-05-17 op struct got_worktree *);
554 78f5ac24 2022-03-19 op
555 78f5ac24 2022-03-19 op /*
556 78f5ac24 2022-03-19 op * Lookup paths for the "old" and "new" file before patching and check their
557 78f5ac24 2022-03-19 op * status.
558 78f5ac24 2022-03-19 op */
559 78f5ac24 2022-03-19 op const struct got_error *
560 78f5ac24 2022-03-19 op got_worktree_patch_check_path(const char *, const char *, char **, char **,
561 78f5ac24 2022-03-19 op struct got_worktree *, struct got_repository *, struct got_fileindex *);
562 78f5ac24 2022-03-19 op
563 f2dd7807 2022-05-17 op const struct got_error *
564 f2dd7807 2022-05-17 op got_worktree_patch_schedule_add(const char *, struct got_repository *,
565 f2dd7807 2022-05-17 op struct got_worktree *, struct got_fileindex *, got_worktree_checkout_cb,
566 f2dd7807 2022-05-17 op void *);
567 f2dd7807 2022-05-17 op
568 f2dd7807 2022-05-17 op const struct got_error *
569 f2dd7807 2022-05-17 op got_worktree_patch_schedule_rm(const char *, struct got_repository *,
570 f2dd7807 2022-05-17 op struct got_worktree *, struct got_fileindex *, got_worktree_delete_cb,
571 f2dd7807 2022-05-17 op void *);
572 f2dd7807 2022-05-17 op
573 78f5ac24 2022-03-19 op /* Complete the patch operation. */
574 78f5ac24 2022-03-19 op const struct got_error *
575 4bcdc895 2022-05-17 op got_worktree_patch_complete(struct got_fileindex *, const char *);