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

Re: [PATCH v8 03/12] Move lower case functions into wrapper.c

From
Christian Couder <chriscool@tuxfamily.org>
Date
Mar 27, 2014, 07:47 UTC
Message-ID
<20140327.084745.2069840957131666658.chriscool@tuxfamily.org>
In-Reply-To
<xmqqppl8ftjd.fsf@gitster.dls.corp.google.com>
From: Junio C Hamano <gitster@pobox.com>
Show 42 quoted lines
>
> Christian Couder <chriscool@tuxfamily.org> writes:
> 
>> diff --git a/wrapper.c b/wrapper.c
>> index 0cc5636..c46026a 100644
>> --- a/wrapper.c
>> +++ b/wrapper.c
>> @@ -455,3 +455,17 @@ struct passwd *xgetpwuid_self(void)
>>  		    errno ? strerror(errno) : _("no such user"));
>>  	return pw;
>>  }
>> +
>> +void lowercase(char *p)
>> +{
>> +	for (; *p; p++)
>> +		*p = tolower(*p);
>> +}
>> +
>> +char *xstrdup_tolower(const char *str)
>> +{
>> +	char *dup = xstrdup(str);
>> +	lowercase(dup);
>> +	return dup;
>> +}
>> +
> 
> As a pure code-movement step, this may be OK, but I am not sure if
> both of them want to be public functions in this shape.
> 
> Perhaps
> 
> char *downcase_copy(const char *str)
> {
> 	char *copy = xmalloc(strlen(str) + 1);
>         int i;
>         for (i = 0; str[i]; i++)
>         	copy[i] = tolower(str[i]);
> 	copy[i] = '\0';
>         return copy;
> }
> 
> may avoid having to copy things twice.

Yeah, but it seems a bit wasteful to allocate memory for a new string, then downcase it, then compare it with strcmp() and then free it, instead of just using strcasecmp() on the original string.

> Do you need the other
> function exposed?
No, with the change you suggest, I don't.

Thanks, Christian.

Previous: Junio C HamanoNext: Junio C Hamano
Message 8 of 27 in “Add interpret-trailers builtin”
  1. 00/12 Add interpret-trailers builtinChristian Couder, Mar 26, 2014
  2. 01/12 Add data structures and basic functions for commit trailersChristian Couder, Mar 26, 2014
  3. Junio C HamanoMar 26, 2014
  4. Christian CouderMar 27, 2014
  5. 02/12 trailer: process trailers from stdin and argumentsChristian Couder, Mar 26, 2014
  6. 03/12 Move lower case functions into wrapper.cChristian Couder, Mar 26, 2014
  7. Junio C HamanoMar 26, 2014
  8. Christian CouderMar 27, 2014
  9. Junio C HamanoMar 27, 2014
  10. Junio C HamanoMar 27, 2014
  11. Jeff KingMar 27, 2014
  12. Junio C HamanoMar 27, 2014
  13. Jeff KingMar 27, 2014
  14. Junio C HamanoMar 28, 2014
  15. Jeff KingMar 28, 2014
  16. Christian CouderMar 28, 2014
  17. 04/12 trailer: read and process config informationChristian Couder, Mar 26, 2014
  18. 05/12 trailer: process command line trailer argumentsChristian Couder, Mar 26, 2014
  19. 06/12 trailer: parse trailers from stdinChristian Couder, Mar 26, 2014
  20. 07/12 trailer: put all the processing together and printChristian Couder, Mar 26, 2014
  21. 08/12 trailer: add interpret-trailers commandChristian Couder, Mar 26, 2014
  22. 09/12 trailer: add tests for "git interpret-trailers"Christian Couder, Mar 26, 2014
  23. 10/12 trailer: execute command from 'trailer.<name>.command'Christian Couder, Mar 26, 2014
  24. 11/12 trailer: add tests for commands in config fileChristian Couder, Mar 26, 2014
  25. 12/12 Documentation: add documentation for 'git interpret-trailers'Christian Couder, Mar 26, 2014
  26. Junio C HamanoMar 26, 2014
  27. Christian CouderMar 27, 2014

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.