From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Eric Sunshine" <sunshine@sunshineco.com>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH v2 12/25] fetch-pack: use a common function for verbose printing
Date: Thu, 4 Feb 2016 16:03:48 +0700 [thread overview]
Message-ID: <1454576641-29615-13-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1454576641-29615-1-git-send-email-pclouds@gmail.com>
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>
---
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);
+}
+
static void rev_list_push(struct commit *commit, int mark)
{
if (!(commit->object.flags & mark)) {
@@ -375,8 +390,7 @@ static int find_common(struct fetch_pack_args *args,
retval = -1;
while ((sha1 = get_rev())) {
packet_buf_write(&req_buf, "have %s\n", sha1_to_hex(sha1));
- if (args->verbose)
- fprintf(stderr, "have %s\n", sha1_to_hex(sha1));
+ print_verbose(args, "have %s", sha1_to_hex(sha1));
in_vain++;
if (flush_at <= ++count) {
int ack;
@@ -397,9 +411,9 @@ static int find_common(struct fetch_pack_args *args,
consume_shallow_list(args, fd[0]);
do {
ack = get_ack(fd[0], result_sha1);
- if (args->verbose && ack)
- fprintf(stderr, "got ack %d %s\n", ack,
- sha1_to_hex(result_sha1));
+ if (ack)
+ print_verbose(args, "got ack %d %s", ack,
+ sha1_to_hex(result_sha1));
switch (ack) {
case ACK:
flushes = 0;
@@ -438,8 +452,7 @@ static int find_common(struct fetch_pack_args *args,
} while (ack);
flushes--;
if (got_continue && MAX_IN_VAIN < in_vain) {
- if (args->verbose)
- fprintf(stderr, "giving up\n");
+ print_verbose(args, "giving up");
break; /* give up */
}
}
@@ -449,8 +462,7 @@ done:
packet_buf_write(&req_buf, "done\n");
send_request(args, fd[1], &req_buf);
}
- if (args->verbose)
- fprintf(stderr, "done\n");
+ print_verbose(args, "done");
if (retval != 0) {
multi_ack = 0;
flushes++;
@@ -462,9 +474,8 @@ done:
while (flushes || multi_ack) {
int ack = get_ack(fd[0], result_sha1);
if (ack) {
- if (args->verbose)
- fprintf(stderr, "got ack (%d) %s\n", ack,
- sha1_to_hex(result_sha1));
+ print_verbose(args, "got ack (%d) %s", ack,
+ sha1_to_hex(result_sha1));
if (ack == ACK)
return 0;
multi_ack = 1;
@@ -509,9 +520,8 @@ static void mark_recent_complete_commits(struct fetch_pack_args *args,
unsigned long cutoff)
{
while (complete && cutoff <= complete->item->date) {
- if (args->verbose)
- fprintf(stderr, "Marking %s as complete\n",
- oid_to_hex(&complete->item->object.oid));
+ print_verbose(args, "Marking %s as complete",
+ oid_to_hex(&complete->item->object.oid));
pop_most_recent_commit(&complete, COMPLETE);
}
}
@@ -652,18 +662,12 @@ static int everything_local(struct fetch_pack_args *args,
o = lookup_object(remote);
if (!o || !(o->flags & COMPLETE)) {
retval = 0;
- if (!args->verbose)
- continue;
- fprintf(stderr,
- "want %s (%s)\n", sha1_to_hex(remote),
- ref->name);
+ print_verbose(args, "want %s (%s)", sha1_to_hex(remote),
+ ref->name);
continue;
}
- if (!args->verbose)
- continue;
- fprintf(stderr,
- "already have %s (%s)\n", sha1_to_hex(remote),
- ref->name);
+ print_verbose(args, "already have %s (%s)", sha1_to_hex(remote),
+ ref->name);
}
return retval;
}
@@ -810,39 +814,32 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
if ((args->depth > 0 || is_repository_shallow()) && !server_supports("shallow"))
die("Server does not support shallow clients");
if (server_supports("multi_ack_detailed")) {
- if (args->verbose)
- fprintf(stderr, "Server supports multi_ack_detailed\n");
+ print_verbose(args, "Server supports multi_ack_detailed");
multi_ack = 2;
if (server_supports("no-done")) {
- if (args->verbose)
- fprintf(stderr, "Server supports no-done\n");
+ print_verbose(args, "Server supports no-done");
if (args->stateless_rpc)
no_done = 1;
}
}
else if (server_supports("multi_ack")) {
- if (args->verbose)
- fprintf(stderr, "Server supports multi_ack\n");
+ print_verbose(args, "Server supports multi_ack");
multi_ack = 1;
}
if (server_supports("side-band-64k")) {
- if (args->verbose)
- fprintf(stderr, "Server supports side-band-64k\n");
+ print_verbose(args, "Server supports side-band-64k");
use_sideband = 2;
}
else if (server_supports("side-band")) {
- if (args->verbose)
- fprintf(stderr, "Server supports side-band\n");
+ print_verbose(args, "Server supports side-band");
use_sideband = 1;
}
if (server_supports("allow-tip-sha1-in-want")) {
- if (args->verbose)
- fprintf(stderr, "Server supports allow-tip-sha1-in-want\n");
+ print_verbose(args, "Server supports allow-tip-sha1-in-want");
allow_unadvertised_object_request |= ALLOW_TIP_SHA1;
}
if (server_supports("allow-reachable-sha1-in-want")) {
- if (args->verbose)
- fprintf(stderr, "Server supports allow-reachable-sha1-in-want\n");
+ print_verbose(args, "Server supports allow-reachable-sha1-in-want\n");
allow_unadvertised_object_request |= ALLOW_REACHABLE_SHA1;
}
if (!server_supports("thin-pack"))
@@ -851,17 +848,16 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
args->no_progress = 0;
if (!server_supports("include-tag"))
args->include_tag = 0;
- if (server_supports("ofs-delta")) {
- if (args->verbose)
- fprintf(stderr, "Server supports ofs-delta\n");
- } else
+ if (server_supports("ofs-delta"))
+ print_verbose(args, "Server supports ofs-delta");
+ else
prefer_ofs_delta = 0;
if ((agent_feature = server_feature_value("agent", &agent_len))) {
agent_supported = 1;
- if (args->verbose && agent_len)
- fprintf(stderr, "Server version is %.*s\n",
- agent_len, agent_feature);
+ if (agent_len)
+ print_verbose(args, "Server version is %.*s",
+ agent_len, agent_feature);
}
if (everything_local(args, &ref, sought, nr_sought)) {
--
2.7.0.377.g4cd97dd
next prev parent reply other threads:[~2016-02-04 9:05 UTC|newest]
Thread overview: 63+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-04 9:03 [PATCH v2 00/25] More flexibility in making shallow clones Nguyễn Thái Ngọc Duy
2016-02-04 9:03 ` [PATCH v2 01/25] remote-curl.c: convert fetch_git() to use argv_array Nguyễn Thái Ngọc Duy
2016-02-04 22:59 ` Junio C Hamano
2016-02-04 9:03 ` [PATCH v2 02/25] transport-helper.c: refactor set_helper_option() Nguyễn Thái Ngọc Duy
2016-02-04 23:18 ` Junio C Hamano
2016-02-04 9:03 ` [PATCH v2 03/25] transport-helper.c: do not send null option to remote helper Nguyễn Thái Ngọc Duy
2016-02-04 23:22 ` Junio C Hamano
2016-02-06 9:38 ` Duy Nguyen
2016-02-08 20:53 ` Junio C Hamano
2016-02-04 9:03 ` [PATCH v2 04/25] upload-pack: move shallow deepen code out of receive_needs() Nguyễn Thái Ngọc Duy
2016-02-04 23:30 ` Junio C Hamano
2016-02-04 9:03 ` [PATCH v2 05/25] upload-pack: move "shallow" sending code out of deepen() Nguyễn Thái Ngọc Duy
2016-02-04 9:03 ` [PATCH v2 06/25] upload-pack: remove unused variable "backup" Nguyễn Thái Ngọc Duy
2016-02-04 23:32 ` Junio C Hamano
2016-02-04 9:03 ` [PATCH v2 07/25] upload-pack: move "unshallow" sending code out of deepen() Nguyễn Thái Ngọc Duy
2016-02-04 23:39 ` Junio C Hamano
2016-02-04 9:03 ` [PATCH v2 08/25] upload-pack: use skip_prefix() instead of starts_with() when possible Nguyễn Thái Ngọc Duy
2016-02-04 23:42 ` Junio C Hamano
2016-02-04 9:03 ` [PATCH v2 09/25] upload-pack: tighten number parsing at "deepen" lines Nguyễn Thái Ngọc Duy
2016-02-04 23:48 ` Junio C Hamano
2016-02-15 3:07 ` Duy Nguyen
2016-02-04 9:03 ` [PATCH v2 10/25] upload-pack: move rev-list code out of check_non_tip() Nguyễn Thái Ngọc Duy
2016-02-04 9:03 ` [PATCH v2 11/25] fetch-pack: use skip_prefix() instead of starts_with() when possible Nguyễn Thái Ngọc Duy
2016-02-04 23:56 ` Junio C Hamano
2016-02-04 9:03 ` Nguyễn Thái Ngọc Duy [this message]
2016-02-05 0:02 ` [PATCH v2 12/25] fetch-pack: use a common function for verbose printing Junio C Hamano
2016-02-05 4:03 ` Eric Sunshine
2016-02-04 9:03 ` [PATCH v2 13/25] fetch-pack: use a separate flag for fetch in deepening mode Nguyễn Thái Ngọc Duy
2016-02-05 0:03 ` Junio C Hamano
2016-02-05 4:13 ` Eric Sunshine
2016-02-04 9:03 ` [PATCH v2 14/25] shallow.c: implement a generic shallow boundary finder based on rev-list Nguyễn Thái Ngọc Duy
2016-02-08 21:09 ` Junio C Hamano
2016-02-15 8:00 ` Duy Nguyen
2016-02-19 9:30 ` Duy Nguyen
2016-02-04 9:03 ` [PATCH v2 15/25] upload-pack: add deepen-since to cut shallow repos based on time Nguyễn Thái Ngọc Duy
2016-02-08 21:14 ` Junio C Hamano
2016-02-04 9:03 ` [PATCH v2 16/25] fetch: define shallow boundary with --shallow-since Nguyễn Thái Ngọc Duy
2016-02-04 9:03 ` [PATCH v2 17/25] clone: define shallow clone boundary based on time " Nguyễn Thái Ngọc Duy
2016-02-08 21:20 ` Junio C Hamano
2016-02-04 9:03 ` [PATCH v2 18/25] t5500, t5539: tests for shallow depth since a specific date Nguyễn Thái Ngọc Duy
2016-02-08 21:24 ` Junio C Hamano
2016-02-15 7:17 ` Duy Nguyen
2016-02-04 9:03 ` [PATCH v2 19/25] refs: add expand_ref() Nguyễn Thái Ngọc Duy
2016-02-08 21:27 ` Junio C Hamano
2016-02-04 9:03 ` [PATCH v2 20/25] upload-pack: support define shallow boundary by excluding revisions Nguyễn Thái Ngọc Duy
2016-02-05 5:03 ` Eric Sunshine
2016-02-08 21:34 ` Junio C Hamano
2016-02-05 5:05 ` Eric Sunshine
2016-02-15 3:31 ` Duy Nguyen
2016-02-04 9:03 ` [PATCH v2 21/25] fetch: define shallow boundary with --shallow-exclude Nguyễn Thái Ngọc Duy
2016-02-05 5:26 ` Eric Sunshine
2016-02-15 3:53 ` Duy Nguyen
2016-02-15 5:52 ` Eric Sunshine
2016-02-15 5:56 ` Eric Sunshine
2016-02-15 8:15 ` Duy Nguyen
2016-02-19 1:35 ` Eric Sunshine
2016-02-04 9:03 ` [PATCH v2 22/25] clone: define shallow clone " Nguyễn Thái Ngọc Duy
2016-02-04 9:03 ` [PATCH v2 23/25] t5500, t5539: tests for shallow depth excluding a ref Nguyễn Thái Ngọc Duy
2016-02-04 9:04 ` [PATCH v2 24/25] upload-pack: make check_reachable_object() return unreachable list if asked Nguyễn Thái Ngọc Duy
2016-02-05 5:41 ` Eric Sunshine
2016-02-04 9:04 ` [PATCH v2 25/25] fetch, upload-pack: --deepen=N extends shallow boundary by N commits Nguyễn Thái Ngọc Duy
2016-02-08 21:45 ` [PATCH v2 00/25] More flexibility in making shallow clones Junio C Hamano
2016-02-12 0:24 ` Duy Nguyen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1454576641-29615-13-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=sunshine@sunshineco.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).