Subject: Re: [PATCH v5 1/4] object-name: make get_oid quietly return an error

From: Junio C Hamano <[email-masked]>
Date: Thu, 08 May 2025 18:55:23 -0700

"brian m. carlson" <[email-masked]> writes:

> diff --git a/object-name.c b/object-name.c
> index 2c751a5352..3138103343 100644
> --- a/object-name.c
> +++ b/object-name.c
> @@ -1081,13 +1081,17 @@ static int get_oid_basic(struct repository *r, const char *str, int len,
>  				 * still fill in the oid with the "old" value,
>  				 * which we can use.
>  				 */
> -			} else {
> +			} else if (!(flags & GET_OID_GENTLY)) {
>  				if (flags & GET_OID_QUIETLY) {
>  					exit(128);
>  				}
>  				die(_("log for '%.*s' only has %d entries"),
>  				    len, str, co_cnt);
>  			}
> +			if (flags & GET_OID_GENTLY) {
> +				free(real_ref);
> +				return -1;
> +			}
>  		}
>  	}
>  

Almost everybody else in this function hits "return -1" after
detecting that it cannot yield a valid object name, and this change
makes the oddball case do the same.

Ideally in a distant past, we might want to remove this _GENTLY
flag, together with the code path that is not so gentle, and adjust
the callers that depend on the current behaviour (which I somehow
doubt--- they need to be prepared to deal with the error return from
other parts of the same function already).  We might need to make it
possible for callers to tell which error condition we got (e.g., did
the input give it a non-existing ref?  did reflog walk run out?),
but these (including to the change to just lose "die" and always go
the GENTLY code path) are totally outside the scope of this series.

Thanks.