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

Re: [PATCH] Teach git log --check to return an appropriate error code

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 9, 2008, 19:29 UTC
Message-ID
<7v8wv66l8d.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<alpine.DEB.1.00.0808091404230.24820@pacific.mpi-cbg.de.mpi-cbg.de>
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
Show 7 quoted lines
> On Sat, 9 Aug 2008, Peter Valdemar Mørch wrote:
>
>> 	Whether or not a check fails is stored in the
>> 	DIFF_OPT_CHECK_FAILED field of flags in struct diff_options.
>> 	This flag-field is only set (diff.c:1644), never cleared.
>
> That is a side effect.  How wise is it to rely on that?
Hmm, good point.

The bit will never be cleared during a single diff run by design, because it needs to be cumulative in order to check a patch that describes changes to multiple paths --- iow, the API sequence is (1) the caller to the diff machinery resets the bit to zero and then (2) the caller exercises the diff machinery and expects the machinery to set the bit if even a single failure is detected, or leaves it unset if there is none.

So unless you (log_tree_diff(), the caller of diff machinery), decide to explicitly reset the bit (or decide to use a freshly allocated and initialized diff_options for each commit it feeds diff_tree_sha1()), the assumption would hold. We need to see how plausible it would be for us to break that assumption in the future.

Future versions of log_tree_diff() may want to tweak opt->diffopt per commit, when we have options for "use larger -U<lines> value after hitting this commit", or "use this pathspec to limit the diff output after hitting this commit", for example. But even in these cases, I think it is implausible to start from a freshly initialized diff_options structure. The code most likely would start from the copy of what was in use and update only the necessary fields, without disturbing the state variables.

So I think you are worried a bit too much in this case, even though it is a valid concern in principle. It might warrant a comment somewhere inside log_tree_diff() to tell people not to re-initialize opt->diffopt per commit without thinking, though.

One interesting option that might be interesting to add to the log family would be to show only commits that fail the checkdiff tests. I suspect necessary change for doing so would go to log_tree_diff() codepath.

Previous: Johannes SchindelinNext: Peter Valdemar Mørch (Lists)
Message 10 of 18 in “git diff/log --check exitcode and PAGER environment variable”
  1. Peter Valdemar Mørch (Lists)Aug 8, 2008
  2. Junio C HamanoAug 8, 2008
  3. Peter Valdemar Mørch (Lists)Aug 8, 2008
  4. Re* git diff/log --check exitcode and PAGER environment variableJunio C Hamano, Aug 8, 2008
  5. Peter Valdemar Mørch (Lists)Aug 8, 2008
  6. Johannes SchindelinAug 8, 2008
  7. Junio C HamanoAug 8, 2008
  8. Teach git log --check to return an appropriate error codePeter Valdemar Mørch, Aug 9, 2008
  9. Johannes SchindelinAug 9, 2008
  10. Junio C HamanoAug 9, 2008
  11. Peter Valdemar Mørch (Lists)Aug 10, 2008
  12. Junio C HamanoAug 10, 2008
  13. Junio C HamanoAug 9, 2008
  14. PATCH v2 0/2 Trying patch againPeter Valdemar Mørch, Aug 11, 2008
  15. 1/2 Teach git log --check to return an appropriate exit codePeter Valdemar Mørch, Aug 11, 2008
  16. 2/2 Teach git log --exit-code to return an appropriate exit codePeter Valdemar Mørch, Aug 11, 2008
  17. Jeff KingAug 8, 2008
  18. Jeff KingAug 8, 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.