git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [RFC PATCH v6 3/3] git-remote-ext

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Oct 8, 2010, 22:02 UTC
Message-ID
<20101008220220.GA15214@burratino>
In-Reply-To
<1286571713-7755-4-git-send-email-ilari.liusvaara@elisanet.fi>
Ilari Liusvaara wrote:
> Signed-off-by: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>
Just a few random nits.
> +++ b/builtin/remote-ext.c
> @@ -0,0 +1,243 @@

[...] [...]

> +			default:
> +				die("Bad remote-ext placeholder '\\%c'.",
> +					str[rpos]);
Should be "Bad remote-ext placeholder '%%%c'.", I think.
Show 6 quoted lines
> +static const char **parse_argv(const char *arg, const char *service)
> +{
> +	int arguments = 0;
> +	int i;
> +	char **ret;
> +	char *(temparray[MAXARGUMENTS + 1]);
Would be more idiomatic to leave out the parentheses.
> +
> +	while (*arg) {
> +		char *ret;
Would be clearer without shadowing.  Maybe
		char *expanded;
[...]
Show 5 quoted lines
> +	ret = xcalloc(arguments + 1, sizeof(char *));
> +	for (i = 0; i < arguments; i++)
> +		ret[i] = temparray[i];
> +
> +	return (const char **)ret;
Maybe
	ret = xmalloc(...
	for (...
	ret[arguments] = NULL;
	return ret;
(to avoid clearing memory that is about to be overwritten) or even
	ret = xmalloc(...
	memcpy(ret, temparray, arguments * sizeof(*ret));
	ret[arguments] = NULL;
	return ret;
(to emphasize the copy) would make sense?

Why is ret of type char ** and then cast away rather than being const char ** in the first place?

Show 7 quoted lines
> +static int command_loop(const char *child)
> +{
> +	char buffer[MAXCOMMAND];
> +
> +	while (1) {
> +		if (!fgets(buffer, MAXCOMMAND - 1, stdin))
> +			exit(0);
Won't this exit(0) for I/O errors?
> +		/* Strip end of line characters. */
> +		while (isspace((unsigned char)buffer[strlen(buffer) - 1]))
> +			buffer[strlen(buffer) - 1] = 0;

This is wasteful: strlen() has to look for the null byte three times just to strip a \r\n from the end. See remote-fd for an example of how to avoid that overhead.

Previous: Ilari Liusvaara
Message 6 of 6 in “git-remote-fd & git-remote-ext”
  1. 0/3 git-remote-fd & git-remote-extIlari Liusvaara, Oct 8, 2010
  2. 1/3 Add bidirectional_transfer_loop()Ilari Liusvaara, Oct 8, 2010
  3. Junio C HamanoOct 12, 2010
  4. 2/3 git-remote-fdIlari Liusvaara, Oct 8, 2010
  5. 3/3 git-remote-extIlari Liusvaara, Oct 8, 2010
  6. Jonathan NiederOct 8, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.