Re: [PATCH 2/5] interpret-trailers: add an option to show only the trailers
- From
- Jonathan Tan <jonathantanmy@google.com>
- Date
- Aug 9, 2017, 18:35 UTC
- Message-ID
- <20170809113527.292c1776@twelve2.svl.corp.google.com>
- In-Reply-To
- <20170809122402.7y4g5g5y2kkrky5e@sigill.intra.peff.net>
On Wed, 9 Aug 2017 08:24:03 -0400 Jeff King <peff@peff.net> wrote:
Show 11 quoted lines
> diff --git a/trailer.c b/trailer.c > index 0a0c2c264d..a4ff99f98a 100644 > --- a/trailer.c > +++ b/trailer.c > @@ -164,13 +164,15 @@ static void print_tok_val(FILE *outfile, const char *tok, const char *val) > fprintf(outfile, "%s%c %s\n", tok, separators[0], val); > } > > -static void print_all(FILE *outfile, struct list_head *head, int trim_empty) > +static void print_all(FILE *outfile, struct list_head *head, > + struct process_trailer_options *opts)
This can be const, I think. (Same thing for patch 1.)
Show 17 quoted lines
> {
> struct list_head *pos;
> struct trailer_item *item;
> list_for_each(pos, head) {
> item = list_entry(pos, struct trailer_item, list);
> - if (!trim_empty || strlen(item->value) > 0)
> + if ((!opts->trim_empty || strlen(item->value) > 0) &&
> + (!opts->only_trailers || item->token))
> print_tok_val(outfile, item->token, item->value);
> }
> }
> @@ -897,9 +899,10 @@ static int process_input_file(FILE *outfile,
> trailer_info_get(&info, str);
>
> /* Print lines before the trailers as is */
> - fwrite(str, 1, info.trailer_start - str, outfile);
> + if (outfile)Any reason why you expect outfile to possibly be NULL?
> + fwrite(str, 1, info.trailer_start - str, outfile); > > - if (!info.blank_line_before_trailer) > + if (outfile && !info.blank_line_before_trailer)
Same comment here.
> fprintf(outfile, "\n");
>
> for (i = 0; i < info.trailer_nr; i++) {