From: Junio C Hamano Date: Fri, 05 Feb 2016 00:02:22 GMT Subject: Re: [PATCH v2 12/25] fetch-pack: use a common function for verbose printing Message-ID: In-Reply-To: <1454576641-29615-13-git-send-email-pclouds@gmail.com> Nguyễn Thái Ngọc Duy writes: > 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 > --- > 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.