git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Issac Trotts <issac.trotts@gmail.com>
Cc: git@vger.kernel.org, Noemi Mercado <noemi@sourcegraph.com>
Subject: Re: [PATCH] log: add %S option (like --source) to log --format
Date: Mon, 17 Dec 2018 18:31:33 +0900	[thread overview]
Message-ID: <xmqqk1k8bitm.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <CANdyxMwxPqTMfLsoK-2JT3Wf3hXZnQNCPRS04aSHzsMbYJZo-Q@mail.gmail.com> (Issac Trotts's message of "Sun, 16 Dec 2018 22:25:14 -0800")

Issac Trotts <issac.trotts@gmail.com> writes:

> 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.

Have your sign-off here (see Documentation/SubmittingPatches),

and then have a line that only has three-dashes on it,

and then any other additional info like this.

>
> This change is based on a question from Stack Overflow:
> https://stackoverflow.com/questions/12712775/git-get-source-information-in-format
> ---




>  Documentation/pretty-formats.txt |  2 ++
>  builtin/log.c                    |  2 +-
>  log-tree.c                       |  1 +
>  pretty.c                         | 10 +++++++
>  t/t4205-log-pretty-formats.sh    | 50 ++++++++++++++++++++++++++++++++
>  5 files changed, 64 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt
> index 417b638cd..acfe7e0a4 100644
> --- a/Documentation/pretty-formats.txt
> +++ b/Documentation/pretty-formats.txt
> @@ -104,6 +104,8 @@ The placeholders are:
>
>  - '%H': commit hash
>  - '%h': abbreviated commit hash
> +- '%S': ref name given on the command line by which the commit was reached
> +  (like `git log --source`)

This looks entirely out of place, among the description of the basic
basic data like the object name of the commit itself, its tree, etc.

Describe this immediately after %d and %D are explained, perhaps.

> diff --git a/builtin/log.c b/builtin/log.c
> index e8e51068b..a314ea2b6 100644
> --- a/builtin/log.c
> +++ b/builtin/log.c
> @@ -203,7 +203,7 @@ static void cmd_log_init_finish(int argc, const
> char **argv, const char *prefix,
>          rev->diffopt.filter || rev->diffopt.flags.follow_renames)
>          rev->always_show_header = 0;
>
> -    if (source) {
> +    if (source || (rev->pretty_given && rev->commit_format ==
> CMIT_FMT_USERFORMAT)) {

Broken line (you let your MUA line-wrap and corrupt your patch???)

>          init_revision_sources(&revision_sources);
>          rev->sources = &revision_sources;
>      }

This means anybody who asks for say --format='%aN %s' pays the price
of keeping track of each commit's source, which is unreasonable.

Perhaps mimick the way how presence of %N is detected in
userformat_want_item() so that we do not pay the price for
init_display_notes() when a format that does not care about %N is
given?

> @@ -1149,6 +1150,15 @@ static size_t format_commit_one(struct strbuf
> *sb, /* in UTF-8 */
>          parse_object(the_repository, &commit->object.oid);
>
>      switch (placeholder[0]) {
> +    case 'S':        /* tag/branch like --source */
> +        slot = revision_sources_at(c->pretty_ctx->rev->sources, commit);
> +        if (slot && *slot) {
> +            strbuf_addstr(sb, *slot);
> +            return 1;
> +        } else {
> +            die(_("failed to get info for %%S"));
> +            return 0;
> +        }

Have this next to case arms that deal with 'd' and 'D".

>      case 'H':        /* commit hash */
>          strbuf_addstr(sb, diff_get_color(c->auto_color, DIFF_COMMIT));
>          strbuf_addstr(sb, oid_to_hex(&commit->object.oid));

This is a tangent, but I think this existing case arm should move to
the previous block before parsing the commit, as %H only needs the
object name of the commit itself (reword the comment before that
switch to read from "independent of the commit" to "computable
without parsing the commit")..

  reply	other threads:[~2018-12-17  9:31 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-17  6:25 [PATCH] log: add %S option (like --source) to log --format Issac Trotts
2018-12-17  9:31 ` Junio C Hamano [this message]
2018-12-18  3:35   ` Issac Trotts
2018-12-17 15:59 ` Jeff King
2018-12-18 17:14   ` Issac Trotts
2018-12-19  3:47     ` Issac Trotts
2018-12-19  8:07       ` Issac Trotts
2018-12-19 17:09         ` Issac Trotts
  -- strict thread matches above, loose matches on Subject: below --
2018-12-19  8:33 issac.trotts
2018-12-21  5:24 ` Issac Trotts
2018-12-22 22:22   ` Jeff King
2018-12-25  2:12     ` Issac Trotts
2018-12-27 13:20 ` Derrick Stolee
2018-12-28 18:14   ` Junio C Hamano
2018-12-31  4:35   ` Issac Trotts
2018-12-31  4:53 issac.trotts
2019-01-02 19:33 ` Junio C Hamano
2019-01-08 13:14   ` Issac Trotts
2018-12-31 21:48 issac.trotts
2019-01-08 13:20 issac.trotts
2019-01-08 22:21 ` Junio C Hamano
2019-01-11  6:28   ` Issac Trotts
2019-01-11 17:37     ` Junio C Hamano
2019-01-11 17:47     ` Junio C Hamano
2019-01-11  6:30 issac.trotts

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=xmqqk1k8bitm.fsf@gitster-ct.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=issac.trotts@gmail.com \
    --cc=noemi@sourcegraph.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 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).