- munmap(map, mapsize);
- if (!strcmp(type, "blob")) {
- struct blob *ret = lookup_blob(sha1);
- parse_blob(ret);
- return &ret->object;
- } else if (!strcmp(type, "tree")) {
- struct tree *ret = lookup_tree(sha1);
- parse_tree(ret);
- return &ret->object;
- } else if (!strcmp(type, "commit")) {
- struct commit *ret = lookup_commit(sha1);
- parse_commit(ret);
- return &ret->object;
- } else if (!strcmp(type, "tag")) {
- struct tag *ret = lookup_tag(sha1);
- parse_tag(ret);
- return &ret->object;
+ if (!strcmp(type, blob_type)) {
+ struct blob *blob = lookup_blob(sha1);
+ parse_blob_buffer(blob, buffer, size);
+ obj = &blob->object;
+ } else if (!strcmp(type, tree_type)) {
+ struct tree *tree = lookup_tree(sha1);
+ obj = &tree->object;
+ if (!tree->object.parsed) {
+ parse_tree_buffer(tree, buffer, size);
+ buffer = NULL;
+ }
+ } else if (!strcmp(type, commit_type)) {
+ struct commit *commit = lookup_commit(sha1);
+ parse_commit_buffer(commit, buffer, size);
+ if (!commit->buffer) {
+ commit->buffer = buffer;
+ buffer = NULL;
+ }
+ obj = &commit->object;
+ } else if (!strcmp(type, tag_type)) {
+ struct tag *tag = lookup_tag(sha1);
+ parse_tag_buffer(tag, buffer, size);
+ obj = &tag->object;