Subject: Re: [PATCH v7 04/17] ref-filter: modify "%(objectname:short)" to take length

From: Junio C Hamano <[email-masked]>
Date: Thu, 10 Nov 2016 15:32:14 -0800

Karthik Nayak <[email-masked]> writes:

>  	else if (!strcmp(arg, "short"))
> -		atom->u.objectname = O_SHORT;
> -	else
> +		atom->u.objectname.option = O_SHORT;
> +	else if (skip_prefix(arg, "short=", &arg)) {
> +		atom->u.objectname.option = O_LENGTH;
> +		if (strtoul_ui(arg, 10, &atom->u.objectname.length) ||
> +		    atom->u.objectname.length == 0)
> +			die(_("positive value expected objectname:short=%s"), arg);
> +		if (atom->u.objectname.length < MINIMUM_ABBREV)
> +			atom->u.objectname.length = MINIMUM_ABBREV;
> +	} else
>  		die(_("unrecognized %%(objectname) argument: %s"), arg);
>  }

Users who want to use the default-abbrev, i.e. the autoscaling one
introduced recently, must use "short", not "short=-1", with this
code (especially with the "must be at least MINIMUM_ABBREV" logic),
but I do not think it is a problem, so I think this is good.

> @@ -591,12 +601,15 @@ static int grab_objectname(const char *name, const unsigned char *sha1,
>  			   struct atom_value *v, struct used_atom *atom)
>  {
>  	if (starts_with(name, "objectname")) {
> -		if (atom->u.objectname == O_SHORT) {
> +		if (atom->u.objectname.option == O_SHORT) {
>  			v->s = xstrdup(find_unique_abbrev(sha1, DEFAULT_ABBREV));
>  			return 1;
> -		} else if (atom->u.objectname == O_FULL) {
> +		} else if (atom->u.objectname.option == O_FULL) {
>  			v->s = xstrdup(sha1_to_hex(sha1));
>  			return 1;
> +		} else if (atom->u.objectname.option == O_LENGTH) {
> +			v->s = xstrdup(find_unique_abbrev(sha1, atom->u.objectname.length));
> +			return 1;