move some more functions from object.c to object_parse.c
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
diff --git a/lib/object.c b/lib/object.c
index faa61ff..e8d569b 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -224,28 +224,6 @@ got_object_open_by_id_str(struct got_object **obj, struct got_repository *repo,
return got_object_open(obj, repo, &id);
}
-void
-got_object_close(struct got_object *obj)
-{
- if (obj->refcnt > 0) {
- obj->refcnt--;
- if (obj->refcnt > 0)
- return;
- }
-
- if (obj->flags & GOT_OBJ_FLAG_DELTIFIED) {
- struct got_delta *delta;
- while (!SIMPLEQ_EMPTY(&obj->deltas.entries)) {
- delta = SIMPLEQ_FIRST(&obj->deltas.entries);
- SIMPLEQ_REMOVE_HEAD(&obj->deltas.entries, entry);
- got_delta_close(delta);
- }
- }
- if (obj->flags & GOT_OBJ_FLAG_PACKED)
- free(obj->path_packfile);
- free(obj);
-}
-
const struct got_error *
got_object_open_as_commit(struct got_commit_object **commit,
struct got_repository *repo, struct got_object_id *id)
@@ -289,13 +267,6 @@ got_object_qid_alloc(struct got_object_qid **qid, struct got_object_id *id)
return NULL;
}
-void
-got_object_qid_free(struct got_object_qid *qid)
-{
- free(qid->id);
- free(qid);
-}
-
const struct got_error *
got_object_commit_open(struct got_commit_object **commit,
struct got_repository *repo, struct got_object *obj)
@@ -337,30 +308,6 @@ got_object_commit_open(struct got_commit_object **commit,
return err;
}
-void
-got_object_commit_close(struct got_commit_object *commit)
-{
- struct got_object_qid *qid;
-
- if (commit->refcnt > 0) {
- commit->refcnt--;
- if (commit->refcnt > 0)
- return;
- }
-
- while (!SIMPLEQ_EMPTY(&commit->parent_ids)) {
- qid = SIMPLEQ_FIRST(&commit->parent_ids);
- SIMPLEQ_REMOVE_HEAD(&commit->parent_ids, entry);
- got_object_qid_free(qid);
- }
-
- free(commit->tree_id);
- free(commit->author);
- free(commit->committer);
- free(commit->logmsg);
- free(commit);
-}
-
const struct got_error *
got_object_tree_open(struct got_tree_object **tree,
struct got_repository *repo, struct got_object *obj)
@@ -425,26 +372,6 @@ done:
return err;
}
-void
-got_object_tree_close(struct got_tree_object *tree)
-{
- struct got_tree_entry *te;
-
- if (tree->refcnt > 0) {
- tree->refcnt--;
- if (tree->refcnt > 0)
- return;
- }
-
- while (!SIMPLEQ_EMPTY(&tree->entries.head)) {
- te = SIMPLEQ_FIRST(&tree->entries.head);
- SIMPLEQ_REMOVE_HEAD(&tree->entries.head, entry);
- got_object_tree_entry_close(te);
- }
-
- free(tree);
-}
-
const struct got_tree_entries *
got_object_tree_get_entries(struct got_tree_object *tree)
{
diff --git a/lib/object_parse.c b/lib/object_parse.c
index cf6560f..3b98216 100644
--- a/lib/object_parse.c
+++ b/lib/object_parse.c
@@ -58,6 +58,35 @@
#define GOT_COMMIT_TAG_AUTHOR "author "
#define GOT_COMMIT_TAG_COMMITTER "committer "
+void
+got_object_close(struct got_object *obj)
+{
+ if (obj->refcnt > 0) {
+ obj->refcnt--;
+ if (obj->refcnt > 0)
+ return;
+ }
+
+ if (obj->flags & GOT_OBJ_FLAG_DELTIFIED) {
+ struct got_delta *delta;
+ while (!SIMPLEQ_EMPTY(&obj->deltas.entries)) {
+ delta = SIMPLEQ_FIRST(&obj->deltas.entries);
+ SIMPLEQ_REMOVE_HEAD(&obj->deltas.entries, entry);
+ got_delta_close(delta);
+ }
+ }
+ if (obj->flags & GOT_OBJ_FLAG_PACKED)
+ free(obj->path_packfile);
+ free(obj);
+}
+
+void
+got_object_qid_free(struct got_object_qid *qid)
+{
+ free(qid->id);
+ free(qid);
+}
+
static const struct got_error *
parse_object_header(struct got_object **obj, char *buf, size_t len)
{
@@ -359,6 +388,30 @@ parse_commit_time(struct tm *tm, char *committer)
return NULL;
}
+void
+got_object_commit_close(struct got_commit_object *commit)
+{
+ struct got_object_qid *qid;
+
+ if (commit->refcnt > 0) {
+ commit->refcnt--;
+ if (commit->refcnt > 0)
+ return;
+ }
+
+ while (!SIMPLEQ_EMPTY(&commit->parent_ids)) {
+ qid = SIMPLEQ_FIRST(&commit->parent_ids);
+ SIMPLEQ_REMOVE_HEAD(&commit->parent_ids, entry);
+ got_object_qid_free(qid);
+ }
+
+ free(commit->tree_id);
+ free(commit->author);
+ free(commit->committer);
+ free(commit->logmsg);
+ free(commit);
+}
+
const struct got_error *
got_object_parse_commit(struct got_commit_object **commit, char *buf, size_t len)
{
@@ -479,14 +532,34 @@ done:
return err;
}
-void
-got_object_tree_entry_close(struct got_tree_entry *te)
+static void
+tree_entry_close(struct got_tree_entry *te)
{
free(te->id);
free(te->name);
free(te);
}
+void
+got_object_tree_close(struct got_tree_object *tree)
+{
+ struct got_tree_entry *te;
+
+ if (tree->refcnt > 0) {
+ tree->refcnt--;
+ if (tree->refcnt > 0)
+ return;
+ }
+
+ 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);
+}
+
struct got_tree_entry *
got_alloc_tree_entry_partial(void)
{
@@ -549,7 +622,7 @@ parse_tree_entry(struct got_tree_entry **te, size_t *elen, char *buf,
*elen += SHA1_DIGEST_LENGTH;
done:
if (err) {
- got_object_tree_entry_close(*te);
+ tree_entry_close(*te);
*te = NULL;
}
return err;