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

ref-filter: how to improve the code

From
Оля Тележная <olyatelezhnaya@gmail.com>
Date
Feb 25, 2018, 18:28 UTC
Message-ID
<CAL21Bmnz=H96EE=yerdigujYQ6M7Y_U-RkDF7oR-UPDU+cZNFA@mail.gmail.com>

Hi everyone, I am trying to remove cat-file formatting part and reuse same functionality from ref-filter. I have a problem that cat-file sometimes needs to continue running even if the request is broken, while in ref-filter we invoke die() in many places everywhere during formatting process. I write this email because I want to discuss how to implement the solution better.

ref-filter has 2 functions which could be interesting for us: format_ref_array_item() and show_ref_array_item(). I guess it's a good idea to print everything in show_ref_array_item(), including all errors. In that case all current users of ref-filter will invoke show_ref_array_item() (as they did it before), and cat-file could use format_ref_array_item() and work with the result in its own logic.

I tried to replace all die("...") with `return error("...")` and finally exit(), but actual problem is that we print "error:..." instead of "fatal:...", and it looks funny. The draft of the code is here: https://github.com/telezhnaya/git/commits/p2

One of the easiest solutions is to add strbuf parameter for errors to all functions that we use during formatting process, fill it in and print in show_ref_array_item() if necessary. What do you think about this idea?

Another way is to change the resulting error message, print current message with "error" prefix and then print something like "fatal: could not format the output". It is easier but I am not sure that it's a good idea to change the interface.

If you have another ideas - please share them with me. It is really important step to make formatting logic more general and easier to reuse.

Thanks! Olga

Next: Jeff King
Message 1 of 4 in “ref-filter: how to improve the code”
  1. Оля ТележнаяFeb 25, 2018
  2. Jeff KingFeb 28, 2018
  3. Оля ТележнаяMar 1, 2018
  4. Jeff KingMar 1, 2018

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.