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 86c3caaf 2018-03-09 stsp
20 eecfbcd1 2018-12-29 stsp /* status codes */
21 f8d1f275 2019-02-04 stsp #define GOT_STATUS_NO_CHANGE ' '
22 eecfbcd1 2018-12-29 stsp #define GOT_STATUS_ADD 'A'
23 eecfbcd1 2018-12-29 stsp #define GOT_STATUS_EXISTS 'E'
24 507dc3bb 2018-12-29 stsp #define GOT_STATUS_UPDATE 'U'
25 512f0d0e 2019-01-02 stsp #define GOT_STATUS_DELETE 'D'
26 276262e8 2019-02-08 stsp #define GOT_STATUS_MODIFY 'M'
27 6353ad76 2019-02-08 stsp #define GOT_STATUS_CONFLICT 'C'
28 6353ad76 2019-02-08 stsp #define GOT_STATUS_MERGE 'G'
29 f8d1f275 2019-02-04 stsp #define GOT_STATUS_MISSING '!'
30 f8d1f275 2019-02-04 stsp #define GOT_STATUS_UNVERSIONED '?'
31 0dbc2271 2019-02-05 stsp #define GOT_STATUS_OBSTRUCTED '~'
32 a129376b 2019-03-28 stsp #define GOT_STATUS_REVERT 'R'
33 eecfbcd1 2018-12-29 stsp
34 0c60ce5a 2018-04-02 stsp /*
35 0c60ce5a 2018-04-02 stsp * Attempt to initialize a new work tree on disk.
36 0c60ce5a 2018-04-02 stsp * The first argument is the path to a directory where the work tree
37 0c60ce5a 2018-04-02 stsp * will be created. The path itself must not yet exist, but the dirname(3)
38 0c60ce5a 2018-04-02 stsp * of the path must already exist.
39 93a30277 2018-12-24 stsp * The reference provided will be used to determine the new worktree's
40 93a30277 2018-12-24 stsp * base commit. The third argument speficies the work tree's path prefix.
41 0c60ce5a 2018-04-02 stsp */
42 86c3caaf 2018-03-09 stsp const struct got_error *got_worktree_init(const char *, struct got_reference *,
43 577ec78f 2018-03-11 stsp const char *, struct got_repository *);
44 0c60ce5a 2018-04-02 stsp
45 0c60ce5a 2018-04-02 stsp /*
46 247140b2 2019-02-05 stsp * Attempt to open a worktree at or above the specified path.
47 0c60ce5a 2018-04-02 stsp * The caller must dispose of it with got_worktree_close().
48 0c60ce5a 2018-04-02 stsp */
49 86c3caaf 2018-03-09 stsp const struct got_error *got_worktree_open(struct got_worktree **, const char *);
50 0c60ce5a 2018-04-02 stsp
51 0c60ce5a 2018-04-02 stsp /* Dispose of an open work tree. */
52 3a6ce05a 2019-02-11 stsp const struct got_error *got_worktree_close(struct got_worktree *);
53 0c60ce5a 2018-04-02 stsp
54 0c60ce5a 2018-04-02 stsp /*
55 c7f4312f 2019-02-05 stsp * Get the path to the root directory of a worktree.
56 c7f4312f 2019-02-05 stsp */
57 c7f4312f 2019-02-05 stsp const char *got_worktree_get_root_path(struct got_worktree *);
58 c7f4312f 2019-02-05 stsp
59 c7f4312f 2019-02-05 stsp /*
60 0c60ce5a 2018-04-02 stsp * Get the path to the repository associated with a worktree.
61 0c60ce5a 2018-04-02 stsp */
62 2fbdb5ae 2018-12-29 stsp const char *got_worktree_get_repo_path(struct got_worktree *);
63 0c60ce5a 2018-04-02 stsp
64 0c60ce5a 2018-04-02 stsp /*
65 49520a32 2018-12-29 stsp * Get the path prefix associated with a worktree.
66 49520a32 2018-12-29 stsp */
67 49520a32 2018-12-29 stsp const char *got_worktree_get_path_prefix(struct got_worktree *);
68 49520a32 2018-12-29 stsp
69 49520a32 2018-12-29 stsp /*
70 e5dc7198 2018-12-29 stsp * Check if a user-provided path prefix matches that of the worktree.
71 e5dc7198 2018-12-29 stsp */
72 e5dc7198 2018-12-29 stsp const struct got_error *got_worktree_match_path_prefix(int *,
73 e5dc7198 2018-12-29 stsp struct got_worktree *, const char *);
74 e5dc7198 2018-12-29 stsp
75 e5dc7198 2018-12-29 stsp /*
76 0c60ce5a 2018-04-02 stsp * Get the name of a work tree's HEAD reference.
77 0c60ce5a 2018-04-02 stsp */
78 bc70eb79 2019-05-09 stsp const char *got_worktree_get_head_ref_name(struct got_worktree *);
79 0c60ce5a 2018-04-02 stsp
80 507dc3bb 2018-12-29 stsp /*
81 024e9686 2019-05-14 stsp * Set the branch head reference of the work tree.
82 024e9686 2019-05-14 stsp */
83 024e9686 2019-05-14 stsp const struct got_error *got_worktree_set_head_ref(struct got_worktree *,
84 024e9686 2019-05-14 stsp struct got_reference *);
85 024e9686 2019-05-14 stsp
86 024e9686 2019-05-14 stsp /*
87 507dc3bb 2018-12-29 stsp * Get the current base commit ID of a worktree.
88 507dc3bb 2018-12-29 stsp */
89 b72f483a 2019-02-05 stsp struct got_object_id *got_worktree_get_base_commit_id(struct got_worktree *);
90 507dc3bb 2018-12-29 stsp
91 507dc3bb 2018-12-29 stsp /*
92 507dc3bb 2018-12-29 stsp * Set the base commit Id of a worktree.
93 507dc3bb 2018-12-29 stsp */
94 507dc3bb 2018-12-29 stsp const struct got_error *got_worktree_set_base_commit_id(struct got_worktree *,
95 507dc3bb 2018-12-29 stsp struct got_repository *, struct got_object_id *);
96 507dc3bb 2018-12-29 stsp
97 0c60ce5a 2018-04-02 stsp /* A callback function which is invoked when a path is checked out. */
98 a0eb853d 2018-12-29 stsp typedef void (*got_worktree_checkout_cb)(void *, unsigned char, const char *);
99 0c60ce5a 2018-04-02 stsp
100 99437157 2018-11-11 stsp /* A callback function which is invoked at cancellation points.
101 99437157 2018-11-11 stsp * May return GOT_ERR_CANCELLED to abort the runing operation. */
102 99437157 2018-11-11 stsp typedef const struct got_error *(*got_worktree_cancel_cb)(void *);
103 99437157 2018-11-11 stsp
104 0c60ce5a 2018-04-02 stsp /*
105 0c60ce5a 2018-04-02 stsp * Attempt to check out files into a work tree from its associated repository
106 0c60ce5a 2018-04-02 stsp * and path prefix, and update the work tree's file index accordingly.
107 0c60ce5a 2018-04-02 stsp * File content is obtained from blobs within the work tree's path prefix
108 93a30277 2018-12-24 stsp * inside the tree corresponding to the work tree's base commit.
109 0c60ce5a 2018-04-02 stsp * The checkout progress callback will be invoked with the provided
110 0c60ce5a 2018-04-02 stsp * void * argument, and the path of each checked out file.
111 c4cdcb68 2019-04-03 stsp *
112 c4cdcb68 2019-04-03 stsp * It is possible to restrict the checkout operation to a specific path in
113 c4cdcb68 2019-04-03 stsp * the work tree, in which case all files outside this path will remain at
114 c4cdcb68 2019-04-03 stsp * their currently recorded base commit. Inconsistent base commits can be
115 c4cdcb68 2019-04-03 stsp * repaired later by running another update operation across the entire work
116 c4cdcb68 2019-04-03 stsp * tree. Inconsistent base-commits may also occur if this function runs into
117 c4cdcb68 2019-04-03 stsp * an error or if the checkout operation is cancelled by the cancel callback.
118 c4cdcb68 2019-04-03 stsp * The specified path is relative to the work tree's root. Pass "" to check
119 c4cdcb68 2019-04-03 stsp * out files across the entire work tree.
120 c4cdcb68 2019-04-03 stsp *
121 c4cdcb68 2019-04-03 stsp * Some operations may refuse to run while the work tree contains files from
122 c4cdcb68 2019-04-03 stsp * multiple base commits.
123 0c60ce5a 2018-04-02 stsp */
124 86c3caaf 2018-03-09 stsp const struct got_error *got_worktree_checkout_files(struct got_worktree *,
125 c4cdcb68 2019-04-03 stsp const char *, struct got_repository *, got_worktree_checkout_cb, void *,
126 99437157 2018-11-11 stsp got_worktree_cancel_cb, void *);
127 507dc3bb 2018-12-29 stsp
128 234035bc 2019-06-01 stsp /* Merge the differences between two commits into a work tree. */
129 234035bc 2019-06-01 stsp const struct got_error *
130 234035bc 2019-06-01 stsp got_worktree_merge_files(struct got_worktree *,
131 234035bc 2019-06-01 stsp struct got_object_id *, struct got_object_id *,
132 234035bc 2019-06-01 stsp struct got_repository *, got_worktree_checkout_cb, void *,
133 234035bc 2019-06-01 stsp got_worktree_cancel_cb, void *);
134 234035bc 2019-06-01 stsp
135 f8d1f275 2019-02-04 stsp /* A callback function which is invoked to report a path's status. */
136 b72f483a 2019-02-05 stsp typedef const struct got_error *(*got_worktree_status_cb)(void *,
137 016a88dd 2019-05-13 stsp unsigned char, const char *, struct got_object_id *,
138 016a88dd 2019-05-13 stsp struct got_object_id *);
139 f8d1f275 2019-02-04 stsp
140 f8d1f275 2019-02-04 stsp /*
141 f8d1f275 2019-02-04 stsp * Report the status of paths in the work tree.
142 f8d1f275 2019-02-04 stsp * The status callback will be invoked with the provided void * argument,
143 f8d1f275 2019-02-04 stsp * a path, and a corresponding status code.
144 f8d1f275 2019-02-04 stsp */
145 6c34b1aa 2019-03-18 stsp const struct got_error *got_worktree_status(struct got_worktree *,
146 6c34b1aa 2019-03-18 stsp const char *, struct got_repository *, got_worktree_status_cb, void *,
147 927df6b7 2019-02-10 stsp got_worktree_cancel_cb cancel_cb, void *);
148 6c7ab921 2019-03-18 stsp
149 6c7ab921 2019-03-18 stsp /*
150 6c7ab921 2019-03-18 stsp * Try to resolve a user-provided path to an on-disk path in the work tree.
151 6c7ab921 2019-03-18 stsp * The caller must dispose of the resolved path with free(3).
152 6c7ab921 2019-03-18 stsp */
153 6c7ab921 2019-03-18 stsp const struct got_error *got_worktree_resolve_path(char **,
154 6c7ab921 2019-03-18 stsp struct got_worktree *, const char *);
155 d00136be 2019-03-26 stsp
156 1dd54920 2019-05-11 stsp /* Schedule files at on-disk paths for addition in the next commit. */
157 031a5338 2019-03-26 stsp const struct got_error *got_worktree_schedule_add(struct got_worktree *,
158 1dd54920 2019-05-11 stsp struct got_pathlist_head *, got_worktree_status_cb, void *,
159 1dd54920 2019-05-11 stsp struct got_repository *);
160 2ec1f75b 2019-03-26 stsp
161 2ec1f75b 2019-03-26 stsp /*
162 2ec1f75b 2019-03-26 stsp * Remove a file from disk and schedule it to be deleted in the next commit.
163 2ec1f75b 2019-03-26 stsp * Don't allow deleting files with uncommitted modifications, unless the
164 2ec1f75b 2019-03-26 stsp * parameter 'delete_local_mods' is set.
165 2ec1f75b 2019-03-26 stsp */
166 2ec1f75b 2019-03-26 stsp const struct got_error *
167 2ec1f75b 2019-03-26 stsp got_worktree_schedule_delete(struct got_worktree *, const char *, int,
168 2ec1f75b 2019-03-26 stsp got_worktree_status_cb, void *, struct got_repository *);
169 a129376b 2019-03-28 stsp
170 a129376b 2019-03-28 stsp /*
171 a129376b 2019-03-28 stsp * Revert a file at the specified path such that it matches its
172 a129376b 2019-03-28 stsp * original state in the worktree's base commit.
173 a129376b 2019-03-28 stsp */
174 a129376b 2019-03-28 stsp const struct got_error *got_worktree_revert(struct got_worktree *,
175 a129376b 2019-03-28 stsp const char *, got_worktree_checkout_cb, void *, struct got_repository *);
176 c4296144 2019-05-09 stsp
177 c4296144 2019-05-09 stsp /*
178 33ad4cbe 2019-05-12 jcs * A callback function which is invoked when a commit message is requested.
179 8656d6c4 2019-05-20 stsp * Passes a pathlist with a struct got_commitable * in the data pointer of
180 8656d6c4 2019-05-20 stsp * each element, a pointer to the log message that must be set by the
181 8656d6c4 2019-05-20 stsp * callback and will be freed after committing, and an argument passed
182 8656d6c4 2019-05-20 stsp * through to the callback.
183 33ad4cbe 2019-05-12 jcs */
184 33ad4cbe 2019-05-12 jcs typedef const struct got_error *(*got_worktree_commit_msg_cb)(
185 33ad4cbe 2019-05-12 jcs struct got_pathlist_head *, char **, void *);
186 33ad4cbe 2019-05-12 jcs
187 33ad4cbe 2019-05-12 jcs /*
188 c4296144 2019-05-09 stsp * Create a new commit from changes in the work tree.
189 c4296144 2019-05-09 stsp * Return the ID of the newly created commit.
190 c4296144 2019-05-09 stsp * The worktree's base commit will be set to this new commit.
191 c4296144 2019-05-09 stsp * Files unaffected by this commit operation will retain their
192 c4296144 2019-05-09 stsp * current base commit.
193 de18fc63 2019-05-09 stsp * An author and a non-empty log message must be specified.
194 de18fc63 2019-05-09 stsp * The name of the committer is optional (may be NULL).
195 c4296144 2019-05-09 stsp * If an on-disk path is specified, only commit changes at or within this path.
196 c4296144 2019-05-09 stsp */
197 de18fc63 2019-05-09 stsp const struct got_error *got_worktree_commit(struct got_object_id **,
198 de18fc63 2019-05-09 stsp struct got_worktree *, const char *, const char *, const char *,
199 33ad4cbe 2019-05-12 jcs got_worktree_commit_msg_cb, void *,
200 33ad4cbe 2019-05-12 jcs got_worktree_status_cb, void *, struct got_repository *);
201 8656d6c4 2019-05-20 stsp
202 8656d6c4 2019-05-20 stsp /* Get the path of a commitable worktree item. */
203 8656d6c4 2019-05-20 stsp const char *got_commitable_get_path(struct got_commitable *);
204 8656d6c4 2019-05-20 stsp
205 8656d6c4 2019-05-20 stsp /* Get the status of a commitable worktree item. */
206 8656d6c4 2019-05-20 stsp unsigned int got_commitable_get_status(struct got_commitable *);