commit ea35256be57fbb7d6afbedd8382c9e6e36b39718 from: Stefan Sperling date: Fri Mar 16 18:27:48 2018 UTC avoid a round-trip via tempfile when reading packed commits commit - 40dc5ff850c9b70725e0ae5ef7e12a05fe0ea894 commit + ea35256be57fbb7d6afbedd8382c9e6e36b39718 blob - 66fcf360ef08cd9ad2a75fee374b6553129d6d2c blob + 1cd78bd397de872885840daf766fa91b523f1545 --- lib/object.c +++ lib/object.c @@ -615,20 +615,27 @@ got_object_commit_open(struct got_commit_object **comm struct got_repository *repo, struct got_object *obj) { const struct got_error *err = NULL; - FILE *f; if (obj->type != GOT_OBJ_TYPE_COMMIT) return got_error(GOT_ERR_OBJ_TYPE); - if (obj->flags & GOT_OBJ_FLAG_PACKED) - err = got_packfile_extract_object(&f, obj, repo); - else + if (obj->flags & GOT_OBJ_FLAG_PACKED) { + uint8_t *buf; + size_t len; + err = got_packfile_extract_object_to_mem(&buf, &len, obj, repo); + if (err) + return err; + len -= obj->hdrlen; + err = parse_commit_object(commit, buf + obj->hdrlen, len); + free(buf); + } else { + FILE *f; err = open_loose_object(&f, obj, repo); - if (err) - return err; - - err = read_commit_object(commit, repo, obj, f); - fclose(f); + if (err) + return err; + err = read_commit_object(commit, repo, obj, f); + fclose(f); + } return err; } blob - a9f4e70b4c44660ba309da7d3b76b74528c49f6a blob + df4373930ad456a300065c03df84108b1aa55891 --- lib/pack.c +++ lib/pack.c @@ -1426,9 +1426,6 @@ got_packfile_extract_object_to_mem(uint8_t **buf, size const struct got_error *err = NULL; FILE *packfile = NULL; - if (obj->type != GOT_OBJ_TYPE_TREE) - return got_error(GOT_ERR_OBJ_TYPE); - if ((obj->flags & GOT_OBJ_FLAG_PACKED) == 0) return got_error(GOT_ERR_OBJ_NOT_PACKED);