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_MODIFIY 'M'
26 #define GOT_STATUS_MISSING '!'
27 #define GOT_STATUS_UNVERSIONED '?'
28 #define GOT_STATUS_OBSTRUCTED '~'
30 /*
31 * Attempt to initialize a new work tree on disk.
32 * The first argument is the path to a directory where the work tree
33 * will be created. The path itself must not yet exist, but the dirname(3)
34 * of the path must already exist.
35 * The reference provided will be used to determine the new worktree's
36 * base commit. The third argument speficies the work tree's path prefix.
37 */
38 const struct got_error *got_worktree_init(const char *, struct got_reference *,
39 const char *, struct got_repository *);
41 /*
42 * Attempt to open a worktree at or above the specified path.
43 * The caller must dispose of it with got_worktree_close().
44 */
45 const struct got_error *got_worktree_open(struct got_worktree **, const char *);
47 /* Dispose of an open work tree. */
48 void got_worktree_close(struct got_worktree *);
50 /*
51 * Get the path to the root directory of a worktree.
52 */
53 const char *got_worktree_get_root_path(struct got_worktree *);
55 /*
56 * Get the path to the repository associated with a worktree.
57 */
58 const char *got_worktree_get_repo_path(struct got_worktree *);
60 /*
61 * Get the path prefix associated with a worktree.
62 */
63 const char *got_worktree_get_path_prefix(struct got_worktree *);
65 /*
66 * Check if a user-provided path prefix matches that of the worktree.
67 */
68 const struct got_error *got_worktree_match_path_prefix(int *,
69 struct got_worktree *, const char *);
71 /*
72 * Get the name of a work tree's HEAD reference.
73 * The caller must dispose of it with free(3).
74 */
75 char *got_worktree_get_head_ref_name(struct got_worktree *);
77 /*
78 * Get the work tree's HEAD reference.
79 * The caller must dispose of it with free(3).
80 */
81 struct got_reference *got_worktree_get_head_ref(struct got_worktree *);
83 /*
84 * Get the current base commit ID of a worktree.
85 */
86 struct got_object_id *got_worktree_get_base_commit_id(struct got_worktree *);
88 /*
89 * Set the base commit Id of a worktree.
90 */
91 const struct got_error *got_worktree_set_base_commit_id(struct got_worktree *,
92 struct got_repository *, struct got_object_id *);
94 /* A callback function which is invoked when a path is checked out. */
95 typedef void (*got_worktree_checkout_cb)(void *, unsigned char, const char *);
97 /* A callback function which is invoked at cancellation points.
98 * May return GOT_ERR_CANCELLED to abort the runing operation. */
99 typedef const struct got_error *(*got_worktree_cancel_cb)(void *);
101 /*
102 * Attempt to check out files into a work tree from its associated repository
103 * and path prefix, and update the work tree's file index accordingly.
104 * File content is obtained from blobs within the work tree's path prefix
105 * inside the tree corresponding to the work tree's base commit.
106 * The checkout progress callback will be invoked with the provided
107 * void * argument, and the path of each checked out file.
108 */
109 const struct got_error *got_worktree_checkout_files(struct got_worktree *,
110 struct got_repository *, got_worktree_checkout_cb progress, void *,
111 got_worktree_cancel_cb, void *);
113 /* A callback function which is invoked to report a path's status. */
114 typedef const struct got_error *(*got_worktree_status_cb)(void *,
115 unsigned char, const char *, struct got_object_id *);
117 /*
118 * Report the status of paths in the work tree.
119 * The status callback will be invoked with the provided void * argument,
120 * a path, and a corresponding status code.
121 */
122 const struct got_error *
123 got_worktree_status(struct got_worktree *, struct got_repository *,
124 got_worktree_status_cb, void *, got_worktree_cancel_cb cancel_cb, void *);