Re: [PATCH v17 13/14] tag.c: implement '--format' option
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Sep 10, 2015, 17:59 UTC
- Message-ID
- <xmqq8u8e40l2.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <1441902169-9891-2-git-send-email-Karthik.188@gmail.com>
Karthik Nayak <karthik.188@gmail.com> writes:
Show 7 quoted lines
> -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.
Show 8 quoted lines
> @@ -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?
> + 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.