2 * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
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.
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.
20 #define GOT_STATUS_ADD 'A'
21 #define GOT_STATUS_EXISTS 'E'
24 * Attempt to initialize a new work tree on disk.
25 * The first argument is the path to a directory where the work tree
26 * will be created. The path itself must not yet exist, but the dirname(3)
27 * of the path must already exist.
28 * The reference provided will be used to determine the new worktree's
29 * base commit. The third argument speficies the work tree's path prefix.
31 const struct got_error *got_worktree_init(const char *, struct got_reference *,
32 const char *, struct got_repository *);
35 * Attempt to open a worktree at the specified path.
36 * The caller must dispose of it with got_worktree_close().
38 const struct got_error *got_worktree_open(struct got_worktree **, const char *);
40 /* Dispose of an open work tree. */
41 void got_worktree_close(struct got_worktree *);
44 * Get the path to the repository associated with a worktree.
45 * The caller must dispose of it with free(3).
47 char *got_worktree_get_repo_path(struct got_worktree *);
50 * Get the name of a work tree's HEAD reference.
51 * The caller must dispose of it with free(3).
53 char *got_worktree_get_head_ref_name(struct got_worktree *);
55 /* A callback function which is invoked when a path is checked out. */
56 typedef void (*got_worktree_checkout_cb)(void *, unsigned char, const char *);
58 /* A callback function which is invoked at cancellation points.
59 * May return GOT_ERR_CANCELLED to abort the runing operation. */
60 typedef const struct got_error *(*got_worktree_cancel_cb)(void *);
63 * Attempt to check out files into a work tree from its associated repository
64 * and path prefix, and update the work tree's file index accordingly.
65 * File content is obtained from blobs within the work tree's path prefix
66 * inside the tree corresponding to the work tree's base commit.
67 * The checkout progress callback will be invoked with the provided
68 * void * argument, and the path of each checked out file.
70 const struct got_error *got_worktree_checkout_files(struct got_worktree *,
71 struct got_repository *, got_worktree_checkout_cb progress, void *,
72 got_worktree_cancel_cb, void *);