git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] tag: add --author option

From
Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Date
Mar 27, 2012, 17:29 UTC
Message-ID
<4F71F902.8090200@in.waw.pl>
In-Reply-To
<4F71E415.9030800@gmx.ch>
On 03/27/2012 06:00 PM, Mathias Weber wrote:
>
> The tag command does not support the --author option as the
> commit command. This adds the --author option to create
> annotated tags with a different author.
Consistency is good.
Show 36 quoted lines
> Signed-off-by: Mathias Weber<mathew.weber@gmail.com>
> ---
>   builtin/tag.c |   26 +++++++++++++++++++++++---
>   1 files changed, 23 insertions(+), 3 deletions(-)
>
> diff --git a/builtin/tag.c b/builtin/tag.c
> index fe7e5e5..416fa88 100644
> --- a/builtin/tag.c
> +++ b/builtin/tag.c
> @@ -309,17 +309,34 @@ struct create_tag_options {
>
>   static void create_tag(const unsigned char *object, const char *tag,
>   		       struct strbuf *buf, struct create_tag_options *opt,
> -		       unsigned char *prev, unsigned char *result)
> +		       unsigned char *prev, unsigned char *result,
> +		       const char *force_author)
>   {
>   	enum object_type type;
>   	char header_buf[1024];
>   	int header_len;
>   	char *path = NULL;
> +	char *name, *email;
> +	const char *author_ident;
>
>   	type = sha1_object_info(object, NULL);
>   	if (type<= OBJ_NONE)
>   	    die(_("bad object type."));
>
> +	if (force_author) {
> +		const char *lb = strstr(force_author, "<");
> +		const char *rb = strchr(force_author, '>');
> +
> +		if (!lb || !rb)
> +			die(_("malformed --author parameter"));
> +			name = xstrndup(force_author, lb - force_author);
> +			email = xstrndup(lb + 2, rb - (lb + 2));

This part is identical to builtin/commit.c, it would be nice to refactor it into a function.

Zbyszek
Show 44 quoted lines
> +
> +		author_ident = fmt_ident(name, email, getenv("GIT_AUTHOR_DATE"),
> +				IDENT_ERROR_ON_NO_NAME);
> +	} else
> +		author_ident = git_committer_info(IDENT_ERROR_ON_NO_NAME);
> +
>   	header_len = snprintf(header_buf, sizeof(header_buf),
>   			  "object %s\n"
>   			  "type %s\n"
> @@ -328,7 +345,7 @@ static void create_tag(const unsigned char *object, const char *tag,
>   			  sha1_to_hex(object),
>   			  typename(type),
>   			  tag,
> -			  git_committer_info(IDENT_ERROR_ON_NO_NAME));
> +			  author_ident);
>
>   	if (header_len>  sizeof(header_buf) - 1)
>   		die(_("tag header too big."));
> @@ -438,6 +455,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
>   		delete = 0, verify = 0;
>   	const char *msgfile = NULL, *keyid = NULL;
>   	struct msg_arg msg = { 0, STRBUF_INIT };
> +	const char *force_author = NULL;
>   	struct commit_list *with_commit = NULL;
>   	struct option options[] = {
>   		OPT_BOOLEAN('l', "list",&list, "list tag names"),
> @@ -452,6 +470,8 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
>   					"annotated tag, needs a message"),
>   		OPT_CALLBACK('m', "message",&msg, "message",
>   			     "tag message", parse_msg_arg),
> +		OPT_STRING(0, "author",&force_author, "author",
> +				 "override author for annotated tag"),
>   		OPT_FILENAME('F', "file",&msgfile, "read message from file"),
>   		OPT_BOOLEAN('s', "sign",&opt.sign, "annotated and GPG-signed tag"),
>   		OPT_STRING(0, "cleanup",&cleanup_arg, "mode",
> @@ -556,7 +576,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
>   		die(_("Invalid cleanup mode %s"), cleanup_arg);
>
>   	if (annotate)
> -		create_tag(object, tag,&buf,&opt, prev, object);
> +		create_tag(object, tag,&buf,&opt, prev, object, force_author);
>
>   	lock = lock_any_ref_for_update(ref.buf, prev, 0);
>   	if (!lock)
Previous: Mathias WeberNext: Mathias Weber
Message 2 of 7 in “tag: add --author option”
  1. tag: add --author optionMathias Weber, Mar 27, 2012
  2. Zbigniew Jędrzejewski-SzmekMar 27, 2012
  3. Mathias WeberMar 27, 2012
  4. Junio C HamanoMar 27, 2012
  5. Mathias WeberMar 27, 2012
  6. Junio C HamanoMar 27, 2012
  7. Junio C HamanoMar 27, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.