Blob


1 /*
2 * Copyright (c) 2018 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_ADD 'A'
21 #define GOT_STATUS_EXISTS 'E'
22 #define GOT_STATUS_UPDATE 'U'
24 /*
25 * Attempt to initialize a new work tree on disk.
26 * The first argument is the path to a directory where the work tree
27 * will be created. The path itself must not yet exist, but the dirname(3)
28 * of the path must already exist.
29 * The reference provided will be used to determine the new worktree's
30 * base commit. The third argument speficies the work tree's path prefix.
31 */
32 const struct got_error *got_worktree_init(const char *, struct got_reference *,
33 const char *, struct got_repository *);
35 /*
36 * Attempt to open a worktree at the specified path.
37 * The caller must dispose of it with got_worktree_close().
38 */
39 const struct got_error *got_worktree_open(struct got_worktree **, const char *);
41 /* Dispose of an open work tree. */
42 void got_worktree_close(struct got_worktree *);
44 /*
45 * Get the path to the repository associated with a worktree.
46 */
47 const char *got_worktree_get_repo_path(struct got_worktree *);
49 /*
50 * Get the path prefix associated with a worktree.
51 */
52 const char *got_worktree_get_path_prefix(struct got_worktree *);
54 /*
55 * Check if a user-provided path prefix matches that of the worktree.
56 */
57 const struct got_error *got_worktree_match_path_prefix(int *,
58 struct got_worktree *, const char *);
60 /*
61 * Get the name of a work tree's HEAD reference.
62 * The caller must dispose of it with free(3).
63 */
64 char *got_worktree_get_head_ref_name(struct got_worktree *);
66 /*
67 * Get the current base commit ID of a worktree.
68 */
69 const struct got_object_id *got_worktree_get_base_commit_id(struct got_worktree *);
71 /*
72 * Set the base commit Id of a worktree.
73 */
74 const struct got_error *got_worktree_set_base_commit_id(struct got_worktree *,
75 struct got_repository *, struct got_object_id *);
77 /* A callback function which is invoked when a path is checked out. */
78 typedef void (*got_worktree_checkout_cb)(void *, unsigned char, const char *);
80 /* A callback function which is invoked at cancellation points.
81 * May return GOT_ERR_CANCELLED to abort the runing operation. */
82 typedef const struct got_error *(*got_worktree_cancel_cb)(void *);
84 /*
85 * Attempt to check out files into a work tree from its associated repository
86 * and path prefix, and update the work tree's file index accordingly.
87 * File content is obtained from blobs within the work tree's path prefix
88 * inside the tree corresponding to the work tree's base commit.
89 * The checkout progress callback will be invoked with the provided
90 * void * argument, and the path of each checked out file.
91 */
92 const struct got_error *got_worktree_checkout_files(struct got_worktree *,
93 struct got_repository *, got_worktree_checkout_cb progress, void *,
94 got_worktree_cancel_cb, void *);