Re: [PATCH] commit: allow --pretty= args to be abbreviated

From: Eric Wong <normalperson@yhbt.net>
Date: 2006-05-16 23:25:41
Junio C Hamano <junkio@cox.net> wrote:
> Eric Wong <normalperson@yhbt.net> writes:
> 
> > Unlike the original one, this one only does prefix matches, so
> > you can't do --pretty=er anymore :)
> 
> Sounds good.  But then you know how long the unique prefix
> are for each candidate, so wouldn't this rather be redundant, I
> wonder?

I just copied the idea for the 2nd for loop from gitopt, since it makes
maintenance easier when there are lots of possibilities.  We only have 6
(soon 7) to worry about for --pretty= here, so hard coding lengths
probably makes more sense.

> > +
> > +	/* look for abbreviations */
> > +	len = strlen(arg);
> > +	found = -1;
> > +	for (i = 0; i < ARRAY_SIZE(cmt_fmts); i++) {
> > +		if (!strncmp(cmt_fmts[i].n, arg, len)) {
> > +			if (found >= 0)
> > +				die("invalid --pretty format: %s", arg);
> > +			found = i;
> > +		}
> > +	}
> > +	if (found >= 0)
> > +		return cmt_fmts[found].v;
> > +	die("invalid --pretty format: %s", arg);
> >  }
> 
> It would probably be better to say "ambiguous" not "invalid" in
> the die() message.

Yes, but only one die() message left now :)

-- 
Eric Wong
Received on Tue May 16 23:26:19 2006

This archive was generated by hypermail 2.1.8 : 2006-05-16 23:26:37 EST