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

Re: [PATCH] interpret-trailers: add option for in-place editing

From
Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Date
Jan 6, 2016, 14:19 UTC
Message-ID
<vpqoacylri6.fsf@anie.imag.fr>
In-Reply-To
<1452087258-3893-1-git-send-email-tobias.klauser@zhinst.com>
Tobias Klauser <tobias.klauser@zhinst.com> writes:
> From: Tobias Klauser <tklauser@distanz.ch>
>
> Add a command line option --in-place to support in-place editing akin to
> sed -i.  This allows to write commands like the following:

Since -i is a common shortcut for --in-place (perl -i, sed -i), it probably makes sense to have it here too. OTOH, this is meant for scripting and perhaps it's best to force script writters to be verbose.

> Also add the corresponding documentation and tests.

This sentence does not harm, but I personnally don't think it's really helpfull, as it's already clear by the diffstat right below, and the patch itself.

Show 13 quoted lines
> -static void print_tok_val(const char *tok, const char *val)
> +static void print_tok_val(FILE *fp, const char *tok, const char *val)
>  {
>  	char c = last_non_space_char(tok);
>  	if (!c)
>  		return;
>  	if (strchr(separators, c))
> -		printf("%s%s\n", tok, val);
> +		fprintf(fp, "%s%s\n", tok, val);
>  	else
> -		printf("%s%c %s\n", tok, separators[0], val);
> +		fprintf(fp, "%s%c %s\n", tok, separators[0], val);
>  }

The patch would be even easier to read if split into a preparatory refactoring patch "turn printf into fprintf" and then the actual one. But it's already rather clear, so you can probably leave it as-is.

> -static void print_lines(struct strbuf **lines, int start, int end)
> +static void print_lines(FILE *fp, struct strbuf **lines, int start, int end)

Here and below: it would probably be more readable with a more explicit name for fp, like "outfile". Especially here:

> -static int process_input_file(struct strbuf **lines,
> +static int process_input_file(FILE *fp,
> +			      struct strbuf **lines,

Where it's tempting to think that a parameter given to process_input_file is ... the input file!

Other than these minor details, the patch looks good to me. Thanks for the patch!

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Previous: Tobias KlauserNext: Tobias Klauser
Message 2 of 5 in “interpret-trailers: add option for in-place editing”
  1. interpret-trailers: add option for in-place editingTobias Klauser, Jan 6, 2016
  2. Matthieu MoyJan 6, 2016
  3. Tobias KlauserJan 6, 2016
  4. Eric SunshineJan 6, 2016
  5. Tobias KlauserJan 7, 2016

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.