Blame


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