* [PATCH] tag: implement --no-strip option
@ 2011-11-14 11:08 Kirill A. Shutemov
2011-11-14 20:26 ` Junio C Hamano
0 siblings, 1 reply; 2+ messages in thread
From: Kirill A. Shutemov @ 2011-11-14 11:08 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Kirill A. Shutemov
From: "Kirill A. Shutemov" <kirill@shutemov.name>
--no-strip turns off strip any comments or empty lines.
It's useful if you want to take a tag message as-is, without any
stripping.
Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
---
Documentation/git-tag.txt | 4 ++++
builtin/tag.c | 13 ++++++++-----
2 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/Documentation/git-tag.txt b/Documentation/git-tag.txt
index c83cb13..947d4e5 100644
--- a/Documentation/git-tag.txt
+++ b/Documentation/git-tag.txt
@@ -99,6 +99,10 @@ OPTIONS
Implies `-a` if none of `-a`, `-s`, or `-u <key-id>`
is given.
+-S::
+--no-strip::
+ Take tag message as-is. Do not strip any comments or empty lines.
+
<tagname>::
The name of the tag to create, delete, or describe.
The new tag name must pass all checks defined by
diff --git a/builtin/tag.c b/builtin/tag.c
index 9b6fd95..427d646 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -320,7 +320,7 @@ static int build_tag_object(struct strbuf *buf, int sign, unsigned char *result)
}
static void create_tag(const unsigned char *object, const char *tag,
- struct strbuf *buf, int message, int sign,
+ struct strbuf *buf, int message, int sign, int nostrip,
unsigned char *prev, unsigned char *result)
{
enum object_type type;
@@ -356,7 +356,7 @@ static void create_tag(const unsigned char *object, const char *tag,
if (!is_null_sha1(prev))
write_tag_body(fd, prev);
- else
+ else if (!nostrip)
write_or_die(fd, _(tag_template), strlen(_(tag_template)));
close(fd);
@@ -367,7 +367,8 @@ static void create_tag(const unsigned char *object, const char *tag,
}
}
- stripspace(buf, 1);
+ if (!nostrip)
+ stripspace(buf, 1);
if (!message && !buf->len)
die(_("no tag message?"));
@@ -423,7 +424,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
const char *object_ref, *tag;
struct ref_lock *lock;
- int annotate = 0, sign = 0, force = 0, lines = -1,
+ int annotate = 0, sign = 0, nostrip = 0, force = 0, lines = -1,
list = 0, delete = 0, verify = 0;
const char *msgfile = NULL, *keyid = NULL;
struct msg_arg msg = { 0, STRBUF_INIT };
@@ -443,6 +444,8 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
"tag message", parse_msg_arg),
OPT_FILENAME('F', "file", &msgfile, "read message from file"),
OPT_BOOLEAN('s', "sign", &sign, "annotated and GPG-signed tag"),
+ OPT_BOOLEAN('S', "no-strip", &nostrip,
+ "turn off tag message stripping"),
OPT_STRING('u', "local-user", &keyid, "key-id",
"use another key to sign the tag"),
OPT__FORCE(&force, "replace the tag if exists"),
@@ -525,7 +528,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
if (annotate)
create_tag(object, tag, &buf, msg.given || msgfile,
- sign, prev, object);
+ sign, nostrip, prev, object);
lock = lock_any_ref_for_update(ref.buf, prev, 0);
if (!lock)
--
1.7.7.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] tag: implement --no-strip option
2011-11-14 11:08 [PATCH] tag: implement --no-strip option Kirill A. Shutemov
@ 2011-11-14 20:26 ` Junio C Hamano
0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2011-11-14 20:26 UTC (permalink / raw)
To: Kirill A. Shutemov; +Cc: git, Junio C Hamano
"Kirill A. Shutemov" <kirill@shutemov.name> writes:
> +-S::
> +--no-strip::
> + Take tag message as-is. Do not strip any comments or empty lines.
Wrong naming convention. Just introduce a boolean --strip option which is
on by default, without adding -S; use of parse-options will allow the user
to negate it from the command line with --no-strip for free.
> diff --git a/builtin/tag.c b/builtin/tag.c
> index 9b6fd95..427d646 100644
> --- a/builtin/tag.c
> +++ b/builtin/tag.c
> @@ -320,7 +320,7 @@ static int build_tag_object(struct strbuf *buf, int sign, unsigned char *result)
> }
>
> static void create_tag(const unsigned char *object, const char *tag,
> - struct strbuf *buf, int message, int sign,
> + struct strbuf *buf, int message, int sign, int nostrip,
Again, wrong naming convention. "int strip" would be fine but I think at
this point "message, sign, strip" tuple should become fields of "struct
create_tag_option" that is passed to this funciton.
> unsigned char *prev, unsigned char *result)
> {
> enum object_type type;
> @@ -356,7 +356,7 @@ static void create_tag(const unsigned char *object, const char *tag,
>
> if (!is_null_sha1(prev))
> write_tag_body(fd, prev);
> - else
> + else if (!nostrip)
This double negation comes only because the argument is misnamed with negation.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-11-14 20:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-14 11:08 [PATCH] tag: implement --no-strip option Kirill A. Shutemov
2011-11-14 20:26 ` Junio C Hamano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).