Re: [PATCH v2 2/4] fetch: refactor `s_update_ref` to use common exit path

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

 



On Fri, Jan 08, 2021 at 03:50:00PM -0800, Junio C Hamano wrote:
> Patrick Steinhardt <ps@xxxxxx> writes:
[snip]
> >  	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

Attachment: signature.asc
Description: PGP signature


[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