From: Michael Schubert <mschub@elegosoft.com>
To: Junio C Hamano <gitster@pobox.com>,
Alex Vandiver <alex@chmrr.net>,
git@vger.kernel.org
Subject: [RFC/PATCH] tag: disallow '-' as tag name
Date: Tue, 10 May 2011 00:56:19 +0200 [thread overview]
Message-ID: <4DC87113.4030204@elegosoft.com> (raw)
In-Reply-To: <7v39knpxbe.fsf@alter.siamese.dyndns.org>
Add strbuf_check_tag_ref() as helper to check a refname for a tag.
Signed-off-by: Michael Schubert <mschub@elegosoft.com>
---
builtin/tag.c | 30 ++++++++++++++++++++++--------
1 files changed, 22 insertions(+), 8 deletions(-)
diff --git a/builtin/tag.c b/builtin/tag.c
index b66b34a..f087a7f 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -352,11 +352,26 @@ static int parse_msg_arg(const struct option *opt, const char *arg, int unset)
return 0;
}
+static int strbuf_check_tag_ref(struct strbuf *sb, const char *name)
+{
+ if (name[0] == '-')
+ return CHECK_REF_FORMAT_ERROR;
+
+ strbuf_reset(sb);
+ strbuf_add(sb, "refs/tags/", 10);
+ strbuf_add(sb, name, strlen(name));
+
+ if (sb->len > PATH_MAX)
+ die(_("tag name too long: %.*s..."), 50, name);
+
+ return check_ref_format(sb->buf);
+}
+
int cmd_tag(int argc, const char **argv, const char *prefix)
{
struct strbuf buf = STRBUF_INIT;
+ struct strbuf ref = STRBUF_INIT;
unsigned char object[20], prev[20];
- char ref[PATH_MAX];
const char *object_ref, *tag;
struct ref_lock *lock;
@@ -452,12 +467,10 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
if (get_sha1(object_ref, object))
die(_("Failed to resolve '%s' as a valid ref."), object_ref);
- if (snprintf(ref, sizeof(ref), "refs/tags/%s", tag) > sizeof(ref) - 1)
- die(_("tag name too long: %.*s..."), 50, tag);
- if (check_ref_format(ref))
+ if (strbuf_check_tag_ref(&ref, tag))
die(_("'%s' is not a valid tag name."), tag);
- if (!resolve_ref(ref, prev, 1, NULL))
+ if (!resolve_ref(ref.buf, prev, 1, NULL))
hashclr(prev);
else if (!force)
die(_("tag '%s' already exists"), tag);
@@ -466,14 +479,15 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
create_tag(object, tag, &buf, msg.given || msgfile,
sign, prev, object);
- lock = lock_any_ref_for_update(ref, prev, 0);
+ lock = lock_any_ref_for_update(ref.buf, prev, 0);
if (!lock)
- die(_("%s: cannot lock the ref"), ref);
+ die(_("%s: cannot lock the ref"), ref.buf);
if (write_ref_sha1(lock, object, NULL) < 0)
- die(_("%s: cannot update the ref"), ref);
+ die(_("%s: cannot update the ref"), ref.buf);
if (force && hashcmp(prev, object))
printf(_("Updated tag '%s' (was %s)\n"), tag, find_unique_abbrev(prev, DEFAULT_ABBREV));
strbuf_release(&buf);
+ strbuf_release(&ref);
return 0;
}
--
1.7.5.1
next prev parent reply other threads:[~2011-05-09 22:56 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-09 15:21 Tags named '-' Alex Vandiver
2011-05-09 18:01 ` Junio C Hamano
2011-05-09 22:56 ` Michael Schubert [this message]
2011-05-09 23:08 ` [RFC/PATCH] tag: disallow '-' as tag name Junio C Hamano
2011-05-09 23:36 ` [RFC/PATCH v2] " Michael Schubert
[not found] ` <BANLkTik7PYjGMMfxaNPubYR7M1OgBrF_qw@mail.gmail.com>
2011-05-10 9:47 ` Michael Schubert
2011-05-09 22:04 ` Tags named '-' Sverre Rabbelier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4DC87113.4030204@elegosoft.com \
--to=mschub@elegosoft.com \
--cc=alex@chmrr.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.