Re: [PATCH v17 13/14] tag.c: implement '--format' option
On Thu, Sep 10, 2015 at 11:29 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 25 quoted lines
> Karthik Nayak <karthik.188@gmail.com> writes:
>
>> -static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting)
>> +static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting, const char *format)
>> {
>> struct ref_array array;
>> - char *format, *to_free = NULL;
>> + char *to_free = NULL;
>> int i;
>
> format is const char * while to_free is non-const char * here.
>
>> @@ -41,12 +41,14 @@ static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting)
>> if (filter->lines == -1)
>> filter->lines = 0;
>>
>> + if (!format) {
>> + if (filter->lines) {
>> + format = xstrfmt("%s %%(contents:lines=%d)",
>> + "%(align:15)%%(refname:short)%%(end)", filter->lines);
>
> Hmmm, did this even pass tests and if so how? What are these double
> %% doing before refname and end? Perhaps we do not have enough test
> coverage?
>Seems like I didn't run the tests here, will change this.
Show 7 quoted lines
>> + to_free = format;
>
> This assignment discards constness.
>
> Take the result of xstrfmt() to to_free (which is a non-const
> pointer) and then assigning it to format (which is a const pointer)
> would work it around.
--
Regards,
Karthik Nayak