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

Re: [PATCH] log: add %S option (like --source) to log --format

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 8, 2019, 22:21 UTC
Message-ID
<xmqqmuoa4wp7.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<20190108132048.57142-1-issactrotts@google.com>
issac.trotts@gmail.com writes:
> From: Issac Trotts <issac.trotts@gmail.com>
Heh, I'll edit this line to match S-o-b: below.
Show 14 quoted lines
>
> Make it possible to write for example
>
>         git log --format="%H,%S"
>
> where the %S at the end is a new placeholder that prints out the ref
> (tag/branch) for each commit.
>
> Using %d might seem like an alternative but it only shows the ref for the last
> commit in the branch.
>
> Signed-off-by: Issac Trotts <issactrotts@google.com>
>
> ---
Show 9 quoted lines
> diff --git a/log-tree.c b/log-tree.c
> index 10680c139..3cb14256e 100644
> --- a/log-tree.c
> +++ b/log-tree.c
> @@ -700,6 +700,7 @@ void show_log(struct rev_info *opt)
>  	ctx.color = opt->diffopt.use_color;
>  	ctx.expand_tabs_in_log = opt->expand_tabs_in_log;
>  	ctx.output_encoding = get_log_output_encoding();
> +	ctx.rev = opt;

There are quite a few existing codepaths that change their behaviour based on NULL-ness of ctx.rev field. How would we make sure that this change have no unintended consequence, I wonder?

Show 10 quoted lines
> +	case 'S':		/* tag/branch like --source */
> +		if (c->pretty_ctx->rev == NULL || c->pretty_ctx->rev->sources == NULL) {
> +			return 0;
> +		}
> +		slot = revision_sources_at(c->pretty_ctx->rev->sources, commit);
> +		if (!(slot && *slot)) {
> +			return 0;
> +		}
> +		strbuf_addstr(sb, *slot);
> +		return 1;
Let's update the style of this hunk here like so:
	if (!c->pretty_ctx->rev || !c->pretty_ctx->rev->sources)
		return 0;
	slot = ...;
	if (!(slot && *slot))
		return 0;
	strbuf_addstr(...);
	return 1;

I wonder if it is even better to apply de-Morgan to one of the above two, i.e.

	if (!(c->pretty_ctx->rev && c->pretty_ctx->rev->sources))
		return 0;
Anyway, thanks.  Will queue.
Previous: issac.trotts@gmail.comNext: Issac Trotts
Message 2 of 5 in “log: add %S option (like --source) to log --format”
  1. log: add %S option (like --source) to log --formatissac.trotts@gmail.com, Jan 8, 2019
  2. Junio C HamanoJan 8, 2019
  3. Issac TrottsJan 11, 2019
  4. Junio C HamanoJan 11, 2019
  5. Junio C HamanoJan 11, 2019

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.