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

Re: [SUPERSEDES PATCH 2/7] nfv?asprintf are broken without va_copy, workaround them.

From
Pierre Habouzit <madcoder@debian.org>
Date
Sep 21, 2007, 07:02 UTC
Message-ID
<20070921070215.GA5689@artemis.corp>
In-Reply-To
<7vejgsk0ev.fsf@gitster.siamese.dyndns.org>
On Fri, Sep 21, 2007 at 06:17:12AM +0000, Junio C Hamano wrote:
Show 53 quoted lines
> Pierre Habouzit <madcoder@debian.org> writes:
> 
> > This reinstates the trace_argv_printf API. The implementation is
> > stupid, but is rewritten in a latter commit. I didn't wanted to bother
> > optimizing it.
> > ...
> >  cache.h           |    2 -
> >  imap-send.c       |   13 ++++++++
> >  merge-recursive.c |   74 ++++++++++++++++++++-----------------------
> >  trace.c           |   90 ++++++++++++++++-------------------------------------
> >  4 files changed, 74 insertions(+), 105 deletions(-)
> > ...
> > diff --git a/merge-recursive.c b/merge-recursive.c
> > index 14b56c2..4e27549 100644
> > --- a/merge-recursive.c
> > +++ b/merge-recursive.c
> > @@ -85,63 +85,57 @@ struct stage_data
> > +static void flush_output(void)
> >  {
> > +	if (obuf.len) {
> > +		fputs(obuf.buf, stdout);
> > +		strbuf_reset(&obuf);
> >  	}
> >  }
> 
> This assumes obuf.buf has necessary indentations and line
> breaks, which is sensible.  However...
> 
> > +static void output(int v, const char *fmt, ...)
> >  {
> > +	if (show(v)) {
> > +		int len;
> > +		va_list ap;
> 
> Yuck, this single if statement covers the entirety of the
> function.  Let's do
> 
> 	if (!show(v))
> 	        return;
> 
> > +		strbuf_grow(&obuf, call_depth);
> > +		memset(obuf.buf + obuf.len, ' ', call_depth);
> > +		strbuf_setlen(&obuf, obuf.len + call_depth);
> 
> Per depth indentation used to be two whitespaces.
> 
> > +		va_start(ap, fmt);
> > +		len = vsnprintf(obuf.buf, strbuf_avail(&obuf) + 1, fmt, ap);
> > +		va_end(ap);
> 
> And you overwrite whatever used to be in the buffer, including
> the previous buffered message and indentation you added.  Not
> nice...
  ooops, I wrote it too quickly.
> I'll squash this on top of yours for now.
  works for me except the little remark in the end :)
>  merge-recursive.c |   45 +++++++++++++++++++++++----------------------
>  1 files changed, 23 insertions(+), 22 deletions(-)
> 
> +	strbuf_setlen(&obuf, obuf.len + len);
> +	strbuf_add(&obuf, "\n", 1);
  rather use strbuf_addch(&obuf, '\n')
Show 9 quoted lines
> +	if (!buffer_output)
> +		flush_output();
>  }
>  
>  static void output_commit_title(struct commit *commit)
> -
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
-- 
·O·  Pierre Habouzit
··O                                                madcoder@debian.org
OOO                                                http://www.madism.org
Previous: Junio C HamanoNext: Pierre Habouzit
Message 7 of 11 in “quote/strbuf series, take 3”
  1. Pierre HabouzitSep 19, 2007
  2. Junio C HamanoSep 20, 2007
  3. Christian CouderSep 20, 2007
  4. Pierre HabouzitSep 20, 2007
  5. 2/7 nfv?asprintf are broken without va_copy, workaround them.Pierre Habouzit, Sep 20, 2007
  6. Junio C HamanoSep 21, 2007
  7. Pierre HabouzitSep 21, 2007
  8. 4/7 sq_quote_argv and add_to_string rework with strbuf's.Pierre Habouzit, Sep 20, 2007
  9. Pierre HabouzitSep 20, 2007
  10. Pierre HabouzitSep 21, 2007
  11. 7/7 Pierre Habouzit, Sep 21, 2007

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.