X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=commit.c;h=abbf155da938cf675696e812b4083c8a773ffab0;hb=fbe082a528861af785be15bb37d1c7d8f574daa4;hp=706c7cba08ebc2100c2dbf63ed1238f39324f750;hpb=bd2c39f58f915af532b488c5bda753314f0db603;p=git.git diff --git a/commit.c b/commit.c index 706c7cba..abbf155d 100644 --- a/commit.c +++ b/commit.c @@ -1,10 +1,30 @@ +#include "tag.h" #include "commit.h" #include "cache.h" -#include -#include const char *commit_type = "commit"; +static struct commit *check_commit(struct object *obj, unsigned char *sha1) +{ + if (obj->type != commit_type) { + error("Object %s is a %s, not a commit", + sha1_to_hex(sha1), obj->type); + return NULL; + } + return (struct commit *) obj; +} + +struct commit *lookup_commit_reference(unsigned char *sha1) +{ + struct object *obj = parse_object(sha1); + + if (!obj) + return NULL; + if (obj->type == tag_type) + obj = ((struct tag *)obj)->tagged; + return check_commit(obj, sha1); +} + struct commit *lookup_commit(unsigned char *sha1) { struct object *obj = lookup_object(sha1); @@ -15,12 +35,9 @@ struct commit *lookup_commit(unsigned char *sha1) ret->object.type = commit_type; return ret; } - if (obj->type != commit_type) { - error("Object %s is a %s, not a commit", - sha1_to_hex(sha1), obj->type); - return NULL; - } - return (struct commit *) obj; + if (!obj->type) + obj->type = commit_type; + return check_commit(obj, sha1); } static unsigned long parse_commit_date(const char *buf) @@ -86,6 +103,10 @@ int parse_commit(struct commit *item) sha1_to_hex(item->object.sha1)); } ret = parse_commit_buffer(item, buffer, size); + if (!ret) { + item->buffer = buffer; + return 0; + } free(buffer); return ret; }