Commit eef6493a8d08ef874a8060f8966241d8c1337168

Stefan Sperling 2018-01-19T18:09:29

Make struct got_object opaque to users of the library

diff --git a/include/got_object.h b/include/got_object.h
index 54b890a..59e948f 100644
--- a/include/got_object.h
+++ b/include/got_object.h
@@ -63,8 +63,7 @@ struct got_commit_object {
 	char *logmsg;
 };
 
-struct got_object {
-	int type;
+struct got_object;
 #define GOT_OBJ_TYPE_COMMIT		1
 #define GOT_OBJ_TYPE_TREE		2
 #define GOT_OBJ_TYPE_BLOB		3
@@ -73,22 +72,6 @@ struct got_object {
 #define GOT_OBJ_TYPE_OFFSET_DELTA	6
 #define GOT_OBJ_TYPE_REF_DELTA		7
 
-	int flags;
-#define GOT_OBJ_FLAG_PACKED		0x01
-
-	size_t hdrlen;
-	size_t size;
-	struct got_object_id id;
-
-	char *path_packfile;	/* if packed */
-	off_t pack_offset;	/* if packed */
-
-	/* If type is OFFSET_DELTA: */
-	int base_type;
-	uint64_t base_size;
-	off_t base_obj_offset;
-};
-
 struct got_repository;
 
 char *got_object_id_str(struct got_object_id *, char *, size_t);
diff --git a/lib/diff.c b/lib/diff.c
index 3bf0c3c..cbf2d2f 100644
--- a/lib/diff.c
+++ b/lib/diff.c
@@ -163,7 +163,7 @@ diff_modified_blob(struct got_object_id *id1, struct got_object_id *id2,
 	err = got_object_open(&obj1, repo, id1);
 	if (err)
 		return got_error(GOT_ERR_BAD_OBJ_HDR);
-	if (obj1->type != GOT_OBJ_TYPE_BLOB) {
+	if (got_object_get_type(obj1) != GOT_OBJ_TYPE_BLOB) {
 		err = got_error(GOT_ERR_OBJ_TYPE);
 		goto done;
 	}
@@ -173,7 +173,7 @@ diff_modified_blob(struct got_object_id *id1, struct got_object_id *id2,
 		err= got_error(GOT_ERR_BAD_OBJ_HDR);
 		goto done;
 	}
-	if (obj2->type != GOT_OBJ_TYPE_BLOB) {
+	if (got_object_get_type(obj2) != GOT_OBJ_TYPE_BLOB) {
 		err = got_error(GOT_ERR_BAD_OBJ_DATA);
 		goto done;
 	}
@@ -265,7 +265,7 @@ diff_modified_tree(struct got_object_id *id1, struct got_object_id *id2,
 	if (err)
 		goto done;
 
-	if (treeobj1->type != GOT_OBJ_TYPE_TREE) {
+	if (got_object_get_type(treeobj1) != GOT_OBJ_TYPE_TREE) {
 		err = got_error(GOT_ERR_OBJ_TYPE);
 		goto done;
 	}
@@ -274,7 +274,7 @@ diff_modified_tree(struct got_object_id *id1, struct got_object_id *id2,
 	if (err)
 		goto done;
 
-	if (treeobj2->type != GOT_OBJ_TYPE_TREE) {
+	if (got_object_get_type(treeobj2) != GOT_OBJ_TYPE_TREE) {
 		err = got_error(GOT_ERR_OBJ_TYPE);
 		goto done;
 	}
diff --git a/lib/object.c b/lib/object.c
index 9f2bc6f..5ff0a64 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -31,6 +31,7 @@
 #include "got_repository.h"
 #include "got_sha1.h"
 #include "pack.h"
+#include "object.h"
 
 #ifndef MIN
 #define	MIN(_a,_b) ((_a) < (_b) ? (_a) : (_b))
diff --git a/lib/pack.c b/lib/pack.c
index a91b594..86f4deb 100644
--- a/lib/pack.c
+++ b/lib/pack.c
@@ -36,6 +36,7 @@
 #include "pack.h"
 #include "path.h"
 #include "delta.h"
+#include "object.h"
 
 #define GOT_PACK_PREFIX		"pack-"
 #define GOT_PACKFILE_SUFFIX	".pack"
diff --git a/regress/repository/repository_test.c b/regress/repository/repository_test.c
index 6495ec4..7619771 100644
--- a/regress/repository/repository_test.c
+++ b/regress/repository/repository_test.c
@@ -261,12 +261,12 @@ repo_diff_blob(const char *repo_path)
 	err = got_object_open(&obj1, repo, &id1);
 	if (err != NULL || obj1 == NULL)
 		return 0;
-	if (obj1->type != GOT_OBJ_TYPE_BLOB)
+	if (got_object_get_type(obj1) != GOT_OBJ_TYPE_BLOB)
 		return 0;
 	err = got_object_open(&obj2, repo, &id2);
 	if (err != NULL || obj2 == NULL)
 		return 0;
-	if (obj2->type != GOT_OBJ_TYPE_BLOB)
+	if (got_object_get_type(obj2) != GOT_OBJ_TYPE_BLOB)
 		return 0;
 
 	err = got_object_blob_open(&blob1, repo, obj1, 512);
@@ -318,12 +318,12 @@ repo_diff_tree(const char *repo_path)
 	err = got_object_open(&obj1, repo, &id1);
 	if (err != NULL || obj1 == NULL)
 		return 0;
-	if (obj1->type != GOT_OBJ_TYPE_TREE)
+	if (got_object_get_type(obj1) != GOT_OBJ_TYPE_TREE)
 		return 0;
 	err = got_object_open(&obj2, repo, &id2);
 	if (err != NULL || obj2 == NULL)
 		return 0;
-	if (obj2->type != GOT_OBJ_TYPE_TREE)
+	if (got_object_get_type(obj2) != GOT_OBJ_TYPE_TREE)
 		return 0;
 
 	err = got_object_tree_open(&tree1, repo, obj1);