diff options
author | Erik van Zijst <erik.van.zijst@gmail.com> | 2012-11-02 21:28:17 +0400 |
---|---|---|
committer | Erik van Zijst <erik.van.zijst@gmail.com> | 2012-11-02 21:28:17 +0400 |
commit | 6bb9fea13ee2da6475ac799acd5f8296bc1a8537 (patch) | |
tree | d9947d87d5f11136993cc4cf08c3ea00897329dc /src/tag.c | |
parent | e30c052c4e46df9d8f929ab4f86f34718bb15a5d (diff) |
tags: Fixed the tag parser to correctly treat the message field as optional.
This fix makes libgit2 capable of parsing annotated tag objects that lack
the optional message/description field.
Previously, libgit2 treated this field as mandatory and raised a tag_error on
such tags. However, the message field is optional.
An example of such a tag is refs/tags/v2.6.16.31-rc1 in Linux:
$ git cat-file tag refs/tags/v2.6.16.31-rc1
object afaa018cefb6af63befef1df7d8febaae904434f
type commit
tag v2.6.16.31-rc1
tagger Adrian Bunk <bunk@stusta.de> 1162716505 +0100
$
Diffstat (limited to 'src/tag.c')
-rw-r--r-- | src/tag.c | 17 |
1 files changed, 10 insertions, 7 deletions
@@ -139,16 +139,19 @@ int git_tag__parse_buffer(git_tag *tag, const char *buffer, size_t length) return -1; } - if( *buffer != '\n' ) - return tag_error("No new line before message"); + tag->message = NULL; + if (buffer < buffer_end) { + if( *buffer != '\n' ) + return tag_error("No new line before message"); - text_len = buffer_end - ++buffer; + text_len = buffer_end - ++buffer; - tag->message = git__malloc(text_len + 1); - GITERR_CHECK_ALLOC(tag->message); + tag->message = git__malloc(text_len + 1); + GITERR_CHECK_ALLOC(tag->message); - memcpy(tag->message, buffer, text_len); - tag->message[text_len] = '\0'; + memcpy(tag->message, buffer, text_len); + tag->message[text_len] = '\0'; + } return 0; } |