Re: [PATCH/RFD] fix connection via git protocol
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Apr 18, 2023, 20:47 UTC
- Message-ID
- <xmqqa5z4dijd.fsf@gitster.g>
- In-Reply-To
- <20230418033904.GA60552@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 14 quoted lines
> All of that makes me wonder if we wouldn't be just as happy with it as a > string in the first place. In three out of four locations that use it, > they want the string anyway (to feed to getaddrinfo). And in the final > one (git-daemon), we need to convert from the user's "--port" anyway, so > there's always some string-to-int parsing. And depending on the #ifdefs, > in most cases we turn it back into a string anyway to feed to...you > guessed it, getaddrinfo! > > The exception is when NO_IPV6 is defined, in which we do want the > numeric value. But we could delay parsing until that point (and > otherwise let getaddrinfo handle, which seems more correct anyway). > > Something like this (though I'd probably split it into a few patches to > reason about the motivation and implications of each):
The updated code keeps the "port" as a string and turns it into a short integer only when it is needed, which is nice. In the future, parse_port() may even want to be extended to call something like getservbyname(), to allow something silly like
#define DEFAULT_GIT_PORT "git"