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

Re: [PATCH 1/2] sha1_name: don't trigger detailed diagnosis for file arguments

From
Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Date
Jun 18, 2012, 17:42 UTC
Message-ID
<vpqpq8wpled.fsf@bauges.imag.fr>
In-Reply-To
<7vehpc4jpw.fsf@alter.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> writes:
Show 13 quoted lines
> I am not so sure about that.  The "only-to-die" caller is not even
> expecting that the call to this codepath would successfully return.
>
> Or at least, it shouldn't.
>
> So it might not be a bad idea to actually catch this as a
> programming error and do
>
> 	if (only_to_die) {
>         	if (!ret)
>                 	die("BUG");
> 		diagnose_invalid_sha1_path(...);
> 	}
I disagree.

The only-to-die caller can expect that get_sha1_with_context_1 never returns when called with only-to-die, but it's a stronger assumption to expect that this particular place will trigger the failure.

In this case, the assumption is correct because there's a "return ret;" a bit later in the code, but I don't think we should have to look at this to check the correctness of the code (for example, if something like "if (ret) try_some_fallback_method();" is later added before "return ret;", then the assumption would become false).

My version reads as
  try something;
  if (it failed && I'm only here to report an error)
          report_error();
which I find easier to understand.
-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Previous: Junio C HamanoNext: Junio C Hamano
Message 13 of 16 in “"Detailed diagnosis" perhaps broken”
  1. Junio C HamanoJun 15, 2012
  2. Matthieu MoyJun 17, 2012
  3. 1/2 sha1_name: don't trigger detailed diagnosis for file argumentsMatthieu Moy, Jun 17, 2012
  4. 2/2 verify_filename: ask the caller to chose the kind of diagnosisMatthieu Moy, Jun 17, 2012
  5. Junio C HamanoJun 17, 2012
  6. Matthieu MoyJun 18, 2012
  7. Junio C HamanoJun 18, 2012
  8. 1/2 sha1_name: don't trigger detailed diagnosis for file argumentsMatthieu Moy, Jun 18, 2012
  9. 2/2 verify_filename: ask the caller to chose the kind of diagnosisMatthieu Moy, Jun 18, 2012
  10. Junio C HamanoJun 18, 2012
  11. Matthieu MoyJun 19, 2012
  12. Junio C HamanoJun 18, 2012
  13. Matthieu MoyJun 18, 2012
  14. Junio C HamanoJun 18, 2012
  15. Matthieu MoyJun 18, 2012
  16. Junio C HamanoJun 18, 2012

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.