Blame


1 718b3ab0 2018-03-17 stsp /*
2 718b3ab0 2018-03-17 stsp * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
3 718b3ab0 2018-03-17 stsp *
4 718b3ab0 2018-03-17 stsp * Permission to use, copy, modify, and distribute this software for any
5 718b3ab0 2018-03-17 stsp * purpose with or without fee is hereby granted, provided that the above
6 718b3ab0 2018-03-17 stsp * copyright notice and this permission notice appear in all copies.
7 718b3ab0 2018-03-17 stsp *
8 718b3ab0 2018-03-17 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 718b3ab0 2018-03-17 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 718b3ab0 2018-03-17 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 718b3ab0 2018-03-17 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 718b3ab0 2018-03-17 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 718b3ab0 2018-03-17 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 718b3ab0 2018-03-17 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 718b3ab0 2018-03-17 stsp */
16 718b3ab0 2018-03-17 stsp
17 718b3ab0 2018-03-17 stsp struct got_worktree {
18 718b3ab0 2018-03-17 stsp char *root_path;
19 718b3ab0 2018-03-17 stsp char *repo_path;
20 437adc9d 2020-12-10 yzhong int root_fd;
21 718b3ab0 2018-03-17 stsp char *path_prefix;
22 eaccb85f 2018-12-25 stsp struct got_object_id *base_commit_id;
23 36a38700 2019-05-10 stsp char *head_ref_name;
24 c442a90d 2019-03-10 stsp uuid_t uuid;
25 718b3ab0 2018-03-17 stsp
26 718b3ab0 2018-03-17 stsp /*
27 718b3ab0 2018-03-17 stsp * File descriptor for the lock file, open while a work tree is open.
28 718b3ab0 2018-03-17 stsp * When a work tree is opened, a shared lock on the lock file is
29 718b3ab0 2018-03-17 stsp * acquired with flock(2). This shared lock is held until the work
30 718b3ab0 2018-03-17 stsp * tree is closed, i.e. throughout the lifetime of any operation
31 718b3ab0 2018-03-17 stsp * which uses a work tree.
32 718b3ab0 2018-03-17 stsp * Before any modifications are made to the on-disk state of work
33 718b3ab0 2018-03-17 stsp * tree meta data, tracked files, or directory tree structure, this
34 718b3ab0 2018-03-17 stsp * shared lock must be upgraded to an exclusive lock.
35 718b3ab0 2018-03-17 stsp */
36 718b3ab0 2018-03-17 stsp int lockfd;
37 50b0790e 2020-09-11 stsp
38 50b0790e 2020-09-11 stsp /* Absolute path to worktree's got.conf file. */
39 50b0790e 2020-09-11 stsp char *gotconfig_path;
40 50b0790e 2020-09-11 stsp
41 50b0790e 2020-09-11 stsp /* Settings read from got.conf. */
42 50b0790e 2020-09-11 stsp struct got_gotconfig *gotconfig;
43 718b3ab0 2018-03-17 stsp };
44 718b3ab0 2018-03-17 stsp
45 8656d6c4 2019-05-20 stsp struct got_commitable {
46 8656d6c4 2019-05-20 stsp char *path;
47 8656d6c4 2019-05-20 stsp char *in_repo_path;
48 8656d6c4 2019-05-20 stsp char *ondisk_path;
49 8656d6c4 2019-05-20 stsp unsigned char status;
50 f0b75401 2019-08-03 stsp unsigned char staged_status;
51 8656d6c4 2019-05-20 stsp struct got_object_id *blob_id;
52 8656d6c4 2019-05-20 stsp struct got_object_id *base_blob_id;
53 f0b75401 2019-08-03 stsp struct got_object_id *staged_blob_id;
54 8656d6c4 2019-05-20 stsp struct got_object_id *base_commit_id;
55 8656d6c4 2019-05-20 stsp mode_t mode;
56 8656d6c4 2019-05-20 stsp int flags;
57 8656d6c4 2019-05-20 stsp #define GOT_COMMITABLE_ADDED 0x01
58 8656d6c4 2019-05-20 stsp };
59 8656d6c4 2019-05-20 stsp
60 718b3ab0 2018-03-17 stsp #define GOT_WORKTREE_GOT_DIR ".got"
61 0f92850e 2018-12-25 stsp #define GOT_WORKTREE_FILE_INDEX "file-index"
62 718b3ab0 2018-03-17 stsp #define GOT_WORKTREE_REPOSITORY "repository"
63 718b3ab0 2018-03-17 stsp #define GOT_WORKTREE_PATH_PREFIX "path-prefix"
64 0f92850e 2018-12-25 stsp #define GOT_WORKTREE_HEAD_REF "head-ref"
65 0f92850e 2018-12-25 stsp #define GOT_WORKTREE_BASE_COMMIT "base-commit"
66 718b3ab0 2018-03-17 stsp #define GOT_WORKTREE_LOCK "lock"
67 718b3ab0 2018-03-17 stsp #define GOT_WORKTREE_FORMAT "format"
68 ec22038e 2019-03-10 stsp #define GOT_WORKTREE_UUID "uuid"
69 c3022ba5 2019-07-27 stsp #define GOT_WORKTREE_HISTEDIT_SCRIPT "histedit-script"
70 718b3ab0 2018-03-17 stsp
71 718b3ab0 2018-03-17 stsp #define GOT_WORKTREE_FORMAT_VERSION 1
72 718b3ab0 2018-03-17 stsp #define GOT_WORKTREE_INVALID_COMMIT_ID GOT_SHA1_STRING_ZERO
73 0cd1c46a 2019-03-11 stsp
74 1ab61ced 2019-07-10 stsp #define GOT_WORKTREE_BASE_REF_PREFIX "refs/got/worktree/base"
75 517bab73 2019-03-11 stsp
76 517bab73 2019-03-11 stsp const struct got_error *got_worktree_get_base_ref_name(char **,
77 517bab73 2019-03-11 stsp struct got_worktree *worktree);
78 818c7501 2019-07-11 stsp
79 818c7501 2019-07-11 stsp /* Temporary branch which accumulates commits during a rebase operation. */
80 818c7501 2019-07-11 stsp #define GOT_WORKTREE_REBASE_TMP_REF_PREFIX "refs/got/worktree/rebase/tmp"
81 818c7501 2019-07-11 stsp
82 818c7501 2019-07-11 stsp /* Symbolic reference pointing at the name of the new base branch. */
83 818c7501 2019-07-11 stsp #define GOT_WORKTREE_NEWBASE_REF_PREFIX "refs/got/worktree/rebase/newbase"
84 818c7501 2019-07-11 stsp
85 818c7501 2019-07-11 stsp /* Symbolic reference pointing at the name of the branch being rebased. */
86 818c7501 2019-07-11 stsp #define GOT_WORKTREE_REBASE_BRANCH_REF_PREFIX "refs/got/worktree/rebase/branch"
87 818c7501 2019-07-11 stsp
88 818c7501 2019-07-11 stsp /* Reference pointing at the ID of the current commit being rebased. */
89 818c7501 2019-07-11 stsp #define GOT_WORKTREE_REBASE_COMMIT_REF_PREFIX "refs/got/worktree/rebase/commit"
90 0ebf8283 2019-07-24 stsp
91 0ebf8283 2019-07-24 stsp /* Temporary branch which accumulates commits during a histedit operation. */
92 0ebf8283 2019-07-24 stsp #define GOT_WORKTREE_HISTEDIT_TMP_REF_PREFIX "refs/got/worktree/histedit/tmp"
93 0ebf8283 2019-07-24 stsp
94 0ebf8283 2019-07-24 stsp /* Symbolic reference pointing at the name of the branch being edited. */
95 0ebf8283 2019-07-24 stsp #define GOT_WORKTREE_HISTEDIT_BRANCH_REF_PREFIX \
96 0ebf8283 2019-07-24 stsp "refs/got/worktree/histedit/branch"
97 0ebf8283 2019-07-24 stsp
98 0ebf8283 2019-07-24 stsp /* Reference pointing at the ID of the work tree's pre-edit base commit. */
99 0ebf8283 2019-07-24 stsp #define GOT_WORKTREE_HISTEDIT_BASE_COMMIT_REF_PREFIX \
100 0ebf8283 2019-07-24 stsp "refs/got/worktree/histedit/base-commit"
101 0ebf8283 2019-07-24 stsp
102 0ebf8283 2019-07-24 stsp /* Reference pointing at the ID of the current commit being edited. */
103 0ebf8283 2019-07-24 stsp #define GOT_WORKTREE_HISTEDIT_COMMIT_REF_PREFIX \
104 0ebf8283 2019-07-24 stsp "refs/got/worktree/histedit/commit"
105 f259c4c1 2021-09-24 stsp
106 f259c4c1 2021-09-24 stsp /* Symbolic reference pointing at the name of the merge source branch. */
107 f259c4c1 2021-09-24 stsp #define GOT_WORKTREE_MERGE_BRANCH_REF_PREFIX "refs/got/worktree/merge/branch"
108 f259c4c1 2021-09-24 stsp
109 f259c4c1 2021-09-24 stsp /* Reference pointing at the ID of the merge source branches's tip commit. */
110 f259c4c1 2021-09-24 stsp #define GOT_WORKTREE_MERGE_COMMIT_REF_PREFIX "refs/got/worktree/merge/commit"