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