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

Re: [PATCH 3/3] pretty=format: Avoid some expensive calculations when not needed

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 7, 2007, 20:43 UTC
Message-ID
<7vhcjxaire.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<4730F5FA.3030705@lsrfire.ath.cx>
René Scharfe <rene.scharfe@lsrfire.ath.cx> writes:
> I haven't seen any comments on strbuf_expand.  Is it too far out?
> Here it is again, adjusted for current master and with the changes
> to strbuf.[ch] coming first:
Numbers talk ;-).

In your previous round, you alluded that the strbuf_expand() interface could allow caching of the return value of fn(), but I do not think strbuf_expand() in this patch has anything to directly support that notion.

Nor I would expect to --- fn() could keep the really expensive information cached, keyed with context value, if it wanted to, but in practice for the purpose of format_commit_item() I do not offhand see anything cacheable and reusable, unless the user did stupid things (e.g. use more than one %h in the format string).

I added a few paragraphs to describe the API in the commit log message, and rewrote "# master" to "(master)" etc.

-- >8 -- pretty=format: Avoid some expensive calculations when not needed

This rewrites the custom format prettyprinter for commit objects by introducing a new strbuf API function "strbuf_expand()".

The function takes a format string, list of placeholder strings, a user supplied function 'fn', and an opaque pointer 'context' to tell 'fn' what thingy to operate on.

The function 'fn' is expected to accept a strbuf, a parsed placeholder string and the 'context' pointer, and append the interpolated value for the 'context' thingy, according to the format specified by the placeholder.

Here my measurements of most of Paul's test cases (best of three runs):

(master) $ time git log --pretty=oneline >/dev/null

...
Previous: Pierre HabouzitNext: René Scharfe
Message 20 of 24 in “Make user formatted commit listing less expensive”
  1. 0/3 Make user formatted commit listing less expensiveJohannes Schindelin, Nov 4, 2007
  2. 1/3 Split off the pretty print stuff into its own fileJohannes Schindelin, Nov 4, 2007
  3. Junio C HamanoNov 5, 2007
  4. 2/3 interpolate.[ch]: Add a function to find which interpolations are active.Johannes Schindelin, Nov 4, 2007
  5. 3/3 pretty=format: Avoid some expensive calculations when not neededJohannes Schindelin, Nov 4, 2007
  6. Junio C HamanoNov 5, 2007
  7. René ScharfeNov 5, 2007
  8. Jon LoeligerNov 5, 2007
  9. Johannes SchindelinNov 5, 2007
  10. Junio C HamanoNov 6, 2007
  11. René ScharfeNov 6, 2007
  12. René ScharfeNov 6, 2007
  13. Johannes SchindelinNov 6, 2007
  14. René ScharfeNov 7, 2007
  15. Johannes SchindelinNov 8, 2007
  16. Pierre HabouzitNov 7, 2007
  17. Pierre HabouzitNov 7, 2007
  18. René ScharfeNov 7, 2007
  19. Pierre HabouzitNov 7, 2007
  20. Junio C HamanoNov 7, 2007
  21. René ScharfeNov 9, 2007
  22. Johannes SchindelinNov 6, 2007
  23. 1/2 interpolate.[ch]: Add a function to find which interpolations are active.Johannes Schindelin, Nov 6, 2007
  24. 2/2 pretty=format: Avoid some expensive calculations when not neededJohannes Schindelin, Nov 6, 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.