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 {
18 char *root_path;
19 char *repo_path;
20 char *path_prefix;
21 struct got_object_id *base_commit_id;
22 char *head_ref_name;
23 uuid_t uuid;
25 /*
26 * File descriptor for the lock file, open while a work tree is open.
27 * When a work tree is opened, a shared lock on the lock file is
28 * acquired with flock(2). This shared lock is held until the work
29 * tree is closed, i.e. throughout the lifetime of any operation
30 * which uses a work tree.
31 * Before any modifications are made to the on-disk state of work
32 * tree meta data, tracked files, or directory tree structure, this
33 * shared lock must be upgraded to an exclusive lock.
34 */
35 int lockfd;
37 /* Absolute path to worktree's got.conf file. */
38 char *gotconfig_path;
40 /* Settings read from got.conf. */
41 struct got_gotconfig *gotconfig;
42 };
44 struct got_commitable {
45 char *path;
46 char *in_repo_path;
47 char *ondisk_path;
48 unsigned char status;
49 unsigned char staged_status;
50 struct got_object_id *blob_id;
51 struct got_object_id *base_blob_id;
52 struct got_object_id *staged_blob_id;
53 struct got_object_id *base_commit_id;
54 mode_t mode;
55 int flags;
56 #define GOT_COMMITABLE_ADDED 0x01
57 };
59 #define GOT_WORKTREE_GOT_DIR ".got"
60 #define GOT_WORKTREE_FILE_INDEX "file-index"
61 #define GOT_WORKTREE_REPOSITORY "repository"
62 #define GOT_WORKTREE_PATH_PREFIX "path-prefix"
63 #define GOT_WORKTREE_HEAD_REF "head-ref"
64 #define GOT_WORKTREE_BASE_COMMIT "base-commit"
65 #define GOT_WORKTREE_LOCK "lock"
66 #define GOT_WORKTREE_FORMAT "format"
67 #define GOT_WORKTREE_UUID "uuid"
68 #define GOT_WORKTREE_HISTEDIT_SCRIPT "histedit-script"
70 #define GOT_WORKTREE_FORMAT_VERSION 1
71 #define GOT_WORKTREE_INVALID_COMMIT_ID GOT_SHA1_STRING_ZERO
73 #define GOT_WORKTREE_BASE_REF_PREFIX "refs/got/worktree/base"
75 const struct got_error *got_worktree_get_base_ref_name(char **,
76 struct got_worktree *worktree);
78 /* Temporary branch which accumulates commits during a rebase operation. */
79 #define GOT_WORKTREE_REBASE_TMP_REF_PREFIX "refs/got/worktree/rebase/tmp"
81 /* Symbolic reference pointing at the name of the new base branch. */
82 #define GOT_WORKTREE_NEWBASE_REF_PREFIX "refs/got/worktree/rebase/newbase"
84 /* Symbolic reference pointing at the name of the branch being rebased. */
85 #define GOT_WORKTREE_REBASE_BRANCH_REF_PREFIX "refs/got/worktree/rebase/branch"
87 /* Reference pointing at the ID of the current commit being rebased. */
88 #define GOT_WORKTREE_REBASE_COMMIT_REF_PREFIX "refs/got/worktree/rebase/commit"
90 /* Temporary branch which accumulates commits during a histedit operation. */
91 #define GOT_WORKTREE_HISTEDIT_TMP_REF_PREFIX "refs/got/worktree/histedit/tmp"
93 /* Symbolic reference pointing at the name of the branch being edited. */
94 #define GOT_WORKTREE_HISTEDIT_BRANCH_REF_PREFIX \
95 "refs/got/worktree/histedit/branch"
97 /* Reference pointing at the ID of the work tree's pre-edit base commit. */
98 #define GOT_WORKTREE_HISTEDIT_BASE_COMMIT_REF_PREFIX \
99 "refs/got/worktree/histedit/base-commit"
101 /* Reference pointing at the ID of the current commit being edited. */
102 #define GOT_WORKTREE_HISTEDIT_COMMIT_REF_PREFIX \
103 "refs/got/worktree/histedit/commit"