make struct got_tree_object opaque
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
diff --git a/include/got_object.h b/include/got_object.h
index df0f4ad..52bd46f 100644
--- a/include/got_object.h
+++ b/include/got_object.h
@@ -17,6 +17,7 @@
struct got_object_id;
struct got_blob_object;
+struct got_tree_object;
struct got_tree_entry {
SIMPLEQ_ENTRY(got_tree_entry) entry;
@@ -25,11 +26,11 @@ struct got_tree_entry {
struct got_object_id *id;
};
-struct got_tree_object {
- int nentries;
- SIMPLEQ_HEAD(, got_tree_entry) entries;
+SIMPLEQ_HEAD(got_tree_entries_queue, got_tree_entry);
- int refcnt; /* for internal use only */
+struct got_tree_entries {
+ int nentries;
+ struct got_tree_entries_queue head;
};
struct got_object_qid {
@@ -141,6 +142,10 @@ const struct got_error *got_object_tree_open(struct got_tree_object **,
/* Dispose of a tree object. */
void got_object_tree_close(struct got_tree_object *);
+/* Get the entries of a tree object. */
+const struct got_tree_entries *got_object_tree_get_entries(
+ struct got_tree_object *);
+
/*
* Attempt to open a blob object in a repository.
* The provided object must be of type GOT_OBJ_TYPE_BLOB.
diff --git a/lib/diff.c b/lib/diff.c
index e4f7dbb..abdee82 100644
--- a/lib/diff.c
+++ b/lib/diff.c
@@ -152,8 +152,10 @@ struct got_tree_entry *
match_entry_by_name(struct got_tree_entry *te1, struct got_tree_object *tree2)
{
struct got_tree_entry *te2;
+ const struct got_tree_entries *entries2;
- SIMPLEQ_FOREACH(te2, &tree2->entries, entry) {
+ entries2 = got_object_tree_get_entries(tree2);
+ SIMPLEQ_FOREACH(te2, &entries2->head, entry) {
if (strcmp(te1->name, te2->name) == 0)
return te2;
}
@@ -423,10 +425,16 @@ got_diff_tree(struct got_tree_object *tree1, struct got_tree_object *tree2,
struct got_tree_entry *te1 = NULL;
struct got_tree_entry *te2 = NULL;
- if (tree1)
- te1 = SIMPLEQ_FIRST(&tree1->entries);
- if (tree2)
- te2 = SIMPLEQ_FIRST(&tree2->entries);
+ if (tree1) {
+ const struct got_tree_entries *entries;
+ entries = got_object_tree_get_entries(tree1);
+ te1 = SIMPLEQ_FIRST(&entries->head);
+ }
+ if (tree2) {
+ const struct got_tree_entries *entries;
+ entries = got_object_tree_get_entries(tree2);
+ te2 = SIMPLEQ_FIRST(&entries->head);
+ }
do {
if (te1) {
diff --git a/lib/got_lib_object.h b/lib/got_lib_object.h
index ed4dac1..9f5b22c 100644
--- a/lib/got_lib_object.h
+++ b/lib/got_lib_object.h
@@ -34,6 +34,11 @@ struct got_object {
int refcnt; /* > 0 if open and/or cached */
};
+struct got_tree_object {
+ struct got_tree_entries entries;
+ int refcnt;
+};
+
struct got_blob_object {
FILE *f;
struct got_zstream_buf zb;
diff --git a/lib/object.c b/lib/object.c
index 3a8d465..a55e09d 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -782,7 +782,7 @@ parse_tree_object(struct got_tree_object **tree, uint8_t *buf, size_t len)
if (*tree == NULL)
return got_error_from_errno();
- SIMPLEQ_INIT(&(*tree)->entries);
+ SIMPLEQ_INIT(&(*tree)->entries.head);
while (remain > 0) {
struct got_tree_entry *te;
@@ -791,8 +791,8 @@ parse_tree_object(struct got_tree_object **tree, uint8_t *buf, size_t len)
err = parse_tree_entry(&te, &elen, buf, remain);
if (err)
return err;
- (*tree)->nentries++;
- SIMPLEQ_INSERT_TAIL(&(*tree)->entries, te, entry);
+ (*tree)->entries.nentries++;
+ SIMPLEQ_INSERT_TAIL(&(*tree)->entries.head, te, entry);
buf += elen;
remain -= elen;
}
@@ -1200,15 +1200,21 @@ got_object_tree_close(struct got_tree_object *tree)
return;
}
- while (!SIMPLEQ_EMPTY(&tree->entries)) {
- te = SIMPLEQ_FIRST(&tree->entries);
- SIMPLEQ_REMOVE_HEAD(&tree->entries, entry);
+ while (!SIMPLEQ_EMPTY(&tree->entries.head)) {
+ te = SIMPLEQ_FIRST(&tree->entries.head);
+ SIMPLEQ_REMOVE_HEAD(&tree->entries.head, entry);
tree_entry_close(te);
}
free(tree);
}
+const struct got_tree_entries *
+got_object_tree_get_entries(struct got_tree_object *tree)
+{
+ return &tree->entries;
+}
+
static const struct got_error *
read_blob_object_privsep_child(int outfd, int infd, int imsg_fds[2])
{
@@ -1464,7 +1470,7 @@ find_entry_by_name(struct got_tree_object *tree, const char *name)
{
struct got_tree_entry *te;
- SIMPLEQ_FOREACH(te, &tree->entries, entry) {
+ SIMPLEQ_FOREACH(te, &tree->entries.head, entry) {
if (strcmp(te->name, name) == 0)
return te;
}
diff --git a/lib/privsep.c b/lib/privsep.c
index 2fc13c0..a0f4d62 100644
--- a/lib/privsep.c
+++ b/lib/privsep.c
@@ -462,7 +462,7 @@ got_privsep_send_tree(struct imsgbuf *ibuf, struct got_tree_object *tree)
struct got_imsg_tree_object itree;
struct got_tree_entry *te;
- itree.nentries = tree->nentries;
+ itree.nentries = tree->entries.nentries;
if (imsg_compose(ibuf, GOT_IMSG_TREE, 0, 0, -1, &itree, sizeof(itree))
== -1)
return got_error_from_errno();
@@ -471,7 +471,7 @@ got_privsep_send_tree(struct imsgbuf *ibuf, struct got_tree_object *tree)
if (err)
return err;
- SIMPLEQ_FOREACH(te, &tree->entries, entry) {
+ SIMPLEQ_FOREACH(te, &tree->entries.head, entry) {
struct got_imsg_tree_entry ite;
uint8_t *buf = NULL;
size_t len = sizeof(ite) + strlen(te->name);
@@ -528,7 +528,7 @@ get_more:
n = imsg_get(ibuf, &imsg);
if (n == 0) {
- if (*tree && (*tree)->nentries != nentries)
+ if (*tree && (*tree)->entries.nentries != nentries)
goto get_more;
break;
}
@@ -558,8 +558,8 @@ get_more:
err = got_error_from_errno();
break;
}
- (*tree)->nentries = itree.nentries;
- SIMPLEQ_INIT(&(*tree)->entries);
+ (*tree)->entries.nentries = itree.nentries;
+ SIMPLEQ_INIT(&(*tree)->entries.head);
break;
case GOT_IMSG_TREE_ENTRY:
/* This message should be preceeded by GOT_IMSG_TREE. */
@@ -596,7 +596,7 @@ get_more:
memcpy(te->id->sha1, ite.id, SHA1_DIGEST_LENGTH);
te->mode = ite.mode;
- SIMPLEQ_INSERT_TAIL(&(*tree)->entries, te, entry);
+ SIMPLEQ_INSERT_TAIL(&(*tree)->entries.head, te, entry);
nentries++;
break;
default:
@@ -607,7 +607,7 @@ get_more:
imsg_free(&imsg);
}
done:
- if (*tree && (*tree)->nentries != nentries) {
+ if (*tree && (*tree)->entries.nentries != nentries) {
if (err == NULL)
err = got_error(GOT_ERR_PRIVSEP_LEN);
got_object_tree_close(*tree);
diff --git a/lib/worktree.c b/lib/worktree.c
index 176d82f..dc82efb 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -550,6 +550,7 @@ tree_checkout(struct got_worktree *worktree,
got_worktree_checkout_cb progress_cb, void *progress_arg)
{
const struct got_error *err = NULL;
+ const struct got_tree_entries *entries;
struct got_tree_entry *te;
size_t len;
@@ -558,7 +559,8 @@ tree_checkout(struct got_worktree *worktree,
if (strncmp(path, worktree->path_prefix, len) != 0)
return NULL;
- SIMPLEQ_FOREACH(te, &tree->entries, entry) {
+ entries = got_object_tree_get_entries(tree);
+ SIMPLEQ_FOREACH(te, &entries->head, entry) {
err = tree_checkout_entry(worktree, fileindex, te, path, repo,
progress_cb, progress_arg);
if (err)
diff --git a/regress/repository/repository_test.c b/regress/repository/repository_test.c
index 021825f..8b5fcb7 100644
--- a/regress/repository/repository_test.c
+++ b/regress/repository/repository_test.c
@@ -88,6 +88,7 @@ print_tree_object(struct got_object *obj, char *parent,
struct got_repository *repo)
{
struct got_tree_object *tree;
+ const struct got_tree_entries *entries;
struct got_tree_entry *te;
const struct got_error *err;
@@ -95,7 +96,8 @@ print_tree_object(struct got_object *obj, char *parent,
if (err != NULL)
return err;
- SIMPLEQ_FOREACH(te, &tree->entries, entry) {
+ entries = got_object_tree_get_entries(tree);
+ SIMPLEQ_FOREACH(te, &entries->head, entry) {
struct got_object *treeobj;
char *next_parent;
char *hex;