From: Johan Herland Date: Sat, 09 Jun 2007 00:19:11 GMT Subject: [PATCH 15/21] Make tag names (i.e. the tag object's "tag" line) optional Message-ID: <200706090219.12011.johan@herland.net> In-Reply-To: <200706090210.36270.johan@herland.net> The tag line is now optional. If not given in the tag object data, it defaults to the empty string ("") in the parsed tag object. The patch also adds a change to git-show; when asked to display a tag object with no name (missing "tag" header), we will show the tag's sha1 instead of an empty string. Finally the patch includes some tweaks to the selftests to make them work with optional tag names. Signed-off-by: Johan Herland --- builtin-log.c | 2 +- t/t3800-mktag.sh | 6 +++--- tag.c | 51 +++++++++++++++++++++++++++++---------------------- tag.h | 2 +- 4 files changed, 34 insertions(+), 27 deletions(-) diff --git a/builtin-log.c b/builtin-log.c index 212cdfc..8a238c7 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -181,7 +181,7 @@ int cmd_show(int argc, const char **argv, const char *prefix) printf("%stag %s%s\n\n", diff_get_color(rev.diffopt.color_diff, DIFF_COMMIT), - t->tag, + *(t->tag) ? t->tag : name, diff_get_color(rev.diffopt.color_diff, DIFF_RESET)); ret = show_object(o->sha1, 1); diff --git a/t/t3800-mktag.sh b/t/t3800-mktag.sh index 3bce5e0..3381239 100755 --- a/t/t3800-mktag.sh +++ b/t/t3800-mktag.sh @@ -106,7 +106,7 @@ xxx mytag EOF cat >expect.pat <expect.pat <expect.pat < ' ') - continue; - return error("Tag object (@ char " PD_FMT "): " - "Could not verify tag name", - tag_line + i - data); + if (tag_len) { /* tag name was given */ + for (i = 0; i < tag_len; ++i) { + unsigned char c = tag_line[i]; + if (c > ' ' && c != 0x7f) + continue; + return error("Tag object (@ char " PD_FMT "): " + "Could not verify tag name", + tag_line + i - data); + } } /* Verify tagger line */ @@ -181,10 +182,16 @@ int parse_and_verify_tag_buffer(struct tag *item, /* The actual stuff afterwards we don't care about.. */ } - if (item) { - item->tag = xmalloc(tag_len + 1); - memcpy(item->tag, tag_line, tag_len); - item->tag[tag_len] = '\0'; + if (item) { /* Store parsed information into item */ + if (tag_len) { /* optional tag name was given */ + item->tag = xmalloc(tag_len + 1); + memcpy(item->tag, tag_line, tag_len); + item->tag[tag_len] = '\0'; + } + else { /* optional tag name not given */ + item->tag = xmalloc(1); + item->tag[0] = '\0'; + } if (!strcmp(type, blob_type)) { item->tagged = &lookup_blob(sha1)->object; diff --git a/tag.h b/tag.h index f341b7f..2631911 100644 --- a/tag.h +++ b/tag.h @@ -8,7 +8,7 @@ extern const char *tag_type; struct tag { struct object object; struct object *tagged; - char *tag; + char *tag; /* optional, may be empty ("") */ char *signature; /* not actually implemented */ }; -- 1.5.2