Re: [PATCH v2 2/4] fetch: refactor `s_update_ref` to use common exit path
On Fri, Jan 08, 2021 at 03:50:00PM -0800, Junio C Hamano wrote:
> Patrick Steinhardt <ps@pks.im> writes:
Show 30 quoted lines
> > ret = ref_transaction_commit(transaction, &err);
> > if (ret) {
> > - df_conflict = (ret == TRANSACTION_NAME_CONFLICT);
> > - goto fail;
> > + ret = (ret == TRANSACTION_NAME_CONFLICT) ? STORE_REF_ERROR_DF_CONFLICT
> > + : STORE_REF_ERROR_OTHER;
> > + goto out;
> > }
> >
> > +out:
> > ref_transaction_free(transaction);
>
> It is a bit funny to see a goto that jumps to the label without
> having anything else in between, but we know we will be adding more
> code just before the "out:" label, so it is a good preliminary
> preparation.
>
> I think a variant that is much easier to follow would be to write
> like this instead:
>
> switch (ref_transaction_commit(transaction, &err)) {
> case 0: /* happy */
> break;
> case TRANSACTION_NAME_CONFLICT:
> ret = STORE_REF_ERROR_DF_CONFLICT;
> goto out;
> default:
> ret = STORE_REF_ERROR_OTHER;
> goto out;
> }Agreed, that is easier to read. Thanks!
Patrick