commit f934cf2c63fe7f1b40d3c217c01a8c6b6556e670 from: Stefan Sperling date: Mon Feb 12 20:27:40 2018 UTC make struct got_blob_object opaque commit - 354a7e122f5a2dbd5cae092cadf02ffac4f5436a commit + f934cf2c63fe7f1b40d3c217c01a8c6b6556e670 blob - 339b6c1b3cd86d892dc0c1e5df004c0c974d64fb blob + 7926d579671de282543c40cfd7061b6a535d71ce --- include/got_object.h +++ 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 *); blob - 25249ba62043d334e9f01225ca63a12ffd86bb2f blob + 0d417198dabeffa3677bed2341c49fdefa698b55 --- lib/diff.c +++ lib/diff.c @@ -44,6 +44,7 @@ got_diff_blob(struct got_blob_object *blob1, struct go 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 go } 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 go /* 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)); blob - 273788d7f3ccc4a3162819094255583f4e60e88b blob + d9ff8c0898d627f34404689ba378093081a3fa8e --- lib/object.c +++ lib/object.c @@ -739,8 +739,26 @@ got_object_blob_close(struct got_blob_object *blob) free(blob->read_buf); fclose(blob->f); 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) { blob - 7d64bfaba781aa3e3e2aa9f60b316106f3bc6bc6 blob + 9b27d1b8f5cb6507171a8a3db2a4a98bce3e0562 --- lib/object.h +++ 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; +}; blob - 9fc0d8e21bf71822413c61994063d653a193e98d blob + 0b04bd618d455a241730c9202119f379a6d102ce --- regress/repository/repository_test.c +++ 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");