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