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 86c3caaf 2018-03-09 stsp
19 eecfbcd1 2018-12-29 stsp /* status codes */
20 f8d1f275 2019-02-04 stsp #define GOT_STATUS_NO_CHANGE ' '
21 eecfbcd1 2018-12-29 stsp #define GOT_STATUS_ADD 'A'
22 eecfbcd1 2018-12-29 stsp #define GOT_STATUS_EXISTS 'E'
23 507dc3bb 2018-12-29 stsp #define GOT_STATUS_UPDATE 'U'
24 512f0d0e 2019-01-02 stsp #define GOT_STATUS_DELETE 'D'
25 276262e8 2019-02-08 stsp #define GOT_STATUS_MODIFY 'M'
26 6353ad76 2019-02-08 stsp #define GOT_STATUS_CONFLICT 'C'
27 6353ad76 2019-02-08 stsp #define GOT_STATUS_MERGE 'G'
28 f8d1f275 2019-02-04 stsp #define GOT_STATUS_MISSING '!'
29 f8d1f275 2019-02-04 stsp #define GOT_STATUS_UNVERSIONED '?'
30 0dbc2271 2019-02-05 stsp #define GOT_STATUS_OBSTRUCTED '~'
31 eecfbcd1 2018-12-29 stsp
32 0c60ce5a 2018-04-02 stsp /*
33 0c60ce5a 2018-04-02 stsp * Attempt to initialize a new work tree on disk.
34 0c60ce5a 2018-04-02 stsp * The first argument is the path to a directory where the work tree
35 0c60ce5a 2018-04-02 stsp * will be created. The path itself must not yet exist, but the dirname(3)
36 0c60ce5a 2018-04-02 stsp * of the path must already exist.
37 93a30277 2018-12-24 stsp * The reference provided will be used to determine the new worktree's
38 93a30277 2018-12-24 stsp * base commit. The third argument speficies the work tree's path prefix.
39 0c60ce5a 2018-04-02 stsp */
40 86c3caaf 2018-03-09 stsp const struct got_error *got_worktree_init(const char *, struct got_reference *,
41 577ec78f 2018-03-11 stsp const char *, struct got_repository *);
42 0c60ce5a 2018-04-02 stsp
43 0c60ce5a 2018-04-02 stsp /*
44 247140b2 2019-02-05 stsp * Attempt to open a worktree at or above the specified path.
45 0c60ce5a 2018-04-02 stsp * The caller must dispose of it with got_worktree_close().
46 0c60ce5a 2018-04-02 stsp */
47 86c3caaf 2018-03-09 stsp const struct got_error *got_worktree_open(struct got_worktree **, const char *);
48 0c60ce5a 2018-04-02 stsp
49 0c60ce5a 2018-04-02 stsp /* Dispose of an open work tree. */
50 3a6ce05a 2019-02-11 stsp const struct got_error *got_worktree_close(struct got_worktree *);
51 0c60ce5a 2018-04-02 stsp
52 0c60ce5a 2018-04-02 stsp /*
53 c7f4312f 2019-02-05 stsp * Get the path to the root directory of a worktree.
54 c7f4312f 2019-02-05 stsp */
55 c7f4312f 2019-02-05 stsp const char *got_worktree_get_root_path(struct got_worktree *);
56 c7f4312f 2019-02-05 stsp
57 c7f4312f 2019-02-05 stsp /*
58 0c60ce5a 2018-04-02 stsp * Get the path to the repository associated with a worktree.
59 0c60ce5a 2018-04-02 stsp */
60 2fbdb5ae 2018-12-29 stsp const char *got_worktree_get_repo_path(struct got_worktree *);
61 0c60ce5a 2018-04-02 stsp
62 0c60ce5a 2018-04-02 stsp /*
63 49520a32 2018-12-29 stsp * Get the path prefix associated with a worktree.
64 49520a32 2018-12-29 stsp */
65 49520a32 2018-12-29 stsp const char *got_worktree_get_path_prefix(struct got_worktree *);
66 49520a32 2018-12-29 stsp
67 49520a32 2018-12-29 stsp /*
68 e5dc7198 2018-12-29 stsp * Check if a user-provided path prefix matches that of the worktree.
69 e5dc7198 2018-12-29 stsp */
70 e5dc7198 2018-12-29 stsp const struct got_error *got_worktree_match_path_prefix(int *,
71 e5dc7198 2018-12-29 stsp struct got_worktree *, const char *);
72 e5dc7198 2018-12-29 stsp
73 e5dc7198 2018-12-29 stsp /*
74 0c60ce5a 2018-04-02 stsp * Get the name of a work tree's HEAD reference.
75 0c60ce5a 2018-04-02 stsp * The caller must dispose of it with free(3).
76 0c60ce5a 2018-04-02 stsp */
77 6c34b1aa 2019-03-18 stsp char *got_worktree_get_head_ref_name(struct got_worktree *);
78 0c60ce5a 2018-04-02 stsp
79 507dc3bb 2018-12-29 stsp /*
80 be7061eb 2018-12-30 stsp * Get the work tree's HEAD reference.
81 be7061eb 2018-12-30 stsp * The caller must dispose of it with free(3).
82 be7061eb 2018-12-30 stsp */
83 be7061eb 2018-12-30 stsp struct got_reference *got_worktree_get_head_ref(struct got_worktree *);
84 be7061eb 2018-12-30 stsp
85 be7061eb 2018-12-30 stsp /*
86 507dc3bb 2018-12-29 stsp * Get the current base commit ID of a worktree.
87 507dc3bb 2018-12-29 stsp */
88 b72f483a 2019-02-05 stsp struct got_object_id *got_worktree_get_base_commit_id(struct got_worktree *);
89 507dc3bb 2018-12-29 stsp
90 507dc3bb 2018-12-29 stsp /*
91 507dc3bb 2018-12-29 stsp * Set the base commit Id of a worktree.
92 507dc3bb 2018-12-29 stsp */
93 507dc3bb 2018-12-29 stsp const struct got_error *got_worktree_set_base_commit_id(struct got_worktree *,
94 507dc3bb 2018-12-29 stsp struct got_repository *, struct got_object_id *);
95 507dc3bb 2018-12-29 stsp
96 0c60ce5a 2018-04-02 stsp /* A callback function which is invoked when a path is checked out. */
97 a0eb853d 2018-12-29 stsp typedef void (*got_worktree_checkout_cb)(void *, unsigned char, const char *);
98 0c60ce5a 2018-04-02 stsp
99 99437157 2018-11-11 stsp /* A callback function which is invoked at cancellation points.
100 99437157 2018-11-11 stsp * May return GOT_ERR_CANCELLED to abort the runing operation. */
101 99437157 2018-11-11 stsp typedef const struct got_error *(*got_worktree_cancel_cb)(void *);
102 99437157 2018-11-11 stsp
103 0c60ce5a 2018-04-02 stsp /*
104 0c60ce5a 2018-04-02 stsp * Attempt to check out files into a work tree from its associated repository
105 0c60ce5a 2018-04-02 stsp * and path prefix, and update the work tree's file index accordingly.
106 0c60ce5a 2018-04-02 stsp * File content is obtained from blobs within the work tree's path prefix
107 93a30277 2018-12-24 stsp * inside the tree corresponding to the work tree's base commit.
108 0c60ce5a 2018-04-02 stsp * The checkout progress callback will be invoked with the provided
109 0c60ce5a 2018-04-02 stsp * void * argument, and the path of each checked out file.
110 0c60ce5a 2018-04-02 stsp */
111 86c3caaf 2018-03-09 stsp const struct got_error *got_worktree_checkout_files(struct got_worktree *,
112 93a30277 2018-12-24 stsp struct got_repository *, got_worktree_checkout_cb progress, void *,
113 99437157 2018-11-11 stsp got_worktree_cancel_cb, void *);
114 507dc3bb 2018-12-29 stsp
115 f8d1f275 2019-02-04 stsp /* A callback function which is invoked to report a path's status. */
116 b72f483a 2019-02-05 stsp typedef const struct got_error *(*got_worktree_status_cb)(void *,
117 b72f483a 2019-02-05 stsp unsigned char, const char *, struct got_object_id *);
118 f8d1f275 2019-02-04 stsp
119 f8d1f275 2019-02-04 stsp /*
120 f8d1f275 2019-02-04 stsp * Report the status of paths in the work tree.
121 f8d1f275 2019-02-04 stsp * The status callback will be invoked with the provided void * argument,
122 f8d1f275 2019-02-04 stsp * a path, and a corresponding status code.
123 f8d1f275 2019-02-04 stsp */
124 6c34b1aa 2019-03-18 stsp const struct got_error *got_worktree_status(struct got_worktree *,
125 6c34b1aa 2019-03-18 stsp const char *, struct got_repository *, got_worktree_status_cb, void *,
126 927df6b7 2019-02-10 stsp got_worktree_cancel_cb cancel_cb, void *);
127 6c7ab921 2019-03-18 stsp
128 6c7ab921 2019-03-18 stsp /*
129 6c7ab921 2019-03-18 stsp * Try to resolve a user-provided path to an on-disk path in the work tree.
130 6c7ab921 2019-03-18 stsp * The caller must dispose of the resolved path with free(3).
131 6c7ab921 2019-03-18 stsp */
132 6c7ab921 2019-03-18 stsp const struct got_error *got_worktree_resolve_path(char **,
133 6c7ab921 2019-03-18 stsp struct got_worktree *, const char *);