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 86c3caaf 2018-03-09 stsp
21 eecfbcd1 2018-12-29 stsp /* status codes */
22 f8d1f275 2019-02-04 stsp #define GOT_STATUS_NO_CHANGE ' '
23 eecfbcd1 2018-12-29 stsp #define GOT_STATUS_ADD 'A'
24 eecfbcd1 2018-12-29 stsp #define GOT_STATUS_EXISTS 'E'
25 507dc3bb 2018-12-29 stsp #define GOT_STATUS_UPDATE 'U'
26 512f0d0e 2019-01-02 stsp #define GOT_STATUS_DELETE 'D'
27 276262e8 2019-02-08 stsp #define GOT_STATUS_MODIFY 'M'
28 6353ad76 2019-02-08 stsp #define GOT_STATUS_CONFLICT 'C'
29 6353ad76 2019-02-08 stsp #define GOT_STATUS_MERGE 'G'
30 f8d1f275 2019-02-04 stsp #define GOT_STATUS_MISSING '!'
31 f8d1f275 2019-02-04 stsp #define GOT_STATUS_UNVERSIONED '?'
32 0dbc2271 2019-02-05 stsp #define GOT_STATUS_OBSTRUCTED '~'
33 a129376b 2019-03-28 stsp #define GOT_STATUS_REVERT 'R'
34 2b92fad7 2019-06-02 stsp #define GOT_STATUS_CANNOT_DELETE 'd'
35 a484d721 2019-06-10 stsp #define GOT_STATUS_BUMP_BASE 'b'
36 eecfbcd1 2018-12-29 stsp
37 0c60ce5a 2018-04-02 stsp /*
38 0c60ce5a 2018-04-02 stsp * Attempt to initialize a new work tree on disk.
39 0c60ce5a 2018-04-02 stsp * The first argument is the path to a directory where the work tree
40 0c60ce5a 2018-04-02 stsp * will be created. The path itself must not yet exist, but the dirname(3)
41 0c60ce5a 2018-04-02 stsp * of the path must already exist.
42 93a30277 2018-12-24 stsp * The reference provided will be used to determine the new worktree's
43 93a30277 2018-12-24 stsp * base commit. The third argument speficies the work tree's path prefix.
44 0c60ce5a 2018-04-02 stsp */
45 86c3caaf 2018-03-09 stsp const struct got_error *got_worktree_init(const char *, struct got_reference *,
46 577ec78f 2018-03-11 stsp const char *, struct got_repository *);
47 0c60ce5a 2018-04-02 stsp
48 0c60ce5a 2018-04-02 stsp /*
49 247140b2 2019-02-05 stsp * Attempt to open a worktree at or above the specified path.
50 0c60ce5a 2018-04-02 stsp * The caller must dispose of it with got_worktree_close().
51 0c60ce5a 2018-04-02 stsp */
52 86c3caaf 2018-03-09 stsp const struct got_error *got_worktree_open(struct got_worktree **, const char *);
53 0c60ce5a 2018-04-02 stsp
54 0c60ce5a 2018-04-02 stsp /* Dispose of an open work tree. */
55 3a6ce05a 2019-02-11 stsp const struct got_error *got_worktree_close(struct got_worktree *);
56 0c60ce5a 2018-04-02 stsp
57 0c60ce5a 2018-04-02 stsp /*
58 c7f4312f 2019-02-05 stsp * Get the path to the root directory of a worktree.
59 c7f4312f 2019-02-05 stsp */
60 c7f4312f 2019-02-05 stsp const char *got_worktree_get_root_path(struct got_worktree *);
61 c7f4312f 2019-02-05 stsp
62 c7f4312f 2019-02-05 stsp /*
63 0c60ce5a 2018-04-02 stsp * Get the path to the repository associated with a worktree.
64 0c60ce5a 2018-04-02 stsp */
65 2fbdb5ae 2018-12-29 stsp const char *got_worktree_get_repo_path(struct got_worktree *);
66 0c60ce5a 2018-04-02 stsp
67 0c60ce5a 2018-04-02 stsp /*
68 49520a32 2018-12-29 stsp * Get the path prefix associated with a worktree.
69 49520a32 2018-12-29 stsp */
70 49520a32 2018-12-29 stsp const char *got_worktree_get_path_prefix(struct got_worktree *);
71 49520a32 2018-12-29 stsp
72 49520a32 2018-12-29 stsp /*
73 e5dc7198 2018-12-29 stsp * Check if a user-provided path prefix matches that of the worktree.
74 e5dc7198 2018-12-29 stsp */
75 e5dc7198 2018-12-29 stsp const struct got_error *got_worktree_match_path_prefix(int *,
76 e5dc7198 2018-12-29 stsp struct got_worktree *, const char *);
77 e5dc7198 2018-12-29 stsp
78 e5dc7198 2018-12-29 stsp /*
79 0c60ce5a 2018-04-02 stsp * Get the name of a work tree's HEAD reference.
80 0c60ce5a 2018-04-02 stsp */
81 bc70eb79 2019-05-09 stsp const char *got_worktree_get_head_ref_name(struct got_worktree *);
82 0c60ce5a 2018-04-02 stsp
83 507dc3bb 2018-12-29 stsp /*
84 024e9686 2019-05-14 stsp * Set the branch head reference of the work tree.
85 024e9686 2019-05-14 stsp */
86 024e9686 2019-05-14 stsp const struct got_error *got_worktree_set_head_ref(struct got_worktree *,
87 024e9686 2019-05-14 stsp struct got_reference *);
88 024e9686 2019-05-14 stsp
89 024e9686 2019-05-14 stsp /*
90 507dc3bb 2018-12-29 stsp * Get the current base commit ID of a worktree.
91 507dc3bb 2018-12-29 stsp */
92 b72f483a 2019-02-05 stsp struct got_object_id *got_worktree_get_base_commit_id(struct got_worktree *);
93 507dc3bb 2018-12-29 stsp
94 507dc3bb 2018-12-29 stsp /*
95 507dc3bb 2018-12-29 stsp * Set the base commit Id of a worktree.
96 507dc3bb 2018-12-29 stsp */
97 507dc3bb 2018-12-29 stsp const struct got_error *got_worktree_set_base_commit_id(struct got_worktree *,
98 507dc3bb 2018-12-29 stsp struct got_repository *, struct got_object_id *);
99 507dc3bb 2018-12-29 stsp
100 0c60ce5a 2018-04-02 stsp /* A callback function which is invoked when a path is checked out. */
101 1ee397ad 2019-07-12 stsp typedef const struct got_error *(*got_worktree_checkout_cb)(void *,
102 1ee397ad 2019-07-12 stsp unsigned char, const char *);
103 0c60ce5a 2018-04-02 stsp
104 99437157 2018-11-11 stsp /* A callback function which is invoked at cancellation points.
105 99437157 2018-11-11 stsp * May return GOT_ERR_CANCELLED to abort the runing operation. */
106 99437157 2018-11-11 stsp typedef const struct got_error *(*got_worktree_cancel_cb)(void *);
107 99437157 2018-11-11 stsp
108 0c60ce5a 2018-04-02 stsp /*
109 0c60ce5a 2018-04-02 stsp * Attempt to check out files into a work tree from its associated repository
110 0c60ce5a 2018-04-02 stsp * and path prefix, and update the work tree's file index accordingly.
111 0c60ce5a 2018-04-02 stsp * File content is obtained from blobs within the work tree's path prefix
112 93a30277 2018-12-24 stsp * inside the tree corresponding to the work tree's base commit.
113 0c60ce5a 2018-04-02 stsp * The checkout progress callback will be invoked with the provided
114 0c60ce5a 2018-04-02 stsp * void * argument, and the path of each checked out file.
115 c4cdcb68 2019-04-03 stsp *
116 c4cdcb68 2019-04-03 stsp * It is possible to restrict the checkout operation to a specific path in
117 c4cdcb68 2019-04-03 stsp * the work tree, in which case all files outside this path will remain at
118 c4cdcb68 2019-04-03 stsp * their currently recorded base commit. Inconsistent base commits can be
119 c4cdcb68 2019-04-03 stsp * repaired later by running another update operation across the entire work
120 c4cdcb68 2019-04-03 stsp * tree. Inconsistent base-commits may also occur if this function runs into
121 c4cdcb68 2019-04-03 stsp * an error or if the checkout operation is cancelled by the cancel callback.
122 c4cdcb68 2019-04-03 stsp * The specified path is relative to the work tree's root. Pass "" to check
123 c4cdcb68 2019-04-03 stsp * out files across the entire work tree.
124 c4cdcb68 2019-04-03 stsp *
125 c4cdcb68 2019-04-03 stsp * Some operations may refuse to run while the work tree contains files from
126 c4cdcb68 2019-04-03 stsp * multiple base commits.
127 0c60ce5a 2018-04-02 stsp */
128 86c3caaf 2018-03-09 stsp const struct got_error *got_worktree_checkout_files(struct got_worktree *,
129 c4cdcb68 2019-04-03 stsp const char *, struct got_repository *, got_worktree_checkout_cb, void *,
130 99437157 2018-11-11 stsp got_worktree_cancel_cb, void *);
131 507dc3bb 2018-12-29 stsp
132 234035bc 2019-06-01 stsp /* Merge the differences between two commits into a work tree. */
133 234035bc 2019-06-01 stsp const struct got_error *
134 234035bc 2019-06-01 stsp got_worktree_merge_files(struct got_worktree *,
135 234035bc 2019-06-01 stsp struct got_object_id *, struct got_object_id *,
136 234035bc 2019-06-01 stsp struct got_repository *, got_worktree_checkout_cb, void *,
137 234035bc 2019-06-01 stsp got_worktree_cancel_cb, void *);
138 234035bc 2019-06-01 stsp
139 f8d1f275 2019-02-04 stsp /* A callback function which is invoked to report a path's status. */
140 b72f483a 2019-02-05 stsp typedef const struct got_error *(*got_worktree_status_cb)(void *,
141 016a88dd 2019-05-13 stsp unsigned char, const char *, struct got_object_id *,
142 016a88dd 2019-05-13 stsp struct got_object_id *);
143 f8d1f275 2019-02-04 stsp
144 f8d1f275 2019-02-04 stsp /*
145 f8d1f275 2019-02-04 stsp * Report the status of paths in the work tree.
146 f8d1f275 2019-02-04 stsp * The status callback will be invoked with the provided void * argument,
147 f8d1f275 2019-02-04 stsp * a path, and a corresponding status code.
148 f8d1f275 2019-02-04 stsp */
149 6c34b1aa 2019-03-18 stsp const struct got_error *got_worktree_status(struct got_worktree *,
150 6c34b1aa 2019-03-18 stsp const char *, struct got_repository *, got_worktree_status_cb, void *,
151 927df6b7 2019-02-10 stsp got_worktree_cancel_cb cancel_cb, void *);
152 6c7ab921 2019-03-18 stsp
153 6c7ab921 2019-03-18 stsp /*
154 6c7ab921 2019-03-18 stsp * Try to resolve a user-provided path to an on-disk path in the work tree.
155 6c7ab921 2019-03-18 stsp * The caller must dispose of the resolved path with free(3).
156 6c7ab921 2019-03-18 stsp */
157 6c7ab921 2019-03-18 stsp const struct got_error *got_worktree_resolve_path(char **,
158 6c7ab921 2019-03-18 stsp struct got_worktree *, const char *);
159 d00136be 2019-03-26 stsp
160 1dd54920 2019-05-11 stsp /* Schedule files at on-disk paths for addition in the next commit. */
161 031a5338 2019-03-26 stsp const struct got_error *got_worktree_schedule_add(struct got_worktree *,
162 1dd54920 2019-05-11 stsp struct got_pathlist_head *, got_worktree_status_cb, void *,
163 1dd54920 2019-05-11 stsp struct got_repository *);
164 2ec1f75b 2019-03-26 stsp
165 2ec1f75b 2019-03-26 stsp /*
166 17ed4618 2019-06-02 stsp * Remove files from disk and schedule them to be deleted in the next commit.
167 2ec1f75b 2019-03-26 stsp * Don't allow deleting files with uncommitted modifications, unless the
168 2ec1f75b 2019-03-26 stsp * parameter 'delete_local_mods' is set.
169 2ec1f75b 2019-03-26 stsp */
170 2ec1f75b 2019-03-26 stsp const struct got_error *
171 17ed4618 2019-06-02 stsp got_worktree_schedule_delete(struct got_worktree *,
172 17ed4618 2019-06-02 stsp struct got_pathlist_head *, int, got_worktree_status_cb, void *,
173 17ed4618 2019-06-02 stsp struct got_repository *);
174 a129376b 2019-03-28 stsp
175 a129376b 2019-03-28 stsp /*
176 a129376b 2019-03-28 stsp * Revert a file at the specified path such that it matches its
177 a129376b 2019-03-28 stsp * original state in the worktree's base commit.
178 a129376b 2019-03-28 stsp */
179 a129376b 2019-03-28 stsp const struct got_error *got_worktree_revert(struct got_worktree *,
180 e20a8b6f 2019-06-04 stsp struct got_pathlist_head *, got_worktree_checkout_cb, void *,
181 e20a8b6f 2019-06-04 stsp struct got_repository *);
182 c4296144 2019-05-09 stsp
183 c4296144 2019-05-09 stsp /*
184 33ad4cbe 2019-05-12 jcs * A callback function which is invoked when a commit message is requested.
185 8656d6c4 2019-05-20 stsp * Passes a pathlist with a struct got_commitable * in the data pointer of
186 8656d6c4 2019-05-20 stsp * each element, a pointer to the log message that must be set by the
187 8656d6c4 2019-05-20 stsp * callback and will be freed after committing, and an argument passed
188 8656d6c4 2019-05-20 stsp * through to the callback.
189 33ad4cbe 2019-05-12 jcs */
190 33ad4cbe 2019-05-12 jcs typedef const struct got_error *(*got_worktree_commit_msg_cb)(
191 33ad4cbe 2019-05-12 jcs struct got_pathlist_head *, char **, void *);
192 33ad4cbe 2019-05-12 jcs
193 33ad4cbe 2019-05-12 jcs /*
194 c4296144 2019-05-09 stsp * Create a new commit from changes in the work tree.
195 c4296144 2019-05-09 stsp * Return the ID of the newly created commit.
196 c4296144 2019-05-09 stsp * The worktree's base commit will be set to this new commit.
197 c4296144 2019-05-09 stsp * Files unaffected by this commit operation will retain their
198 c4296144 2019-05-09 stsp * current base commit.
199 de18fc63 2019-05-09 stsp * An author and a non-empty log message must be specified.
200 de18fc63 2019-05-09 stsp * The name of the committer is optional (may be NULL).
201 c4296144 2019-05-09 stsp * If an on-disk path is specified, only commit changes at or within this path.
202 c4296144 2019-05-09 stsp */
203 de18fc63 2019-05-09 stsp const struct got_error *got_worktree_commit(struct got_object_id **,
204 de18fc63 2019-05-09 stsp struct got_worktree *, const char *, const char *, const char *,
205 33ad4cbe 2019-05-12 jcs got_worktree_commit_msg_cb, void *,
206 33ad4cbe 2019-05-12 jcs got_worktree_status_cb, void *, struct got_repository *);
207 8656d6c4 2019-05-20 stsp
208 8656d6c4 2019-05-20 stsp /* Get the path of a commitable worktree item. */
209 8656d6c4 2019-05-20 stsp const char *got_commitable_get_path(struct got_commitable *);
210 8656d6c4 2019-05-20 stsp
211 8656d6c4 2019-05-20 stsp /* Get the status of a commitable worktree item. */
212 8656d6c4 2019-05-20 stsp unsigned int got_commitable_get_status(struct got_commitable *);
213 818c7501 2019-07-11 stsp
214 818c7501 2019-07-11 stsp /*
215 818c7501 2019-07-11 stsp * Prepare for rebasing a branch onto the work tree's current branch.
216 818c7501 2019-07-11 stsp * This function creates references to a temporary branch, the branch
217 818c7501 2019-07-11 stsp * being rebased, and the work tree's current branch, under the
218 818c7501 2019-07-11 stsp * "got/worktree/rebase/" namespace. These references are used to
219 818c7501 2019-07-11 stsp * keep track of rebase operation state and are used as input and/or
220 818c7501 2019-07-11 stsp * output arguments with other rebase-related functions.
221 818c7501 2019-07-11 stsp */
222 818c7501 2019-07-11 stsp const struct got_error *got_worktree_rebase_prepare(struct got_reference **,
223 818c7501 2019-07-11 stsp struct got_reference **, struct got_worktree *, struct got_reference *,
224 818c7501 2019-07-11 stsp struct got_repository *);
225 818c7501 2019-07-11 stsp
226 818c7501 2019-07-11 stsp /*
227 818c7501 2019-07-11 stsp * Continue an interrupted rebase operation.
228 818c7501 2019-07-11 stsp * This function returns existing references created when rebase was prepared,
229 818c7501 2019-07-11 stsp * and the ID of the commit currently being rebased. This should be called
230 818c7501 2019-07-11 stsp * before either resuming or aborting a rebase operation.
231 818c7501 2019-07-11 stsp */
232 818c7501 2019-07-11 stsp const struct got_error *got_worktree_rebase_continue(struct got_object_id **,
233 818c7501 2019-07-11 stsp struct got_reference **, struct got_reference **, struct got_reference **,
234 818c7501 2019-07-11 stsp struct got_worktree *, struct got_repository *);
235 818c7501 2019-07-11 stsp
236 818c7501 2019-07-11 stsp /* Check whether a, potentially interrupted, rebase operation is in progress. */
237 818c7501 2019-07-11 stsp const struct got_error *got_worktree_rebase_in_progress(int *,
238 818c7501 2019-07-11 stsp struct got_worktree *);
239 818c7501 2019-07-11 stsp
240 818c7501 2019-07-11 stsp /*
241 818c7501 2019-07-11 stsp * Merge changes from the commit currently being rebased into the work tree.
242 818c7501 2019-07-11 stsp * Report affected files, including merge conflicts, via the specified
243 01757395 2019-07-12 stsp * progress callback. Also populate a list of affected paths which should
244 01757395 2019-07-12 stsp * be passed to got_worktree_rebase_commit() after a conflict-free merge.
245 01757395 2019-07-12 stsp * This list must be initialized with TAILQ_INIT() and disposed of with
246 01757395 2019-07-12 stsp * got_worktree_rebase_pathlist_free().
247 818c7501 2019-07-11 stsp */
248 818c7501 2019-07-11 stsp const struct got_error *got_worktree_rebase_merge_files(
249 01757395 2019-07-12 stsp struct got_pathlist_head *, struct got_worktree *,
250 01757395 2019-07-12 stsp struct got_object_id *, struct got_object_id *, struct got_repository *,
251 01757395 2019-07-12 stsp got_worktree_checkout_cb, void *, got_worktree_cancel_cb, void *);
252 818c7501 2019-07-11 stsp
253 818c7501 2019-07-11 stsp /*
254 01757395 2019-07-12 stsp * Commit changes merged by got_worktree_rebase_merge_files() to a temporary
255 01757395 2019-07-12 stsp * branch and return the ID of the newly created commit. An optional list of
256 01757395 2019-07-12 stsp * merged paths can be provided; otherwise this function will perform a status
257 01757395 2019-07-12 stsp * crawl across the entire work tree to find paths to commit.
258 818c7501 2019-07-11 stsp */
259 818c7501 2019-07-11 stsp const struct got_error *got_worktree_rebase_commit(struct got_object_id **,
260 01757395 2019-07-12 stsp struct got_pathlist_head *, struct got_worktree *,
261 01757395 2019-07-12 stsp struct got_reference *, struct got_commit_object *,
262 818c7501 2019-07-11 stsp struct got_object_id *, struct got_repository *);
263 818c7501 2019-07-11 stsp
264 01757395 2019-07-12 stsp /* Free a list of merged paths from got_worktree_merge_files. */
265 01757395 2019-07-12 stsp void got_worktree_rebase_pathlist_free(struct got_pathlist_head *);
266 01757395 2019-07-12 stsp
267 818c7501 2019-07-11 stsp /* Postpone the rebase operation. Should be called after a merge conflict. */
268 818c7501 2019-07-11 stsp const struct got_error *got_worktree_rebase_postpone(struct got_worktree *);
269 818c7501 2019-07-11 stsp
270 818c7501 2019-07-11 stsp /*
271 818c7501 2019-07-11 stsp * Complete the current rebase operation. This should be called once all
272 818c7501 2019-07-11 stsp * commits have been rebased successfully.
273 818c7501 2019-07-11 stsp */
274 818c7501 2019-07-11 stsp const struct got_error *got_worktree_rebase_complete(struct got_worktree *,
275 818c7501 2019-07-11 stsp struct got_reference *, struct got_reference *, struct got_reference *,
276 818c7501 2019-07-11 stsp struct got_repository *);
277 818c7501 2019-07-11 stsp
278 818c7501 2019-07-11 stsp /*
279 818c7501 2019-07-11 stsp * Abort the current rebase operation.
280 818c7501 2019-07-11 stsp * Report reverted files via the specified progress callback.
281 818c7501 2019-07-11 stsp */
282 818c7501 2019-07-11 stsp const struct got_error *got_worktree_rebase_abort(struct got_worktree *,
283 818c7501 2019-07-11 stsp struct got_repository *, struct got_reference *,
284 818c7501 2019-07-11 stsp got_worktree_checkout_cb, void *);