git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Taylor Blau <me@ttaylorr.com>
To: "Martin Ågren" <martin.agren@gmail.com>
Cc: Taylor Blau <me@ttaylorr.com>,
	Git Mailing List <git@vger.kernel.org>, Jeff King <peff@peff.net>,
	Derrick Stolee <dstolee@microsoft.com>,
	Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH 2/6] commit-graph.h: store object directory in 'struct commit_graph'
Date: Sun, 2 Feb 2020 19:58:19 -0800	[thread overview]
Message-ID: <20200203035819.GA23625@syl.local> (raw)
In-Reply-To: <CAN0heSrrrWjBKnzjMfzEkTMVTge2AfVdwsp6D5Mx==5S8-ZLJQ@mail.gmail.com>

Hi Martin,

Thanks for your review! Your comments were all quite helpful, and I
applied all of your suggested changes.

On Fri, Jan 31, 2020 at 07:52:02AM +0100, Martin Ågren wrote:
> On Fri, 31 Jan 2020 at 00:03, Taylor Blau <me@ttaylorr.com> wrote:
> > Instead of getting rid of the 'struct object_directory *', store that
> > insead of a 'char *odb' in 'struct commit_graph'. Once the 'struct
>
> s/insead/instead/

Typo. Thanks for noticing. I fixed this in my local copy of this branch.

> >         if (open_ok)
> >                 graph = load_commit_graph_one_fd_st(fd, &st);
> > -        else
> > -               graph = read_commit_graph_one(the_repository, opts.obj_dir);
> > +       else {
> > +               struct object_directory *odb;
> > +               if ((odb = find_odb(the_repository, opts.obj_dir)))
> > +                       graph = read_commit_graph_one(the_repository, odb);
> > +       }
>
> I'm a tiny bit allergic to this assignment-within-if. It's wrapped by
> another pair of parentheses, which both compilers and humans know to
> interpret as "trust me, this is not a mistake", but I still find this
> easier to read:
>
>   odb = find_odb(...);
>   if (odb)
>           ....

To be honest, I'm not such a fan of this style myself, but it seemed odd
to me to write:

  struct object_directory *odb;
  odb = ...;
  if (odb) {
  }

when we were really only trying to call 'find_odb()' and do something
with its result, but only if it was non-NULL. I counted 152 of these
assign-if's laying around with:

  $ git grep 'if ((.* =[^=]' | wc -l

but it seems like they are in poor style (as evidenced by your and
Junio's response later in the thread). So, I removed this and instead
promoted 'odb' to a local variable at the function level, since we
do that promotion anyway in a couple of patches later. This reduces the
churn, and avoids either an assign-if, or a define/assign/check.

> > --- a/builtin/commit.c
> > +++ b/builtin/commit.c
>
> > +#include "object-store.h"

No; this is a stray left over from some development on this branch. I'll
remove it.

> This is the only change in this file, which looks a bit odd. I haven't
> actually applied your patches, to be honest, but is this inclusion
> really needed?
>
> > --- a/commit-graph.c
> > +++ b/commit-graph.c
>
> > +struct object_directory *find_odb(struct repository *r, const char *obj_dir)
>
> This doesn't look commit-graph related -- could/should it go somewhere
> else?

I'll respond in more complete detail further down in the thread, but the
short answer is "yes, this should go in builtin/commit-graph.c".

> > +{
> > +       struct object_directory *odb;
> > +       char *obj_dir_real = real_pathdup(obj_dir, 1);
> > +       int cmp = -1;
> > +
> > +       prepare_alt_odb(r);
> > +       for (odb = r->objects->odb; odb; odb = odb->next) {
> > +               cmp = strcmp(obj_dir_real, real_path(odb->path));
> > +               if (!cmp)
> > +                       break;
> > +       }
>
> At this point, either odb is NULL or cmp is zero. Those are the only two
> ways out of the loop.
>
> > +       free(obj_dir_real);
> > +
> > +       if (cmp)
> > +               odb = NULL;
>
> Meaning that this doesn't do much? If the most recent comparison failed,
> it's because we didn't find anything, so odb will be NULL.
>
> > +       return odb;
> > +}
>
> I think you could drop `cmp` and that final check, and write the loop
> body as "if (!strcmp(...)) break". You could also have an empty loop
> body, but I wouldn't go there -- I'd find that less readable. (Maybe
> that's just me.)

Thanks, I changed this to remove the 'cmp' check outside of the loop,
which I agree is unnecessary.

> Martin

Thanks,
Taylor

  parent reply	other threads:[~2020-02-03  3:58 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-30 23:00 [PATCH 0/6] commit-graph: use 'struct object_directory *' everywhere Taylor Blau
2020-01-30 23:00 ` [PATCH 1/6] t5318: don't pass non-object directory to '--object-dir' Taylor Blau
2020-01-30 23:00 ` [PATCH 5/6] commit-graph.c: remove path normalization, comparison Taylor Blau
2020-01-30 23:00 ` [PATCH 6/6] commit-graph.h: use odb in 'load_commit_graph_one_fd_st' Taylor Blau
2020-01-30 23:00 ` [PATCH 2/6] commit-graph.h: store object directory in 'struct commit_graph' Taylor Blau
2020-01-31  6:52   ` Martin Ågren
2020-01-31 10:20     ` Jeff King
2020-01-31 19:19       ` Martin Ågren
2020-02-03  4:36       ` Taylor Blau
2020-02-03  8:36         ` Jeff King
2020-01-31 20:49     ` Junio C Hamano
2020-02-03  3:58     ` Taylor Blau [this message]
2020-01-30 23:00 ` [PATCH 4/6] commit-graph.h: store an odb in 'struct write_commit_graph_context' Taylor Blau
2020-01-30 23:00 ` [PATCH 3/6] builtin/commit-graph.c: die() with unknown '--object-dir' Taylor Blau
2020-01-31 10:30 ` [PATCH 0/6] commit-graph: use 'struct object_directory *' everywhere Jeff King
2020-01-31 13:22   ` Derrick Stolee
2020-02-03  4:38     ` Taylor Blau
2020-02-03 21:17 ` [PATCH v2 0/5] " Taylor Blau
2020-02-03 21:17   ` [PATCH v2 1/5] t5318: don't pass non-object directory to '--object-dir' Taylor Blau
2020-02-03 21:17   ` [PATCH v2 2/5] commit-graph.h: store an odb in 'struct write_commit_graph_context' Taylor Blau
2020-02-04  5:51     ` Taylor Blau
2020-02-04 19:54       ` Junio C Hamano
2020-02-04 21:28         ` Taylor Blau
2020-02-04 21:44           ` Junio C Hamano
2020-02-03 21:18   ` [PATCH v2 3/5] commit-graph.h: store object directory in 'struct commit_graph' Taylor Blau
2020-02-03 21:18   ` [PATCH v2 4/5] commit-graph.c: remove path normalization, comparison Taylor Blau
2020-02-03 21:18   ` [PATCH v2 5/5] commit-graph.h: use odb in 'load_commit_graph_one_fd_st' Taylor Blau
2020-02-05 12:30   ` [PATCH v2 0/5] commit-graph: use 'struct object_directory *' everywhere Jeff King

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=20200203035819.GA23625@syl.local \
    --to=me@ttaylorr.com \
    --cc=dstolee@microsoft.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=martin.agren@gmail.com \
    --cc=peff@peff.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).