Re: [PATCH v7 04/17] ref-filter: modify "%(objectname:short)" to take length
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Nov 10, 2016, 23:32 UTC
- Message-ID
- <xmqqk2ca52td.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <20161108201211.25213-5-Karthik.188@gmail.com>
Karthik Nayak <karthik.188@gmail.com> writes:
Show 14 quoted lines
> 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.
Show 15 quoted lines
> @@ -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;