diff mbox series

[v2,4/8] refs: make errno output explicit for refs_resolve_ref_unsafe

Message ID 11b2184044d766183edf5ee1888f38945e8a7fd1.1623329869.git.gitgitgadget@gmail.com (mailing list archive)
State Superseded
Headers show
Series refs: cleanup errno sideband ref related functions | expand

Commit Message

Han-Wen Nienhuys June 10, 2021, 12:57 p.m. UTC
From: Han-Wen Nienhuys <hanwen@google.com>

This introduces refs_resolve_ref_unsafe_with_errno(), which makes the API
contract for the errno output explicit. The implementation still relies on
the global errno variable to ensure no side effects of this refactoring.

In a follow-on commits, we will

* migrate callers that need this error information

* clear errno in refs_resolve_ref_unsafe() to make sure these other callers
aren't using the error output accidentally.

Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
Reviewed-by: Jonathan Tan <jonathantanmy@google.com>
---
 refs.c               | 12 ++++++++++++
 refs/refs-internal.h |  8 ++++++++
 2 files changed, 20 insertions(+)

Comments

Ævar Arnfjörð Bjarmason July 1, 2021, 11:56 a.m. UTC | #1
On Thu, Jun 10 2021, Han-Wen Nienhuys via GitGitGadget wrote:

> From: Han-Wen Nienhuys <hanwen@google.com>
>
> This introduces refs_resolve_ref_unsafe_with_errno(), which makes the API
> contract for the errno output explicit. The implementation still relies on
> the global errno variable to ensure no side effects of this refactoring.
>
> In a follow-on commits, we will
>
> * migrate callers that need this error information
>
> * clear errno in refs_resolve_ref_unsafe() to make sure these other callers
> aren't using the error output accidentally.
>
> Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
> Reviewed-by: Jonathan Tan <jonathantanmy@google.com>
> ---
>  refs.c               | 12 ++++++++++++
>  refs/refs-internal.h |  8 ++++++++
>  2 files changed, 20 insertions(+)
>
> diff --git a/refs.c b/refs.c
> index bebe3f584da7..64e2d55adcfb 100644
> --- a/refs.c
> +++ b/refs.c
> @@ -1781,6 +1781,18 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
>  	return NULL;
>  }
>  
> +const char *refs_resolve_ref_unsafe_with_errno(struct ref_store *refs,
> +					       const char *refname,
> +					       int resolve_flags,
> +					       struct object_id *oid,
> +					       int *flags, int *failure_errno)
> +{
> +	const char *result = refs_resolve_ref_unsafe(refs, refname,
> +						     resolve_flags, oid, flags);
> +	*failure_errno = errno;
> +	return result;
> +}
> +
>  /* backend functions */
>  int refs_init_db(struct strbuf *err)
>  {
> diff --git a/refs/refs-internal.h b/refs/refs-internal.h
> index 904b2a9e51ae..eb97023658f8 100644
> --- a/refs/refs-internal.h
> +++ b/refs/refs-internal.h
> @@ -153,6 +153,14 @@ int refs_read_raw_ref(struct ref_store *ref_store,
>  		      const char *refname, struct object_id *oid,
>  		      struct strbuf *referent, unsigned int *type);
>  
> +/* Like refs_resolve_ref_unsafe, but provide access to errno code that lead to a
> + * failure. */
> +const char *refs_resolve_ref_unsafe_with_errno(struct ref_store *refs,
> +					       const char *refname,
> +					       int resolve_flags,
> +					       struct object_id *oid,
> +					       int *flags, int *failure_errno);
> +
>  /*
>   * Write an error to `err` and return a nonzero value iff the same
>   * refname appears multiple times in `refnames`. `refnames` must be

Okey, this might be eligable for comments similar to what I've had so
far, but no callers yet. Let's read on to those commits, right now I'm
thinking "this looks small enough that it should be squashed into that
future commit"....
diff mbox series

Patch

diff --git a/refs.c b/refs.c
index bebe3f584da7..64e2d55adcfb 100644
--- a/refs.c
+++ b/refs.c
@@ -1781,6 +1781,18 @@  const char *refs_resolve_ref_unsafe(struct ref_store *refs,
 	return NULL;
 }
 
+const char *refs_resolve_ref_unsafe_with_errno(struct ref_store *refs,
+					       const char *refname,
+					       int resolve_flags,
+					       struct object_id *oid,
+					       int *flags, int *failure_errno)
+{
+	const char *result = refs_resolve_ref_unsafe(refs, refname,
+						     resolve_flags, oid, flags);
+	*failure_errno = errno;
+	return result;
+}
+
 /* backend functions */
 int refs_init_db(struct strbuf *err)
 {
diff --git a/refs/refs-internal.h b/refs/refs-internal.h
index 904b2a9e51ae..eb97023658f8 100644
--- a/refs/refs-internal.h
+++ b/refs/refs-internal.h
@@ -153,6 +153,14 @@  int refs_read_raw_ref(struct ref_store *ref_store,
 		      const char *refname, struct object_id *oid,
 		      struct strbuf *referent, unsigned int *type);
 
+/* Like refs_resolve_ref_unsafe, but provide access to errno code that lead to a
+ * failure. */
+const char *refs_resolve_ref_unsafe_with_errno(struct ref_store *refs,
+					       const char *refname,
+					       int resolve_flags,
+					       struct object_id *oid,
+					       int *flags, int *failure_errno);
+
 /*
  * Write an error to `err` and return a nonzero value iff the same
  * refname appears multiple times in `refnames`. `refnames` must be