[PATCH v4 26/28] reftable: fixup for new base topic 1/3

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Lifted from Han-Wen's [1], with the addition of the removal of the
reftable_error_to_errno() which is now unused. I also changed the:

    if err < 0
    if err > 1

to just:

    if err < 0
    else if err

Which is clearer in this context, i.e. the reader doesn't need to
squint to see that the two if's are related, but different only in "<"
v.s. ">".

1. https://lore.kernel.org/git/pull.1054.v3.git.git.1629207607.gitgitgadget@xxxxxxxxx/

Signed-off-by: Han-Wen Nienhuys <hanwen@xxxxxxxxxx>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@xxxxxxxxx>
---
 refs/reftable-backend.c | 38 ++++++++------------------------------
 1 file changed, 8 insertions(+), 30 deletions(-)

diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c
index d972910bf21..dcc792e5e87 100644
--- a/refs/reftable-backend.c
+++ b/refs/reftable-backend.c
@@ -108,7 +108,7 @@ static const char *bare_ref_name(const char *ref)
 static int git_reftable_read_raw_ref(struct ref_store *ref_store,
 				     const char *refname, struct object_id *oid,
 				     struct strbuf *referent,
-				     unsigned int *type);
+				     unsigned int *type, int *failure_errno);
 
 static void clear_reftable_log_record(struct reftable_log_record *log)
 {
@@ -424,6 +424,7 @@ static int fixup_symrefs(struct ref_store *ref_store,
 	struct strbuf referent = STRBUF_INIT;
 	int i = 0;
 	int err = 0;
+	int failure_errno;
 
 	for (i = 0; i < transaction->nr; i++) {
 		struct ref_update *update = transaction->updates[i];
@@ -433,8 +434,8 @@ static int fixup_symrefs(struct ref_store *ref_store,
 						&old_oid, &referent,
 						/* mutate input, like
 						   files-backend.c */
-						&update->type);
-		if (err < 0 && errno == ENOENT &&
+						&update->type, &failure_errno);
+		if (err < 0 && failure_errno == ENOENT &&
 		    is_null_oid(&update->old_oid)) {
 			err = 0;
 		}
@@ -1587,30 +1588,10 @@ git_reftable_reflog_expire(struct ref_store *ref_store, const char *refname,
 	return err;
 }
 
-static int reftable_error_to_errno(int err)
-{
-	switch (err) {
-	case REFTABLE_IO_ERROR:
-		return EIO;
-	case REFTABLE_FORMAT_ERROR:
-		return EFAULT;
-	case REFTABLE_NOT_EXIST_ERROR:
-		return ENOENT;
-	case REFTABLE_LOCK_ERROR:
-		return EBUSY;
-	case REFTABLE_API_ERROR:
-		return EINVAL;
-	case REFTABLE_ZLIB_ERROR:
-		return EDOM;
-	default:
-		return ERANGE;
-	}
-}
-
 static int git_reftable_read_raw_ref(struct ref_store *ref_store,
 				     const char *refname, struct object_id *oid,
 				     struct strbuf *referent,
-				     unsigned int *type)
+				     unsigned int *type, int *failure_errno)
 {
 	struct git_reftable_ref_store *refs =
 		(struct git_reftable_ref_store *)ref_store;
@@ -1633,13 +1614,10 @@ static int git_reftable_read_raw_ref(struct ref_store *ref_store,
 	}
 
 	err = reftable_stack_read_ref(stack, refname, &ref);
-	if (err > 0) {
-		errno = ENOENT;
-		err = -1;
-		goto done;
-	}
 	if (err < 0) {
-		errno = reftable_error_to_errno(err);
+		goto done;
+	} else if (err) {
+		*failure_errno = ENOENT;
 		err = -1;
 		goto done;
 	}
-- 
2.33.0.662.gbaddc25a55e





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux