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

Re: [PATCH v3 1/3] refs API: use "failure_errno", not "errno"

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 12, 2022, 19:59 UTC
Message-ID
<xmqqh7a8u3my.fsf@gitster.g>
In-Reply-To
<patch-v3-1.3-a45268ac24b-20220112T123117Z-avarab@gmail.com>
Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
Show 6 quoted lines
> @@ -1722,8 +1722,6 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
>  		if (refs_read_raw_ref(refs, refname, oid, &sb_refname,
>  				      &read_flags, failure_errno)) {
>  			*flags |= read_flags;
> -			if (errno)
> -				*failure_errno = errno;
Looks good.  

The whole point of passing failure_errno down to refs_read_raw_ref() is that we capture the reason of the failure there without having to rely on errno at this point in the flow. Removal of this assignment makes perfect sense.

But ...
Show 27 quoted lines
> diff --git a/refs/files-backend.c b/refs/files-backend.c
> index b529fdf237e..43a3b882d7c 100644
> --- a/refs/files-backend.c
> +++ b/refs/files-backend.c
> @@ -382,7 +382,6 @@ static int files_read_raw_ref(struct ref_store *ref_store, const char *refname,
>  	if (lstat(path, &st) < 0) {
>  		int ignore_errno;
>  		myerr = errno;
> -		errno = 0;
>  		if (myerr != ENOENT)
>  			goto out;
>  		if (refs_read_raw_ref(refs->packed_ref_store, refname, oid,
> @@ -399,7 +398,6 @@ static int files_read_raw_ref(struct ref_store *ref_store, const char *refname,
>  		strbuf_reset(&sb_contents);
>  		if (strbuf_readlink(&sb_contents, path, st.st_size) < 0) {
>  			myerr = errno;
> -			errno = 0;
>  			if (myerr == ENOENT || myerr == EINVAL)
>  				/* inconsistent with lstat; retry */
>  				goto stat_ref;
> @@ -469,6 +467,7 @@ static int files_read_raw_ref(struct ref_store *ref_store, const char *refname,
>  
>  	strbuf_release(&sb_path);
>  	strbuf_release(&sb_contents);
> +	errno = 0;
>  	return ret;
>  }

... it is not clear to me if this part makes sense. If everybody above the callstack uses failure_errno as the source of truth, clearing errno here in this function should not be necessary and is misleading to readers of the code, no?

Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 15 of 28 in “errno oversight”
  1. Han-Wen NienhuysDec 8, 2021
  2. Ævar Arnfjörð BjarmasonDec 8, 2021
  3. Ævar Arnfjörð BjarmasonDec 8, 2021
  4. Junio C HamanoDec 8, 2021
  5. 0/3 refs: ab/refs-errno-cleanup fixup + remove "failure_errno"Ævar Arnfjörð Bjarmason, Dec 9, 2021
  6. 1/3 refs API: use "failure_errno", not "errno"Ævar Arnfjörð Bjarmason, Dec 9, 2021
  7. 2/3 sequencer: don't use die_errno() on refs_resolve_ref_unsafe() failureÆvar Arnfjörð Bjarmason, Dec 9, 2021
  8. 3/3 refs API: remove "failure_errno" from refs_resolve_ref_unsafe()Ævar Arnfjörð Bjarmason, Dec 9, 2021
  9. 0/3 refs: ab/refs-errno-cleanup fixup + remove "failure_errno"Ævar Arnfjörð Bjarmason, Dec 12, 2021
  10. 1/3 refs API: use "failure_errno", not "errno"Ævar Arnfjörð Bjarmason, Dec 12, 2021
  11. 2/3 sequencer: don't use die_errno() on refs_resolve_ref_unsafe() failureÆvar Arnfjörð Bjarmason, Dec 12, 2021
  12. 3/3 refs API: remove "failure_errno" from refs_resolve_ref_unsafe()Ævar Arnfjörð Bjarmason, Dec 12, 2021
  13. 0/3 For v2.35.0: refs: ab/refs-errno-cleanup fixup + remove "failure_errno"Ævar Arnfjörð Bjarmason, Jan 12, 2022
  14. 1/3 refs API: use "failure_errno", not "errno"Ævar Arnfjörð Bjarmason, Jan 12, 2022
  15. Junio C HamanoJan 12, 2022
  16. Ævar Arnfjörð BjarmasonJan 13, 2022
  17. 2/3 sequencer: don't use die_errno() on refs_resolve_ref_unsafe() failureÆvar Arnfjörð Bjarmason, Jan 12, 2022
  18. Junio C HamanoJan 12, 2022
  19. 3/3 refs API: remove "failure_errno" from refs_resolve_ref_unsafe()Ævar Arnfjörð Bjarmason, Jan 12, 2022
  20. Junio C HamanoJan 12, 2022
  21. Ævar Arnfjörð BjarmasonJan 13, 2022
  22. Junio C HamanoJan 13, 2022
  23. Ævar Arnfjörð BjarmasonJan 14, 2022
  24. 0/2 refs: remove the last use of "errno" from the public APIÆvar Arnfjörð Bjarmason, Jan 26, 2022
  25. 1/2 sequencer: don't use die_errno() on refs_resolve_ref_unsafe() failureÆvar Arnfjörð Bjarmason, Jan 26, 2022
  26. Junio C HamanoJan 26, 2022
  27. 2/2 refs API: remove "failure_errno" from refs_resolve_ref_unsafe()Ævar Arnfjörð Bjarmason, Jan 26, 2022
  28. Han-Wen NienhuysDec 8, 2021

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.