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

Re: [PATCH 1/2] Function stripspace now gets a buffer instead file descriptors.

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 11, 2007, 22:24 UTC
Message-ID
<7vd4yy1svw.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<4695267A.7080202@gmail.com>
Carlos Rica <jasampler@gmail.com> writes:
Show 10 quoted lines
> diff --git a/builtin-stripspace.c b/builtin-stripspace.c
> index d8358e2..949b640 100644
> --- a/builtin-stripspace.c
> +++ b/builtin-stripspace.c
> @@ -2,12 +2,11 @@
>  #include "cache.h"
>
>  /*
> - * Remove trailing spaces from a line.
> + * Returns the length of a line removing trailing spaces.

This did not parse well for me; perhaps a comma before "removing" would make it easier to read?

Show 6 quoted lines
> @@ -28,52 +26,67 @@ static int cleanup(char *line, int len)
>   * Remove empty lines from the beginning and end
>   * and also trailing spaces from every line.
>   *
> + * Note that the buffer will not be null-terminated.
> + *

The name of the sentinel character '\0' is NUL, not null (which is a different word, used to call a pointer that points nowhere). The buffer will not be "NUL-terminated".

Show 15 quoted lines
> -void stripspace(FILE *in, FILE *out, int skip_comments)
> +size_t stripspace(char *buffer, size_t length, int skip_comments)
>  {
> +		newlen = cleanup(buffer + i, len);
>
>  		/* Not just an empty line? */
> +		if (newlen) {
> +			if (empties != -1)
> +				buffer[j++] = '\n';
>  			if (empties > 0)
> +				buffer[j++] = '\n';
>  			empties = 0;
> +			memmove(buffer + j, buffer + i, newlen);
>  			continue;
>  		}
It somehow strikes me odd that, given this:
	buffer       j        i
        **********************texttext  \n.......
you would first do this with cleanup():
	buffer       j        i
        **********************texttext\n.......
and then do this with this memmove():
	buffer       j        i
        *************texttext\n.......

Would it become simpler if cleanup() knew where the final text goes (i.e. buffer+j)?

Show 10 quoted lines
>  int cmd_stripspace(int argc, const char **argv, const char *prefix)
>  {
> -	stripspace(stdin, stdout, 0);
> +	char *buffer;
> +	unsigned long size;
> +
> +	size = 1024;
> +	buffer = xmalloc(size);
> +	if (read_pipe(0, &buffer, &size))
> +		die("could not read the input");

The command used to be capable of streaming and filtering a few hundred gigabytes of text on a machine with small address space, as it operated one line at a time, but now it cannot as it has to hold everything in core before starting.

I do not think we miss that loss of capability too much, but I wonder if we can be a bit more clever about it, perhaps feeding a chunk at a time. Not a very strong request, but just wondering if it is an easy change.

Previous: Johannes SchindelinNext: Bill Lear
Message 3 of 7 in “Function stripspace now gets a buffer instead file descriptors.”
  1. 1/2 Function stripspace now gets a buffer instead file descriptors.Carlos Rica, Jul 11, 2007
  2. Johannes SchindelinJul 11, 2007
  3. Junio C HamanoJul 11, 2007
  4. Bill LearJul 11, 2007
  5. Carlos RicaJul 11, 2007
  6. Junio C HamanoJul 12, 2007
  7. Carlos RicaJul 12, 2007

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.