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

Re: [PATCH v3 1/2] add strbuf_set operations

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 12, 2014, 18:51 UTC
Message-ID
<xmqqmwdi55co.fsf@gitster.dls.corp.google.com>
In-Reply-To
<20140612082218.GA5419@hudson.localdomain>
Jeremiah Mahler <jmmahler@gmail.com> writes:
Show 5 quoted lines
> Thomas,
>
> On Thu, Jun 12, 2014 at 10:11:36AM +0200, Thomas Braun wrote:
>> Am 12.06.2014 09:29, schrieb Jeremiah Mahler:
>> > A common use case with strubfs is to set the buffer to a new value.
strubfs???
Show 35 quoted lines
>> > This must be done in two steps: a reset followed by an add.
>> > 
>> >   strbuf_reset(buf);
>> >   strbuf_add(buf, new_buf, len);
>> > 
>> > In cases where the buffer is being built up in steps, these operations
>> > make sense and correctly convey what is being performed.
>> > 
>> >   strbuf_reset(buf);
>> >   strbuf_add(buf, data1, len1);
>> >   strbuf_add(buf, data2, len2);
>> >   strbuf_add(buf, data3, len3);
>> > 
>> > However, in other cases, it can be confusing and is not very concise.
>> > 
>> >   strbuf_reset(buf);
>> >   strbuf_add(buf, default, len1);
>> > 
>> >   if (cond1) {
>> >     strbuf_reset(buf);
>> >     strbuf_add(buf, data2, len2);
>> >   }
>> > 
>> >   if (cond2) {
>> >     strbuf_reset(buf);
>> >     strbuf_add(buf, data3, len3);
>> >   }
>> > 
>> > Add strbuf_set operations so that it can be re-written in a clear and
>> > concise way.
>> > 
>> >   strbuf_set(buf, default len1);
>> very minor nit: missing comma between default and len1.
>
> I can't believe I missed that.  Good catch ;-)
Previous: Jeremiah MahlerNext: Jeremiah Mahler
Message 5 of 16 in “add strbuf_set operations”
  1. 0/2 add strbuf_set operationsJeremiah Mahler, Jun 12, 2014
  2. 1/2 add strbuf_set operationsJeremiah Mahler, Jun 12, 2014
  3. Thomas BraunJun 12, 2014
  4. Jeremiah MahlerJun 12, 2014
  5. Junio C HamanoJun 12, 2014
  6. Jeremiah MahlerJun 12, 2014
  7. Eric SunshineJun 12, 2014
  8. Jeremiah MahlerJun 12, 2014
  9. Junio C HamanoJun 12, 2014
  10. Jeremiah MahlerJun 12, 2014
  11. Eric SunshineJun 12, 2014
  12. Jeremiah MahlerJun 12, 2014
  13. Jeff KingJun 13, 2014
  14. Jeremiah MahlerJun 14, 2014
  15. 2/2 builtin/remote: improve readability via strbuf_set()Jeremiah Mahler, Jun 12, 2014
  16. Eric SunshineJun 12, 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.