Re: [PATCH 1/5] connect: split git:// setup into a separate function
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Oct 24, 2017, 01:44 UTC
- Message-ID
- <xmqqpo9d9v5y.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <20171023231703.f457jp43dh7fddpv@aiede.mtv.corp.google.com>
Jonathan Nieder <jrnieder@gmail.com> writes:
Show 10 quoted lines
> The git_connect function is growing long. Split the > PROTO_GIT-specific portion to a separate function to make it easier to > read. > > No functional change intended. > > Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> > Reviewed-by: Stefan Beller <sbeller@google.com> > --- > As before, except with sbeller's Reviewed-by.
I found this quite nice, except for one thing.
Show 12 quoted lines
> +/*
> + * Open a connection using Git's native protocol.
> + *
> + * The caller is responsible for freeing hostandport, but this function may
> + * modify it (for example, to truncate it to remove the port part).
> + */
> +static struct child_process *git_connect_git(int fd[2], char *hostandport,
> + const char *path, const char *prog,
> + int flags)
> +{
> + struct child_process *conn = &no_fork;
> + struct strbuf request = STRBUF_INIT;As this one decides what "conn" to return, including the fallback &no_fork instance,...
Show 8 quoted lines
> + ... > + return conn; > +} > + > /* > * This returns a dummy child_process if the transport protocol does not > * need fork(2), or a struct child_process object if it does. Once done, > @@ -881,50 +939,7 @@ struct child_process *git_connect(int fd[2], const char *url,
Each of the if/elseif/ cascade, one of which calls the new helper, now makes an explicit assignment to "conn" declared in git_connect().
Which means the defaulting of git_connect::conn to &no_fork is now unneeded. One of the things that made the original cascade a bit harder to follow than necessary, aside from the physical length of the PROTO_GIT part, was that the case where conn remains to point at no_fork looked very special and it was buried in that long PROTO_GIT part. Now the main source of that issue is fixed, it would make it clear to leave conn uninitialized (or initialize to NULL---but leaving it uninitialized would make the intention of the code more clear, I would think, that each of the if/elseif/ cascade must assign to it).
Show 9 quoted lines
> printf("Diag: path=%s\n", path ? path : "NULL");
> conn = NULL;
> } else if (protocol == PROTO_GIT) {
> - struct strbuf request = STRBUF_INIT;
> -...
> + conn = git_connect_git(fd, hostandport, path, prog, flags);
> } else {
> struct strbuf cmd = STRBUF_INIT;
> const char *const *var;