Blob


1 /*
2 * Copyright (c) 2018, 2019 Stefan Sperling <stsp@openbsd.org>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
17 struct got_worktree;
18 struct got_commitable;
19 struct got_commit_object;
20 struct got_fileindex;
22 /* status codes */
23 #define GOT_STATUS_NO_CHANGE ' '
24 #define GOT_STATUS_ADD 'A'
25 #define GOT_STATUS_EXISTS 'E'
26 #define GOT_STATUS_UPDATE 'U'
27 #define GOT_STATUS_DELETE 'D'
28 #define GOT_STATUS_MODIFY 'M'
29 #define GOT_STATUS_MODE_CHANGE 'm'
30 #define GOT_STATUS_CONFLICT 'C'
31 #define GOT_STATUS_MERGE 'G'
32 #define GOT_STATUS_MISSING '!'
33 #define GOT_STATUS_UNVERSIONED '?'
34 #define GOT_STATUS_OBSTRUCTED '~'
35 #define GOT_STATUS_NONEXISTENT 'N'
36 #define GOT_STATUS_REVERT 'R'
37 #define GOT_STATUS_CANNOT_DELETE 'd'
38 #define GOT_STATUS_BUMP_BASE 'b'
39 #define GOT_STATUS_BASE_REF_ERR 'B'
40 #define GOT_STATUS_CANNOT_UPDATE '#'
42 /* Also defined in got_lib_worktree.h in case got_worktree.h is not included. */
43 #define GOT_WORKTREE_GOT_DIR ".got"
44 #define GOT_WORKTREE_CVG_DIR ".cvg"
46 /*
47 * Attempt to initialize a new work tree on disk.
48 * The first argument is the path to a directory where the work tree
49 * will be created. The path itself must not yet exist, but the dirname(3)
50 * of the path must already exist.
51 * The reference provided will be used to determine the new worktree's
52 * base commit. The third argument speficies the work tree's path prefix.
53 * The fourth argument specifies the meta data directory to use, which
54 * should be either GOT_WORKTREE_GOT_DIR or GOT_WORKTREE_CVG_DIR.
55 */
56 const struct got_error *got_worktree_init(const char *, struct got_reference *,
57 const char *, const char *, struct got_repository *);
59 /*
60 * Attempt to open a worktree at or above the specified path, using
61 * the specified meta data directory which should be either be NULL
62 * in which case a meta directory is auto-discovered, or be one of
63 * GOT_WORKTREE_GOT_DIR and GOT_WORKTREE_CVG_DIR.
64 * The caller must dispose of it with got_worktree_close().
65 */
66 const struct got_error *got_worktree_open(struct got_worktree **,
67 const char *path, const char *meta_dir);
69 /* Dispose of an open work tree. */
70 const struct got_error *got_worktree_close(struct got_worktree *);
72 /*
73 * Get the path to the root directory of a worktree.
74 */
75 const char *got_worktree_get_root_path(struct got_worktree *);
77 /*
78 * Get the path to the repository associated with a worktree.
79 */
80 const char *got_worktree_get_repo_path(struct got_worktree *);
82 /*
83 * Get the path prefix associated with a worktree.
84 */
85 const char *got_worktree_get_path_prefix(struct got_worktree *);
87 /*
88 * Get the UUID of a work tree as a string.
89 * The caller must dispose of the returned UUID string with free(3).
90 */
91 const struct got_error *got_worktree_get_uuid(char **, struct got_worktree *);
93 /*
94 * Check if a user-provided path prefix matches that of the worktree.
95 */
96 const struct got_error *got_worktree_match_path_prefix(int *,
97 struct got_worktree *, const char *);
99 /*
100 * Prefix for references pointing at base commit of backout/cherrypick commits.
101 * Reference path takes the form: PREFIX-WORKTREE_UUID-COMMIT_ID
102 */
103 #define GOT_WORKTREE_CHERRYPICK_REF_PREFIX "refs/got/worktree/cherrypick"
104 #define GOT_WORKTREE_BACKOUT_REF_PREFIX "refs/got/worktree/backout"
106 #define GOT_WORKTREE_CHERRYPICK_REF_PREFIX_LEN \
107 sizeof(GOT_WORKTREE_CHERRYPICK_REF_PREFIX) - 1
108 #define GOT_WORKTREE_BACKOUT_REF_PREFIX_LEN \
109 sizeof(GOT_WORKTREE_BACKOUT_REF_PREFIX) - 1
110 #define GOT_WORKTREE_UUID_STRLEN 36
112 const struct got_error *got_worktree_get_logmsg_ref_name(char **,
113 struct got_worktree *, const char *);
114 /*
115 * Get the name of a work tree's HEAD reference.
116 */
117 const char *got_worktree_get_head_ref_name(struct got_worktree *);
119 /*
120 * Set the branch head reference of the work tree.
121 */
122 const struct got_error *got_worktree_set_head_ref(struct got_worktree *,
123 struct got_reference *);
125 /*
126 * Get the current base commit ID of a worktree.
127 */
128 struct got_object_id *got_worktree_get_base_commit_id(struct got_worktree *);
130 /*
131 * Set the base commit Id of a worktree.
132 */
133 const struct got_error *got_worktree_set_base_commit_id(struct got_worktree *,
134 struct got_repository *, struct got_object_id *);
136 /*
137 * Get the state of the work tree. If the work tree's global base commit is
138 * the tip of the work tree's current branch, and each file in the index is
139 * based on this same commit, the char out parameter will be
140 * GOT_WORKTREE_STATE_UPTODATE, else it will be GOT_WORKTREE_STATE_OUTOFDATE.
141 */
142 const struct got_error *got_worktree_get_state(char *,
143 struct got_repository *, struct got_worktree *,
144 got_cancel_cb, void *);
146 #define GOT_WORKTREE_STATE_UNKNOWN ' '
147 #define GOT_WORKTREE_STATE_UPTODATE '*'
148 #define GOT_WORKTREE_STATE_OUTOFDATE '~'
150 /*
151 * Obtain a parsed representation of this worktree's got.conf file.
152 * Return NULL if this configuration file could not be read.
153 */
154 const struct got_gotconfig *got_worktree_get_gotconfig(struct got_worktree *);
156 /* A callback function which is invoked when a path is checked out. */
157 typedef const struct got_error *(*got_worktree_checkout_cb)(void *,
158 unsigned char, const char *);
160 /* A callback function which is invoked when a path is removed. */
161 typedef const struct got_error *(*got_worktree_delete_cb)(void *,
162 unsigned char, unsigned char, const char *);
164 /*
165 * Attempt to check out files into a work tree from its associated repository
166 * and path prefix, and update the work tree's file index accordingly.
167 * File content is obtained from blobs within the work tree's path prefix
168 * inside the tree corresponding to the work tree's base commit.
169 * The checkout progress callback will be invoked with the provided
170 * void * argument, and the path of each checked out file.
172 * It is possible to restrict the checkout operation to specific paths in
173 * the work tree, in which case all files outside those paths will remain at
174 * their currently recorded base commit. Inconsistent base commits can be
175 * repaired later by running another update operation across the entire work
176 * tree. Inconsistent base-commits may also occur if this function runs into
177 * an error or if the checkout operation is cancelled by the cancel callback.
178 * Allspecified paths are relative to the work tree's root. Pass a pathlist
179 * with a single empty path "" to check out files across the entire work tree.
181 * Some operations may refuse to run while the work tree contains files from
182 * multiple base commits.
183 */
184 const struct got_error *got_worktree_checkout_files(struct got_worktree *,
185 struct got_pathlist_head *, struct got_repository *,
186 got_worktree_checkout_cb, void *, got_cancel_cb, void *);
188 /* Merge the differences between two commits into a work tree. */
189 const struct got_error *
190 got_worktree_merge_files(struct got_worktree *,
191 struct got_object_id *, struct got_object_id *,
192 struct got_repository *, got_worktree_checkout_cb, void *,
193 got_cancel_cb, void *);
195 /*
196 * A callback function which is invoked to report a file's status.
198 * If a valid directory file descriptor and a directory entry name are passed,
199 * these should be used to open the file instead of opening the file by path.
200 * This prevents race conditions if the filesystem is modified concurrently.
201 * If the directory descriptor is not available then its value will be -1.
202 */
203 typedef const struct got_error *(*got_worktree_status_cb)(void *,
204 unsigned char, unsigned char, const char *, struct got_object_id *,
205 struct got_object_id *, struct got_object_id *, int, const char *);
207 /*
208 * Report the status of paths in the work tree.
209 * The status callback will be invoked with the provided void * argument,
210 * a path, and a corresponding status code.
211 */
212 const struct got_error *got_worktree_status(struct got_worktree *,
213 struct got_pathlist_head *, struct got_repository *, int no_ignores,
214 got_worktree_status_cb, void *, got_cancel_cb cancel_cb, void *);
216 /*
217 * Try to resolve a user-provided path to an on-disk path in the work tree.
218 * The caller must dispose of the resolved path with free(3).
219 */
220 const struct got_error *got_worktree_resolve_path(char **,
221 struct got_worktree *, const char *);
223 /* Schedule files at on-disk paths for addition in the next commit. */
224 const struct got_error *got_worktree_schedule_add(struct got_worktree *,
225 struct got_pathlist_head *, got_worktree_checkout_cb, void *,
226 struct got_repository *, int);
228 /*
229 * Remove files from disk and schedule them to be deleted in the next commit.
230 * Don't allow deleting files with uncommitted modifications, unless the
231 * parameter 'delete_local_mods' is set.
232 */
233 const struct got_error *
234 got_worktree_schedule_delete(struct got_worktree *,
235 struct got_pathlist_head *, int, const char *,
236 got_worktree_delete_cb, void *, struct got_repository *, int, int);
238 /* A callback function which is used to select or reject a patch. */
239 typedef const struct got_error *(*got_worktree_patch_cb)(int *, void *,
240 unsigned char, const char *, FILE *, int, int);
242 /* Values for result output parameter of got_wortree_patch_cb. */
243 #define GOT_PATCH_CHOICE_NONE 0
244 #define GOT_PATCH_CHOICE_YES 1
245 #define GOT_PATCH_CHOICE_NO 2
246 #define GOT_PATCH_CHOICE_QUIT 3
248 /*
249 * Revert a file at the specified path such that it matches its
250 * original state in the worktree's base commit.
251 * If the patch callback is not NULL, call it to select patch hunks to
252 * revert. Otherwise, revert the whole file found at each path.
253 */
254 const struct got_error *got_worktree_revert(struct got_worktree *,
255 struct got_pathlist_head *, got_worktree_checkout_cb, void *,
256 got_worktree_patch_cb patch_cb, void *patch_arg,
257 struct got_repository *);
259 /*
260 * A callback function which is invoked when a commit message is requested.
261 * Passes a pathlist with a struct got_commitable * in the data pointer of
262 * each element, the path to a file which contains a diff of changes to be
263 * committed (may be NULL), and a pointer to the log message that must be
264 * set by the callback and will be freed after committing, and an argument
265 * passed through to the callback.
266 */
267 typedef const struct got_error *(*got_worktree_commit_msg_cb)(
268 struct got_pathlist_head *, const char *, char **, void *);
270 /*
271 * Create a new commit from changes in the work tree.
272 * Return the ID of the newly created commit.
273 * The worktree's base commit will be set to this new commit.
274 * Files unaffected by this commit operation will retain their
275 * current base commit.
276 * An author and a non-empty log message must be specified.
277 * The name of the committer is optional (may be NULL).
278 * If a path to be committed contains a symlink which points outside
279 * of the path space under version control, raise an error unless
280 * committing of such paths is being forced by the caller.
281 */
282 const struct got_error *got_worktree_commit(struct got_object_id **,
283 struct got_worktree *, struct got_pathlist_head *, const char *,
284 const char *, int, int, int, got_worktree_commit_msg_cb, void *,
285 got_worktree_status_cb, void *, struct got_repository *);
287 /* Get the path of a commitable worktree item. */
288 const char *got_commitable_get_path(struct got_commitable *);
290 /* Get the status of a commitable worktree item. */
291 unsigned int got_commitable_get_status(struct got_commitable *);
293 /*
294 * Prepare for rebasing a branch onto the work tree's current branch.
295 * This function creates references to a temporary branch, the branch
296 * being rebased, and the work tree's current branch, under the
297 * "got/worktree/rebase/" namespace. These references are used to
298 * keep track of rebase operation state and are used as input and/or
299 * output arguments with other rebase-related functions.
300 * The function also returns a pointer to a fileindex which must be
301 * passed back to other rebase-related functions.
302 */
303 const struct got_error *got_worktree_rebase_prepare(struct got_reference **,
304 struct got_reference **, struct got_fileindex **, struct got_worktree *,
305 struct got_reference *, struct got_repository *);
307 /*
308 * Continue an interrupted rebase operation.
309 * This function returns existing references created when rebase was prepared,
310 * and the ID of the commit currently being rebased. This should be called
311 * before either resuming or aborting a rebase operation.
312 * The function also returns a pointer to a fileindex which must be
313 * passed back to other rebase-related functions.
314 */
315 const struct got_error *got_worktree_rebase_continue(struct got_object_id **,
316 struct got_reference **, struct got_reference **, struct got_reference **,
317 struct got_fileindex **, struct got_worktree *, struct got_repository *);
319 /* Check whether a, potentially interrupted, rebase operation is in progress. */
320 const struct got_error *got_worktree_rebase_in_progress(int *,
321 struct got_worktree *);
322 /* Return information about an in-progress rebase operation. */
323 const struct got_error *got_worktree_rebase_info(char **new_base_branch_name,
324 char **branch_name, struct got_worktree *, struct got_repository *);
326 /*
327 * Merge changes from the commit currently being rebased into the work tree.
328 * Report affected files, including merge conflicts, via the specified
329 * progress callback. Also populate a list of affected paths which should
330 * be passed to got_worktree_rebase_commit() after a conflict-free merge.
331 * This list must be initialized with TAILQ_INIT() and disposed of with
332 * got_pathlist_free(list, GOT_PATHLIST_FREE_PATH).
333 */
334 const struct got_error *got_worktree_rebase_merge_files(
335 struct got_pathlist_head *, struct got_worktree *, struct got_fileindex *,
336 struct got_object_id *, struct got_object_id *, struct got_repository *,
337 got_worktree_checkout_cb, void *, got_cancel_cb, void *);
339 /*
340 * Commit changes merged by got_worktree_rebase_merge_files() to a temporary
341 * branch and return the ID of the newly created commit. An optional list of
342 * merged paths can be provided; otherwise this function will perform a status
343 * crawl across the entire work tree to find paths to commit.
344 */
345 const struct got_error *got_worktree_rebase_commit(struct got_object_id **,
346 struct got_pathlist_head *, struct got_worktree *, struct got_fileindex *,
347 struct got_reference *, const char *, struct got_commit_object *,
348 struct got_object_id *, int, struct got_repository *);
350 /* Postpone the rebase operation. Should be called after a merge conflict. */
351 const struct got_error *got_worktree_rebase_postpone(struct got_worktree *,
352 struct got_fileindex *);
354 /*
355 * Complete the current rebase operation. This should be called once all
356 * commits have been rebased successfully.
357 * The create_backup parameter controls whether the rebased branch will
358 * be backed up via a reference in refs/got/backup/rebase/.
359 */
360 const struct got_error *got_worktree_rebase_complete(struct got_worktree *,
361 struct got_fileindex *, struct got_reference *, struct got_reference *,
362 struct got_repository *, int create_backup);
364 /*
365 * Abort the current rebase operation.
366 * Report reverted files via the specified progress callback.
367 */
368 const struct got_error *got_worktree_rebase_abort(struct got_worktree *,
369 struct got_fileindex *, struct got_repository *, struct got_reference *,
370 got_worktree_checkout_cb, void *);
372 /*
373 * Prepare for editing the history of the work tree's current branch.
374 * This function creates references to a temporary branch, and the
375 * work tree's current branch, under the "got/worktree/histedit/" namespace.
376 * These references are used to keep track of histedit operation state and
377 * are used as input and/or output arguments with other histedit-related
378 * functions.
379 */
380 const struct got_error *got_worktree_histedit_prepare(struct got_reference **,
381 struct got_reference **, struct got_object_id **, struct got_fileindex **,
382 struct got_worktree *, struct got_repository *);
384 /*
385 * Continue an interrupted histedit operation.
386 * This function returns existing references created when histedit was
387 * prepared and the ID of the commit currently being edited.
388 * It should be called before resuming or aborting a histedit operation.
389 */
390 const struct got_error *got_worktree_histedit_continue(struct got_object_id **,
391 struct got_reference **, struct got_reference **, struct got_object_id **,
392 struct got_fileindex **, struct got_worktree *, struct got_repository *);
394 /* Check whether a histedit operation is in progress. */
395 const struct got_error *got_worktree_histedit_in_progress(int *,
396 struct got_worktree *);
397 /* Return information about an in-progress histedit operation. */
398 const struct got_error *got_worktree_histedit_info(
399 char **branch_nane, struct got_worktree *,
400 struct got_repository *);
402 /*
403 * Merge changes from the commit currently being edited into the work tree.
404 * Report affected files, including merge conflicts, via the specified
405 * progress callback. Also populate a list of affected paths which should
406 * be passed to got_worktree_histedit_commit() after a conflict-free merge.
407 * This list must be initialized with TAILQ_INIT() and disposed of with
408 * got_pathlist_free(list, GOT_PATHLIST_FREE_PATH).
409 */
410 const struct got_error *got_worktree_histedit_merge_files(
411 struct got_pathlist_head *, struct got_worktree *, struct got_fileindex *,
412 struct got_object_id *, struct got_object_id *, struct got_repository *,
413 got_worktree_checkout_cb, void *, got_cancel_cb, void *);
415 /*
416 * Commit changes merged by got_worktree_histedit_merge_files() to a temporary
417 * branch and return the ID of the newly created commit. An optional list of
418 * merged paths can be provided; otherwise this function will perform a status
419 * crawl across the entire work tree to find paths to commit.
420 * An optional log message can be provided which will be used instead of the
421 * commit's original message.
422 */
423 const struct got_error *got_worktree_histedit_commit(struct got_object_id **,
424 struct got_pathlist_head *, struct got_worktree *, struct got_fileindex *,
425 struct got_reference *, const char *, struct got_commit_object *,
426 struct got_object_id *, const char *, int, struct got_repository *);
428 /*
429 * Record the specified commit as skipped during histedit.
430 * This should be called for commits which get dropped or get folded into
431 * a subsequent commit.
432 */
433 const struct got_error *got_worktree_histedit_skip_commit(struct got_worktree *,
434 struct got_object_id *, struct got_repository *);
436 /* Postpone the histedit operation. */
437 const struct got_error *got_worktree_histedit_postpone(struct got_worktree *,
438 struct got_fileindex *);
440 /*
441 * Complete the current histedit operation. This should be called once all
442 * commits have been edited successfully.
443 */
444 const struct got_error *got_worktree_histedit_complete(struct got_worktree *,
445 struct got_fileindex *, struct got_reference *, struct got_reference *,
446 struct got_repository *);
448 /*
449 * Abort the current histedit operation.
450 * Report reverted files via the specified progress callback.
451 */
452 const struct got_error *got_worktree_histedit_abort(struct got_worktree *,
453 struct got_fileindex *, struct got_repository *, struct got_reference *,
454 struct got_object_id *, got_worktree_checkout_cb, void *);
456 /* Get the path to this work tree's histedit script file. */
457 const struct got_error *got_worktree_get_histedit_script_path(char **,
458 struct got_worktree *);
460 /*
461 * Prepare a work tree for integrating a branch.
462 * Return pointers to a fileindex and locked references which must be
463 * passed back to other integrate-related functions.
464 */
465 const struct got_error *
466 got_worktree_integrate_prepare(struct got_fileindex **,
467 struct got_reference **, struct got_reference **,
468 struct got_worktree *, const char *, struct got_repository *);
470 /*
471 * Carry out a prepared branch integration operation.
472 * Report affected files via the specified progress callback.
473 */
474 const struct got_error *got_worktree_integrate_continue(
475 struct got_worktree *, struct got_fileindex *, struct got_repository *,
476 struct got_reference *, struct got_reference *,
477 got_worktree_checkout_cb, void *, got_cancel_cb, void *);
479 /* Abort a prepared branch integration operation. */
480 const struct got_error *got_worktree_integrate_abort(struct got_worktree *,
481 struct got_fileindex *, struct got_repository *,
482 struct got_reference *, struct got_reference *);
484 /* Postpone the merge operation. Should be called after a merge conflict. */
485 const struct got_error *got_worktree_merge_postpone(struct got_worktree *,
486 struct got_fileindex *);
488 /* Merge changes from the merge source branch into the worktree. */
489 const struct got_error *
490 got_worktree_merge_branch(struct got_worktree *worktree,
491 struct got_fileindex *fileindex,
492 struct got_object_id *yca_commit_id,
493 struct got_object_id *branch_tip,
494 struct got_repository *repo, got_worktree_checkout_cb progress_cb,
495 void *progress_arg, got_cancel_cb cancel_cb, void *cancel_arg);
497 /* Attempt to commit merged changes. */
498 const struct got_error *
499 got_worktree_merge_commit(struct got_object_id **new_commit_id,
500 struct got_worktree *worktree, struct got_fileindex *fileindex,
501 const char *author, const char *committer, int allow_bad_symlinks,
502 struct got_object_id *branch_tip, const char *branch_name,
503 int allow_conflict, struct got_repository *repo,
504 got_worktree_status_cb status_cb, void *status_arg);
506 /*
507 * Complete the merge operation.
508 * This should be called once changes have been successfully committed.
509 */
510 const struct got_error *got_worktree_merge_complete(
511 struct got_worktree *worktree, struct got_fileindex *fileindex,
512 struct got_repository *repo);
514 /* Check whether a merge operation is in progress. */
515 const struct got_error *got_worktree_merge_in_progress(int *,
516 struct got_worktree *, struct got_repository *);
517 /* Return information about an in-progress merge operation. */
518 const struct got_error *
519 got_worktree_merge_info(char **branch_name, struct got_worktree *,
520 struct got_repository *);
522 /*
523 * Prepare for merging a branch into the work tree's current branch: lock the
524 * worktree and check that preconditions are satisfied. The function also
525 * returns a pointer to a fileindex which must be passed back to other
526 * merge-related functions.
527 */
528 const struct got_error *got_worktree_merge_prepare(struct got_fileindex **,
529 struct got_worktree *, struct got_repository *);
531 /*
532 * This function creates a reference to the branch being merged, and to
533 * this branch's current tip commit, in the "got/worktree/merge/" namespace.
534 * These references are used to keep track of merge operation state and are
535 * used as input and/or output arguments with other merge-related functions.
536 */
537 const struct got_error *got_worktree_merge_write_refs(struct got_worktree *,
538 struct got_reference *, struct got_repository *);
540 /*
541 * Continue an interrupted merge operation.
542 * This function returns name of the branch being merged, and the ID of the
543 * tip commit being merged.
544 * This function should be called before either resuming or aborting a
545 * merge operation.
546 * The function also returns a pointer to a fileindex which must be
547 * passed back to other merge-related functions.
548 */
549 const struct got_error *got_worktree_merge_continue(char **,
550 struct got_object_id **, struct got_fileindex **,
551 struct got_worktree *, struct got_repository *);
553 /*
554 * Abort the current rebase operation.
555 * Report reverted files via the specified progress callback.
556 */
557 const struct got_error *got_worktree_merge_abort(struct got_worktree *,
558 struct got_fileindex *, struct got_repository *,
559 got_worktree_checkout_cb, void *);
561 /*
562 * Stage the specified paths for commit.
563 * If the patch callback is not NULL, call it to select patch hunks for
564 * staging. Otherwise, stage the full file content found at each path.
565 * If a path being staged contains a symlink which points outside
566 * of the path space under version control, raise an error unless
567 * staging of such paths is being forced by the caller.
568 */
569 const struct got_error *got_worktree_stage(struct got_worktree *,
570 struct got_pathlist_head *, got_worktree_status_cb, void *,
571 got_worktree_patch_cb, void *, int, struct got_repository *);
573 /*
574 * Merge staged changes for the specified paths back into the work tree
575 * and mark the paths as non-staged again.
576 */
577 const struct got_error *got_worktree_unstage(struct got_worktree *,
578 struct got_pathlist_head *, got_worktree_checkout_cb, void *,
579 got_worktree_patch_cb, void *, struct got_repository *);
581 /* A callback function which is invoked with per-path info. */
582 typedef const struct got_error *(*got_worktree_path_info_cb)(void *,
583 const char *path, mode_t mode, time_t mtime,
584 struct got_object_id *blob_id, struct got_object_id *staged_blob_id,
585 struct got_object_id *commit_id);
587 /*
588 * Report work-tree meta data for paths in the work tree.
589 * The info callback will be invoked with the provided void * argument,
590 * a path, and meta-data arguments (see got_worktree_path_info_cb).
591 */
592 const struct got_error *
593 got_worktree_path_info(struct got_worktree *, struct got_pathlist_head *,
594 got_worktree_path_info_cb, void *, got_cancel_cb , void *);
596 /* References pointing at pre-rebase commit backups. */
597 #define GOT_WORKTREE_REBASE_BACKUP_REF_PREFIX "refs/got/backup/rebase"
599 /* References pointing at pre-histedit commit backups. */
600 #define GOT_WORKTREE_HISTEDIT_BACKUP_REF_PREFIX "refs/got/backup/histedit"
602 /*
603 * Prepare for applying a patch.
604 */
605 const struct got_error *
606 got_worktree_patch_prepare(struct got_fileindex **, char **,
607 struct got_worktree *);
609 /*
610 * Lookup paths for the "old" and "new" file before patching and check their
611 * status.
612 */
613 const struct got_error *
614 got_worktree_patch_check_path(const char *, const char *, char **, char **,
615 struct got_worktree *, struct got_repository *, struct got_fileindex *);
617 const struct got_error *
618 got_worktree_patch_schedule_add(const char *, struct got_repository *,
619 struct got_worktree *, struct got_fileindex *, got_worktree_checkout_cb,
620 void *);
622 const struct got_error *
623 got_worktree_patch_schedule_rm(const char *, struct got_repository *,
624 struct got_worktree *, struct got_fileindex *, got_worktree_delete_cb,
625 void *);
627 /* Complete the patch operation. */
628 const struct got_error *
629 got_worktree_patch_complete(struct got_fileindex *, const char *);