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

Re: [PATCH] Enable git rev-list to parse --quiet

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 20, 2008, 18:31 UTC
Message-ID
<7vwsjg76gl.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<20080720120437.GC15586@mail.local.tull.net>
Nick Andrew <nick@nick-andrew.net> writes:
> Exiting a process from within a callback function seems to me to violate
> the principle of least surprise.
Huh?  Who is surprised?

I do not know who taught you that "do not exit in a callback" dogma, but I suspect it was misrepresented when it was taught to you.

A library that calls your function back could be structured this way:
	lib() {
        	perform some set-up that affects external world;
                call your callback function;
                clean-up the effect of previous set-up action;
	}

and exiting from your callback function is not a good idea as it prevents the library from doing the necessary clean-up in such a case.

But that is true just in a(n extremely) general case. Your generalization is not particularly useful, methinks, and use of exit(0) in the patch is very well justified (rather, I do not think they even need justifying).

 - The callback you are looking at is not a general purpose callback for
   other program's use, but written for a specific use of rev-list;
 - The purpose of that exit(0) is to signal "there is something" as
   quickly as possible, which was what you wanted out of rev-list;
 - Revision traversal is a read-only operation and we know that there is
   no externally visible set-up done in the function you are calling to
   get your callback called, that needs cleaning up later --- this is not
   expected to change, as there are longstanding existing callback
   functions supplied to traverse_commit_list() that die() upon seeing
   errors already.
Previous: Nick Andrew
Message 8 of 8 in “Enable git rev-list to parse --quiet”
  1. Enable git rev-list to parse --quietNick Andrew, Jul 18, 2008
  2. Junio C HamanoJul 18, 2008
  3. Junio C HamanoJul 18, 2008
  4. Nick AndrewJul 18, 2008
  5. Johannes SchindelinJul 18, 2008
  6. Junio C HamanoJul 20, 2008
  7. Nick AndrewJul 20, 2008
  8. Junio C HamanoJul 20, 2008

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.