Commit 03fa71c8764d610e39b7c0428ed2c51d5f0c9c20

Stefan Sperling 2018-09-06T17:42:46

move some more functions from object.c to object_parse.c

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;