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

Re: [PATCH 1/2] Make section_name_match start on '[', and return the length on success

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jul 25, 2009, 14:09 UTC
Message-ID
<alpine.DEB.1.00.0907251605240.8306@pacific.mpi-cbg.de>
In-Reply-To
<1248470504-16326-2-git-send-email-alex@chmrr.net>
Hi,
On Fri, 24 Jul 2009, Alex Vandiver wrote:
Show 11 quoted lines
> diff --git a/config.c b/config.c
> index 04380bb..7d6f6f6 100644
> --- a/config.c
> +++ b/config.c
> @@ -1194,7 +1194,9 @@ write_err_out:
>  static int section_name_match (const char *buf, const char *name)
>  {
>  	int i = 0, j = 0, dot = 0;
> -	for (; buf[i] && buf[i] != ']'; i++) {
> +	if (buf[i] != '[')
> +		return 0;

Is this not unnecessary, given that we only call that function when we know that buf[0] == '[':

Show 10 quoted lines
> @@ -1249,7 +1261,8 @@ int git_config_rename_section(const char *old_name, const char *new_name)
>  			; /* do nothing */
>  		if (buf[i] == '[') {
>  			/* it's a section */
> -			if (section_name_match (&buf[i+1], old_name)) {
> +			int offset = section_name_match (&buf[i], old_name);
> +			if (offset > 0) {
>  				ret++;
>  				if (new_name == NULL) {
>  					remove = 1;

I was a bit surprised that "offset" is not used further in your patch, but I saw that 2/2 uses it.

So except for the unnecessary test, I like your patches (read: ACK).

Ciao, Dscho

Previous: Johannes SchindelinNext: Alex Vandiver
Message 14 of 17 in “Section renaming can lose content”
  1. 0/2 Section renaming can lose contentAlex Vandiver, Jul 24, 2009
  2. 1/2 Make section_name_match start on '[', and return the length on successAlex Vandiver, Jul 24, 2009
  3. 2/2 After renaming a section, print any trailing variable definitionsAlex Vandiver, Jul 24, 2009
  4. Nanako ShiraishiJul 24, 2009
  5. Alex VandiverJul 24, 2009
  6. Make git config fail on variables with no section, as documentedAlex Vandiver, Jul 26, 2009
  7. Johannes SchindelinJul 26, 2009
  8. Alex VandiverJul 26, 2009
  9. Johannes SchindelinJul 26, 2009
  10. Alex VandiverJul 26, 2009
  11. Junio C HamanoJul 24, 2009
  12. (unknown)Nanako Shiraishi, Jul 25, 2009
  13. Johannes SchindelinJul 25, 2009
  14. Johannes SchindelinJul 25, 2009
  15. Alex VandiverJul 25, 2009
  16. Junio C HamanoJul 25, 2009
  17. Johannes SchindelinJul 25, 2009

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.