Re: [PATCH v2 12/25] fetch-pack: use a common function for verbose printing
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Feb 5, 2016, 00:02 UTC
- Message-ID
- <xmqqlh70dnxt.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <1454576641-29615-13-git-send-email-pclouds@gmail.com>
Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:
Show 6 quoted lines
> This reduces the number of "if (verbose)" which makes it a bit easier > to read imo. It also makes it easier to redirect all these printouts, > to a file for example. > > Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> > ---
Show 25 quoted lines
> fetch-pack.c | 88 +++++++++++++++++++++++++++++-------------------------------
> 1 file changed, 42 insertions(+), 46 deletions(-)
>
> diff --git a/fetch-pack.c b/fetch-pack.c
> index 01e34b6..16917f9 100644
> --- a/fetch-pack.c
> +++ b/fetch-pack.c
> @@ -50,6 +50,21 @@ static int non_common_revs, multi_ack, use_sideband;
> #define ALLOW_REACHABLE_SHA1 02
> static unsigned int allow_unadvertised_object_request;
>
> +__attribute__((format (printf, 2, 3)))
> +static inline void print_verbose(const struct fetch_pack_args *args,
> + const char *fmt, ...)
> +{
> + va_list params;
> +
> + if (!args->verbose)
> + return;
> +
> + va_start(params, fmt);
> + vfprintf(stderr, fmt, params);
> + va_end(params);
> + fputc('\n', stderr);
> +}This does "print if told to be verbose". Sounds more like 'tracef', 'reportf', 'debugf', etc.
I am debating myself if it is a good idea to omit the final "\n" on the calling side and add one unconditionally here, but the benefit of brevity on the many callsites outweigh the reduced flexibility, I guess.
Thanks.