This is in preparation for unifying verify_tag() and parse_tag_buffer_internal(). Signed-off-by: Johan Herland <johan@xxxxxxxxxxx> --- tag.c | 54 +++++++++++++++++++++++++++++------------------------- 1 files changed, 29 insertions(+), 25 deletions(-) diff --git a/tag.c b/tag.c index 19c66cd..b134967 100644 --- a/tag.c +++ b/tag.c @@ -46,9 +46,11 @@ static int parse_tag_buffer_internal(struct tag *item, const char *data, const u const char *type_line, *tag_line, *tagger_line; unsigned long type_len, tag_len; - if (item->object.parsed) - return 0; - item->object.parsed = 1; + if (item) { + if (item->object.parsed) + return 0; + item->object.parsed = 1; + } if (size < 64) return error("failed preliminary size check"); @@ -85,28 +87,30 @@ static int parse_tag_buffer_internal(struct tag *item, const char *data, const u memcpy(type, type_line + 5, type_len); type[type_len] = '\0'; - tag_len = tagger_line - tag_line - strlen("tag \n"); - item->tag = xmalloc(tag_len + 1); - memcpy(item->tag, tag_line + 4, tag_len); - item->tag[tag_len] = '\0'; - - if (!strcmp(type, blob_type)) { - item->tagged = &lookup_blob(sha1)->object; - } else if (!strcmp(type, tree_type)) { - item->tagged = &lookup_tree(sha1)->object; - } else if (!strcmp(type, commit_type)) { - item->tagged = &lookup_commit(sha1)->object; - } else if (!strcmp(type, tag_type)) { - item->tagged = &lookup_tag(sha1)->object; - } else { - error("Unknown type %s", type); - item->tagged = NULL; - } - - if (item->tagged && track_object_refs) { - struct object_refs *refs = alloc_object_refs(1); - refs->ref[0] = item->tagged; - set_object_refs(&item->object, refs); + if (item) { + tag_len = tagger_line - tag_line - strlen("tag \n"); + item->tag = xmalloc(tag_len + 1); + memcpy(item->tag, tag_line + 4, tag_len); + item->tag[tag_len] = '\0'; + + if (!strcmp(type, blob_type)) { + item->tagged = &lookup_blob(sha1)->object; + } else if (!strcmp(type, tree_type)) { + item->tagged = &lookup_tree(sha1)->object; + } else if (!strcmp(type, commit_type)) { + item->tagged = &lookup_commit(sha1)->object; + } else if (!strcmp(type, tag_type)) { + item->tagged = &lookup_tag(sha1)->object; + } else { + error("Unknown type %s", type); + item->tagged = NULL; + } + + if (item->tagged && track_object_refs) { + struct object_refs *refs = alloc_object_refs(1); + refs->ref[0] = item->tagged; + set_object_refs(&item->object, refs); + } } return 0; -- 1.5.2 - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html