git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Eric Sunshine <sunshine@sunshineco.com>
To: "Quang Lê Duy" <leduyquang753@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [RFC PATCH 1/1] Add separator lines into `git log --graph`.
Date: Sun, 7 Apr 2024 05:07:37 -0400	[thread overview]
Message-ID: <CAPig+cSD7ONA-MUt=dxt5nh2FQ1nJjbcdDb0ko0j0sBrr0reqg@mail.gmail.com> (raw)
In-Reply-To: <CACXAH50jwngEQLF612FMyZ36yB5Nd7vVHS98KMWYjXqcNzvpwg@mail.gmail.com>

On Sun, Apr 7, 2024 at 3:04 AM Quang Lê Duy <leduyquang753@gmail.com> wrote:
> On Sun, Apr 7, 2024 at 12:47 PM Eric Sunshine <sunshine@sunshineco.com> wrote:
> > > +       return graph->connected_region_state == CONNECTED_REGION_NEW_REGION || (graph->num_parents >= 3 &&
> > > +       graph->connected_region_state = (graph->connected_region_state != CONNECTED_REGION_FIRST_COMMIT &&
> > > +               graph->num_new_columns == 0) ? CONNECTED_REGION_NEW_REGION : CONNECTED_REGION_USE_CURRENT;
> >
> > Style: overly long lines
>
> May I ask how am I expected to place the line breaks? The Linux kernel style
> guide I consulted
> (https://www.kernel.org/doc/html/v4.10/process/coding-style.html) doesn't seem
> to go into too much detail on this.

I don't have a precise answer other than "use good taste". One
reasonably solid rule is that when wrapping at `&&` and `||`, those
operators should appear at the end of the line rather than the
beginning of the next line. So, a possible wrapping for these two
cases might be:

    return graph->connected_region_state == CONNECTED_REGION_NEW_REGION ||
        (graph->num_parents >= 3 &&
        graph->commit_index < (graph->num_columns - 1) &&
        graph->expansion_row < graph_num_expansion_rows(graph));

    graph->connected_region_state =
        (graph->connected_region_state != CONNECTED_REGION_FIRST_COMMIT &&
        graph->num_new_columns == 0) ?
        CONNECTED_REGION_NEW_REGION : CONNECTED_REGION_USE_CURRENT;

Since this enum is private to the C file and not part of an expressive
public API, another possibility for reducing the line length is to
shorten some of the names. For instance:

    enum connected_region_state {
        CONNREG_FIRST_COMMIT,
        CONNREG_USE_CURRENT,
        CONNREG_NEW_REGION
    };

> > > +static void graph_output_separator_line(struct git_graph *graph, struct graph_line *line)
> > > +{
> > > +       /*
> > > +        * This function adds a row that separates two disconnected graphs,
> > > +        * as the appearance of multiple separate commits on top of each other
> > > +        * may cause a misunderstanding that they belong to a timeline.
> > > +        */
> >
> > This comment seems to explain the purpose of the function itself. As
> > such, it should precede the function definition rather than being
> > embedded within it.
>
> I just followed what the surrounding code did (particularly in the original
> `graph_output_pre_commit_line` function), but on second look that functionality
> comment seems to only serve as context for the sentence below that so OK.

Indeed, looking at graph_output_pre_commit_line(), the comment seems
to be explaining the reason for the assert() in that function, whereas
the comment you wrote here seems to be explaining the purpose of the
function itself.

> > > +       assert(graph->connected_region_state == CONNECTED_REGION_NEW_REGION);
> >
> > We tend to use BUG() rather than assert():
>
> Same thing, I just followed that `graph_output_pre_commit_line` did. So I should
> forgo the consistency here? Or is that usage of `assert` in the existing code
> also to be updated?

I see what you mean, now that I'm looking at graph.c. Since assert()
is used so heavily in this file already (and there are no BUG()
invocations at all), it probably makes sense to be consistent and use
assert() here, as well. Adding a sentence to the commit message
explaining that you're using assert() for consistency rather than
BUG() will be helpful to reviewers.

While it might be a nice cleanup to eventually swap out assert() in
favor of BUG(), we should leave that for another day in order to keep
this patch well-focused. (We don't want to add a bunch of "while at
it, let's also change this" items, thus losing focus on what you
actually want to achieve.)

> > > +       /*
> > > +        * Output the row.
> > > +        */
> > > +       graph_line_addstr(line, "---");
> >
> > The code itself is obvious enough without the comment, so the comment
> > is mere noise, thus should be dropped.
>
> Also same thing that I followed for consistency.

Understandable. In this case, I don't personally feel that this
comment is adding any value, thus would drop it, but others (including
yourself) may feel differently.

> > Modern test style is to perform all actions inside the
> > test_expect_success body itself, so:
> >
> >     test_expect_success 'all commits' '
> >         cat >expect <<-\EOF
> >         ...
> >         EOF
> >         test_cmp_graph a b c d e
> >     '
> >
> > Note the use of <<- to allow you to indent the here-doc body.
>
> This is also because I followed what `t4202-log.sh` did, but if that represents
> outdated practice then I'll change.

Understood.

Generally speaking, when adding new tests, we do want to follow modern
practice; that's especially true when creating a brand new test
script, but even when adding new tests to an existing script.

If you're modifying an existing test, then being consistent with the
surrounding code is a good idea. Consistency may also be reasonable
sometimes when inserting a new test into a block of existing
closely-related tests. Saying so in the commit message will help
reviewers understand.


  reply	other threads:[~2024-04-07  9:08 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-07  5:10 [RFC PATCH 0/1] Add lines to `git log --graph` to separate connected regions Lê Duy Quang
2024-04-07  5:10 ` [RFC PATCH 1/1] Add separator lines into `git log --graph` Lê Duy Quang
2024-04-07  5:47   ` Eric Sunshine
2024-04-07  5:52     ` Eric Sunshine
2024-04-07  7:06       ` Quang Lê Duy
2024-04-07  8:35         ` Dragan Simic
2024-04-07  7:03     ` Quang Lê Duy
2024-04-07  9:07       ` Eric Sunshine [this message]
2024-04-07  5:30 ` [RFC PATCH 0/1] Add lines to `git log --graph` to separate connected regions Eric Sunshine
2024-04-07  5:37   ` Junio C Hamano
2024-04-07  6:40     ` Quang Lê Duy
2024-04-07  8:34       ` Dragan Simic
2024-04-07  8:46         ` Quang Lê Duy
2024-04-07  9:13           ` Dragan Simic
2024-04-08 15:49     ` Junio C Hamano

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='CAPig+cSD7ONA-MUt=dxt5nh2FQ1nJjbcdDb0ko0j0sBrr0reqg@mail.gmail.com' \
    --to=sunshine@sunshineco.com \
    --cc=git@vger.kernel.org \
    --cc=leduyquang753@gmail.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.
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).