git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Christian Couder <christian.couder@gmail.com>
Cc: "brian m. carlson" <sandals@crustytoothpaste.net>,
	git <git@vger.kernel.org>, Jeff King <peff@peff.net>,
	Taylor Blau <me@ttaylorr.com>
Subject: Re: [PATCH] rev-list: add option for --pretty without header
Date: Fri, 09 Jul 2021 08:44:20 -0700	[thread overview]
Message-ID: <xmqq8s2f8pbf.fsf@gitster.g> (raw)
In-Reply-To: <CAP8UFD0t0=us1MWHTtEvVhNhWB1P6Q5gp-6v5XVGLBVeZ5RYKg@mail.gmail.com> (Christian Couder's message of "Fri, 9 Jul 2021 10:01:46 +0200")

Christian Couder <christian.couder@gmail.com> writes:

> On Wed, Jul 7, 2021 at 12:47 AM brian m. carlson
> <sandals@crustytoothpaste.net> wrote:
>>
>> In general, we encourage users to use plumbing commands, like git
>> rev-list, over porcelain commands, like git log, when scripting.
>> However, git rev-list has one glaring problem that prevents it from
>> being used in certain cases: when --pretty is used, it always prints out
>> a line containing "commit" and the object ID.
>
> You say always, but it looks like it doesn't do it when
> --pretty=oneline is used.

I've understood that he meant "when --pretty=format is used",
though, as it is the only format whose intent was to allow
generation of output stream that does not have to be preprocessed
with "grep -v '^[0-9a-f]{40}'" etc.

> It looks like the tests only check what happens in case
> --pretty=format:'...' is used, but I wonder what the code does if a
> builtin format is used.

Good point.

I also think the handling of --abbrev-commit may need to be
rethought with this change.  See here:

    diff --git a/builtin/rev-list.c b/builtin/rev-list.c
    index 7677b1af5a..f571cc9598 100644
    --- a/builtin/rev-list.c
    +++ b/builtin/rev-list.c
    @@ -132,7 +132,7 @@ static void show_commit(struct commit *commit, void *data)
            if (revs->abbrev_commit && revs->abbrev)
                    fputs(find_unique_abbrev(&commit->object.oid, revs->abbrev),
                          stdout);
    -	else
    +	else if (revs->include_header)
                    fputs(oid_to_hex(&commit->object.oid), stdout);
            if (revs->print_parents) {
                    struct commit_list *parents = commit->parents;

The original says that if --abbrev-commit is set and --abbrev is set
to non-zero, we'd show unique abbreviation and if not, specifically,
even when --abbrev-commit is set but --abbrev is set to 0, we didn't
do the find_unique_abbrev() of full hexdigits but left the output to
the else clause.  This was because the original code KNOWS that the
else clause unconditionally emits the full commit object name.

That assumption, which made the original code's handling of
"--abbrev-commit --abbrev=0" correct, no longer holds with the
updated code.  What happens is with --no-commit-header, if we give
"--abbrev-commit --abbrev=4", we still see the unique abbreviation
that is not shorter than 4 hexdigits (i.e. "--no-commit-header" is
ignored), but if we say "--abbrev-commit --abbrev=0", we do not see
any commit header.

My hunch is that this "if / else", which determines if the commit
header should give shortened or full length, should be skipped when
the .include_header is false.

  reply	other threads:[~2021-07-09 15:44 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-06 22:43 [PATCH] rev-list: add option for --pretty without header brian m. carlson
2021-07-09  8:01 ` Christian Couder
2021-07-09 15:44   ` Junio C Hamano [this message]
2021-07-11 17:02     ` brian m. carlson
2021-07-11 21:55 ` [PATCH v2] rev-list: add option for --pretty=format " brian m. carlson
2021-07-12  7:30   ` Christian Couder
2021-07-13  0:10     ` brian m. carlson
2021-07-12 18:13   ` Jeff King
2021-07-13  0:15     ` brian m. carlson

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqq8s2f8pbf.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=me@ttaylorr.com \
    --cc=peff@peff.net \
    --cc=sandals@crustytoothpaste.net \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).