Make struct got_object opaque to users of the library
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
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);