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 df6221c7 2023-07-19 stsp const char *meta_dir;
20 718b3ab0 2018-03-17 stsp char *repo_path;
21 437adc9d 2020-12-10 yzhong int root_fd;
22 718b3ab0 2018-03-17 stsp char *path_prefix;
23 eaccb85f 2018-12-25 stsp struct got_object_id *base_commit_id;
24 36a38700 2019-05-10 stsp char *head_ref_name;
25 c442a90d 2019-03-10 stsp uuid_t uuid;
26 718b3ab0 2018-03-17 stsp
27 718b3ab0 2018-03-17 stsp /*
28 718b3ab0 2018-03-17 stsp * File descriptor for the lock file, open while a work tree is open.
29 718b3ab0 2018-03-17 stsp * When a work tree is opened, a shared lock on the lock file is
30 718b3ab0 2018-03-17 stsp * acquired with flock(2). This shared lock is held until the work
31 718b3ab0 2018-03-17 stsp * tree is closed, i.e. throughout the lifetime of any operation
32 718b3ab0 2018-03-17 stsp * which uses a work tree.
33 718b3ab0 2018-03-17 stsp * Before any modifications are made to the on-disk state of work
34 718b3ab0 2018-03-17 stsp * tree meta data, tracked files, or directory tree structure, this
35 718b3ab0 2018-03-17 stsp * shared lock must be upgraded to an exclusive lock.
36 718b3ab0 2018-03-17 stsp */
37 718b3ab0 2018-03-17 stsp int lockfd;
38 50b0790e 2020-09-11 stsp
39 50b0790e 2020-09-11 stsp /* Absolute path to worktree's got.conf file. */
40 50b0790e 2020-09-11 stsp char *gotconfig_path;
41 50b0790e 2020-09-11 stsp
42 50b0790e 2020-09-11 stsp /* Settings read from got.conf. */
43 50b0790e 2020-09-11 stsp struct got_gotconfig *gotconfig;
44 718b3ab0 2018-03-17 stsp };
45 718b3ab0 2018-03-17 stsp
46 8656d6c4 2019-05-20 stsp struct got_commitable {
47 8656d6c4 2019-05-20 stsp char *path;
48 8656d6c4 2019-05-20 stsp char *in_repo_path;
49 8656d6c4 2019-05-20 stsp char *ondisk_path;
50 8656d6c4 2019-05-20 stsp unsigned char status;
51 f0b75401 2019-08-03 stsp unsigned char staged_status;
52 8656d6c4 2019-05-20 stsp struct got_object_id *blob_id;
53 8656d6c4 2019-05-20 stsp struct got_object_id *base_blob_id;
54 f0b75401 2019-08-03 stsp struct got_object_id *staged_blob_id;
55 8656d6c4 2019-05-20 stsp struct got_object_id *base_commit_id;
56 8656d6c4 2019-05-20 stsp mode_t mode;
57 8656d6c4 2019-05-20 stsp int flags;
58 8656d6c4 2019-05-20 stsp #define GOT_COMMITABLE_ADDED 0x01
59 8656d6c4 2019-05-20 stsp };
60 8656d6c4 2019-05-20 stsp
61 df6221c7 2023-07-19 stsp /* Also defined in got_worktree.h */
62 df6221c7 2023-07-19 stsp #ifndef GOT_WORKTREE_GOT_DIR
63 718b3ab0 2018-03-17 stsp #define GOT_WORKTREE_GOT_DIR ".got"
64 df6221c7 2023-07-19 stsp #endif
65 df6221c7 2023-07-19 stsp #ifndef GOT_WORKTREE_CVG_DIR
66 df6221c7 2023-07-19 stsp #define GOT_WORKTREE_CVG_DIR ".cvg"
67 df6221c7 2023-07-19 stsp #endif
68 df6221c7 2023-07-19 stsp
69 0f92850e 2018-12-25 stsp #define GOT_WORKTREE_FILE_INDEX "file-index"
70 718b3ab0 2018-03-17 stsp #define GOT_WORKTREE_REPOSITORY "repository"
71 718b3ab0 2018-03-17 stsp #define GOT_WORKTREE_PATH_PREFIX "path-prefix"
72 0f92850e 2018-12-25 stsp #define GOT_WORKTREE_HEAD_REF "head-ref"
73 0f92850e 2018-12-25 stsp #define GOT_WORKTREE_BASE_COMMIT "base-commit"
74 718b3ab0 2018-03-17 stsp #define GOT_WORKTREE_LOCK "lock"
75 718b3ab0 2018-03-17 stsp #define GOT_WORKTREE_FORMAT "format"
76 ec22038e 2019-03-10 stsp #define GOT_WORKTREE_UUID "uuid"
77 c3022ba5 2019-07-27 stsp #define GOT_WORKTREE_HISTEDIT_SCRIPT "histedit-script"
78 718b3ab0 2018-03-17 stsp
79 718b3ab0 2018-03-17 stsp #define GOT_WORKTREE_FORMAT_VERSION 1
80 718b3ab0 2018-03-17 stsp #define GOT_WORKTREE_INVALID_COMMIT_ID GOT_SHA1_STRING_ZERO
81 0cd1c46a 2019-03-11 stsp
82 1ab61ced 2019-07-10 stsp #define GOT_WORKTREE_BASE_REF_PREFIX "refs/got/worktree/base"
83 517bab73 2019-03-11 stsp
84 818c7501 2019-07-11 stsp /* Temporary branch which accumulates commits during a rebase operation. */
85 818c7501 2019-07-11 stsp #define GOT_WORKTREE_REBASE_TMP_REF_PREFIX "refs/got/worktree/rebase/tmp"
86 818c7501 2019-07-11 stsp
87 818c7501 2019-07-11 stsp /* Symbolic reference pointing at the name of the new base branch. */
88 818c7501 2019-07-11 stsp #define GOT_WORKTREE_NEWBASE_REF_PREFIX "refs/got/worktree/rebase/newbase"
89 818c7501 2019-07-11 stsp
90 818c7501 2019-07-11 stsp /* Symbolic reference pointing at the name of the branch being rebased. */
91 818c7501 2019-07-11 stsp #define GOT_WORKTREE_REBASE_BRANCH_REF_PREFIX "refs/got/worktree/rebase/branch"
92 818c7501 2019-07-11 stsp
93 818c7501 2019-07-11 stsp /* Reference pointing at the ID of the current commit being rebased. */
94 818c7501 2019-07-11 stsp #define GOT_WORKTREE_REBASE_COMMIT_REF_PREFIX "refs/got/worktree/rebase/commit"
95 0ebf8283 2019-07-24 stsp
96 0ebf8283 2019-07-24 stsp /* Temporary branch which accumulates commits during a histedit operation. */
97 0ebf8283 2019-07-24 stsp #define GOT_WORKTREE_HISTEDIT_TMP_REF_PREFIX "refs/got/worktree/histedit/tmp"
98 0ebf8283 2019-07-24 stsp
99 0ebf8283 2019-07-24 stsp /* Symbolic reference pointing at the name of the branch being edited. */
100 0ebf8283 2019-07-24 stsp #define GOT_WORKTREE_HISTEDIT_BRANCH_REF_PREFIX \
101 0ebf8283 2019-07-24 stsp "refs/got/worktree/histedit/branch"
102 0ebf8283 2019-07-24 stsp
103 0ebf8283 2019-07-24 stsp /* Reference pointing at the ID of the work tree's pre-edit base commit. */
104 0ebf8283 2019-07-24 stsp #define GOT_WORKTREE_HISTEDIT_BASE_COMMIT_REF_PREFIX \
105 0ebf8283 2019-07-24 stsp "refs/got/worktree/histedit/base-commit"
106 0ebf8283 2019-07-24 stsp
107 0ebf8283 2019-07-24 stsp /* Reference pointing at the ID of the current commit being edited. */
108 0ebf8283 2019-07-24 stsp #define GOT_WORKTREE_HISTEDIT_COMMIT_REF_PREFIX \
109 0ebf8283 2019-07-24 stsp "refs/got/worktree/histedit/commit"
110 f259c4c1 2021-09-24 stsp
111 f259c4c1 2021-09-24 stsp /* Symbolic reference pointing at the name of the merge source branch. */
112 f259c4c1 2021-09-24 stsp #define GOT_WORKTREE_MERGE_BRANCH_REF_PREFIX "refs/got/worktree/merge/branch"
113 f259c4c1 2021-09-24 stsp
114 f259c4c1 2021-09-24 stsp /* Reference pointing at the ID of the merge source branches's tip commit. */
115 f259c4c1 2021-09-24 stsp #define GOT_WORKTREE_MERGE_COMMIT_REF_PREFIX "refs/got/worktree/merge/commit"
116 3d1b16d1 2023-07-08 jrick
117 3d1b16d1 2023-07-08 jrick /* Reference pointing to temporary commits that may need trivial rebasing. */
118 3d1b16d1 2023-07-08 jrick #define GOT_WORKTREE_COMMIT_REF_PREFIX "refs/got/worktree/commit"