Re: [PATCH 2/6] commit-graph.h: store object directory in 'struct commit_graph'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 31 Jan 2020 at 00:03, Taylor Blau <me@xxxxxxxxxxxx> 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/

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

> --- a/builtin/commit.c
> +++ b/builtin/commit.c

> +#include "object-store.h"

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?

> +{
> +       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.)

Martin



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux