make struct got_blob_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
diff --git a/include/got_object.h b/include/got_object.h
index 339b6c1..7926d57 100644
--- a/include/got_object.h
+++ b/include/got_object.h
@@ -28,16 +28,7 @@ struct got_object_id {
u_int8_t sha1[SHA1_DIGEST_LENGTH];
};
-struct got_blob_object {
- FILE *f;
- struct got_zstream_buf zb;
- size_t hdrlen;
- size_t blocksize;
- uint8_t *read_buf;
- int flags;
-#define GOT_BLOB_F_COMPRESSED 0x01
- struct got_object_id id;
-};
+struct got_blob_object;
struct got_tree_entry {
SIMPLEQ_ENTRY(got_tree_entry) entry;
@@ -93,5 +84,8 @@ void got_object_tree_close(struct got_tree_object *);
const struct got_error *got_object_blob_open(struct got_blob_object **,
struct got_repository *, struct got_object *, size_t);
void got_object_blob_close(struct got_blob_object *);
+char *got_object_blob_id_str(struct got_blob_object*, char *, size_t);
+size_t got_object_blob_get_hdrlen(struct got_blob_object *);
+const uint8_t *got_object_blob_get_read_buf(struct got_blob_object *);
const struct got_error *got_object_blob_read_block(size_t *,
struct got_blob_object *);
diff --git a/lib/diff.c b/lib/diff.c
index 25249ba..0d41719 100644
--- a/lib/diff.c
+++ b/lib/diff.c
@@ -44,6 +44,7 @@ got_diff_blob(struct got_blob_object *blob1, struct got_blob_object *blob2,
char hex2[SHA1_DIGEST_STRING_LENGTH];
char *idstr1 = NULL, *idstr2 = NULL;
size_t len, hdrlen;
+ size_t size1, size2;
int res, flags = 0;
if (blob1) {
@@ -62,33 +63,37 @@ got_diff_blob(struct got_blob_object *blob1, struct got_blob_object *blob2,
} else
flags |= D_EMPTY2;
+ size1 = 0;
if (blob1) {
- idstr1 = got_object_id_str(&blob1->id, hex1, sizeof(hex1));
- hdrlen = blob1->hdrlen;
+ idstr1 = got_object_blob_id_str(blob1, hex1, sizeof(hex1));
+ hdrlen = got_object_blob_get_hdrlen(blob1);
do {
err = got_object_blob_read_block(&len, blob1);
if (err)
goto done;
if (len == 0)
break;
+ size1 += len;
/* Skip blob object header first time around. */
- fwrite(blob1->read_buf + hdrlen, len - hdrlen, 1, f1);
+ fwrite(got_object_blob_get_read_buf(blob1) + hdrlen, len - hdrlen, 1, f1);
hdrlen = 0;
} while (len != 0);
} else
idstr1 = "/dev/null";
+ size2 = 0;
if (blob2) {
- idstr2 = got_object_id_str(&blob2->id, hex2, sizeof(hex2));
- hdrlen = blob2->hdrlen;
+ idstr2 = got_object_blob_id_str(blob2, hex2, sizeof(hex2));
+ hdrlen = got_object_blob_get_hdrlen(blob2);
do {
err = got_object_blob_read_block(&len, blob2);
if (err)
goto done;
if (len == 0)
break;
+ size2 += len;
/* Skip blob object header first time around. */
- fwrite(blob2->read_buf + hdrlen, len - hdrlen, 1, f2);
+ fwrite(got_object_blob_get_read_buf(blob2) + hdrlen, len - hdrlen, 1, f2);
hdrlen = 0;
} while (len != 0);
} else
@@ -107,12 +112,12 @@ got_diff_blob(struct got_blob_object *blob1, struct got_blob_object *blob2,
/* XXX should stat buffers be passed in args instead of ds? */
ds.stb1.st_mode = S_IFREG;
if (blob1)
- ds.stb1.st_size = blob1->zb.z.total_out;
+ ds.stb1.st_size = size1;
ds.stb1.st_mtime = 0; /* XXX */
ds.stb2.st_mode = S_IFREG;
if (blob2)
- ds.stb2.st_size = blob2->zb.z.total_out;
+ ds.stb2.st_size = size2;
ds.stb2.st_mtime = 0; /* XXX */
memset(&args, 0, sizeof(args));
diff --git a/lib/object.c b/lib/object.c
index 273788d..d9ff8c0 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -741,6 +741,24 @@ got_object_blob_close(struct got_blob_object *blob)
free(blob);
}
+char *
+got_object_blob_id_str(struct got_blob_object *blob, char *buf, size_t size)
+{
+ return got_sha1_digest_to_str(blob->id.sha1, buf, size);
+}
+
+size_t
+got_object_blob_get_hdrlen(struct got_blob_object *blob)
+{
+ return blob->hdrlen;
+}
+
+const uint8_t *
+got_object_blob_get_read_buf(struct got_blob_object *blob)
+{
+ return blob->read_buf;
+}
+
const struct got_error *
got_object_blob_read_block(size_t *outlenp, struct got_blob_object *blob)
{
diff --git a/lib/object.h b/lib/object.h
index 7d64bfa..9b27d1b 100644
--- a/lib/object.h
+++ b/lib/object.h
@@ -28,3 +28,14 @@ struct got_object {
off_t pack_offset; /* if packed */
struct got_delta_chain deltas; /* if deltified */
};
+
+struct got_blob_object {
+ FILE *f;
+ struct got_zstream_buf zb;
+ size_t hdrlen;
+ size_t blocksize;
+ uint8_t *read_buf;
+ int flags;
+#define GOT_BLOB_F_COMPRESSED 0x01
+ struct got_object_id id;
+};
diff --git a/regress/repository/repository_test.c b/regress/repository/repository_test.c
index 9fc0d8e..0b04bd6 100644
--- a/regress/repository/repository_test.c
+++ b/regress/repository/repository_test.c
@@ -268,11 +268,12 @@ repo_read_blob(const char *repo_path)
test_printf("\n");
do {
+ const uint8_t *buf = got_object_blob_get_read_buf(blob);
err = got_object_blob_read_block(&len, blob);
if (err)
break;
for (i = 0; i < len; i++)
- test_printf("%c", blob->read_buf[i]);
+ test_printf("%c", buf[i]);
} while (len != 0);
test_printf("\n");