From: Tay Ray Chuan <rctay89@gmail.com>
To: "Git Mailing List" <git@vger.kernel.org>
Cc: "Junio C Hamano" <gitster@pobox.com>, "Jeff King" <peff@peff.net>,
"Sebastian Thiel" <byronimo@googlemail.com>
Subject: [PATCH v2 07/10] transport->progress: use flag authoritatively
Date: Wed, 24 Feb 2010 20:50:26 +0800 [thread overview]
Message-ID: <1267015829-5344-8-git-send-email-rctay89@gmail.com> (raw)
In-Reply-To: <1267015829-5344-1-git-send-email-rctay89@gmail.com>
Set transport->progress in transport.c::transport_set_verbosity() after
checking for the appropriate conditions (eg. --progress, isatty(2)),
and thereafter use it without having to check again.
The rules used are as follows (processing aborts when a rule is
satisfied):
1. Report progress, if force_progress is 1 (ie. --progress).
2. Don't report progress, if verbosity < 0 (ie. -q/--quiet).
3. Report progress if isatty(2) is 1.
This changes progress reporting behaviour such that if both --progress
and --quiet are specified, progress is reported.
In two areas, the logic to determine whether to *not* show progress is
changed to simply use the negation of transport->progress. This changes
behaviour in some ways (see previous paragraph for details).
Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>
---
builtin-clone.c | 5 +----
builtin-fetch.c | 2 +-
builtin-push.c | 2 +-
transport-helper.c | 3 +--
transport.c | 17 +++++++++++++++--
transport.h | 10 ++++++++--
6 files changed, 27 insertions(+), 12 deletions(-)
diff --git a/builtin-clone.c b/builtin-clone.c
index 959fe4b..05f8fb4 100644
--- a/builtin-clone.c
+++ b/builtin-clone.c
@@ -525,10 +525,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
transport_set_option(transport, TRANS_OPT_DEPTH,
option_depth);
- transport_set_verbosity(transport, option_verbosity);
-
- if (option_progress)
- transport->progress = 1;
+ transport_set_verbosity(transport, option_verbosity, option_progress);
if (option_upload_pack)
transport_set_option(transport, TRANS_OPT_UPLOADPACK,
diff --git a/builtin-fetch.c b/builtin-fetch.c
index a7c7e67..bc3fcf3 100644
--- a/builtin-fetch.c
+++ b/builtin-fetch.c
@@ -823,7 +823,7 @@ static int fetch_one(struct remote *remote, int argc, const char **argv)
die("Where do you want to fetch from today?");
transport = transport_get(remote, NULL);
- transport_set_verbosity(transport, verbosity);
+ transport_set_verbosity(transport, verbosity, 0);
if (upload_pack)
set_option(TRANS_OPT_UPLOADPACK, upload_pack);
if (keep)
diff --git a/builtin-push.c b/builtin-push.c
index 0082dad..dce3152 100644
--- a/builtin-push.c
+++ b/builtin-push.c
@@ -107,7 +107,7 @@ static int push_with_options(struct transport *transport, int flags)
int err;
int nonfastforward;
- transport_set_verbosity(transport, verbosity);
+ transport_set_verbosity(transport, verbosity, 0);
if (receivepack)
transport_set_option(transport,
diff --git a/transport-helper.c b/transport-helper.c
index b868ea4..2638781 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -279,9 +279,8 @@ static void standard_options(struct transport *t)
char buf[16];
int n;
int v = t->verbose;
- int no_progress = v < 0 || (!t->progress && !isatty(2));
- set_helper_option(t, "progress", !no_progress ? "true" : "false");
+ set_helper_option(t, "progress", t->progress ? "true" : "false");
n = snprintf(buf, sizeof(buf), "%d", v + 1);
if (n >= sizeof(buf))
diff --git a/transport.c b/transport.c
index f29fd6c..6d85447 100644
--- a/transport.c
+++ b/transport.c
@@ -526,7 +526,7 @@ static int fetch_refs_via_pack(struct transport *transport,
args.include_tag = data->options.followtags;
args.verbose = (transport->verbose > 0);
args.quiet = (transport->verbose < 0);
- args.no_progress = args.quiet || (!transport->progress && !isatty(2));
+ args.no_progress = !transport->progress;
args.depth = data->options.depth;
for (i = 0; i < nr_heads; i++)
@@ -913,6 +913,8 @@ struct transport *transport_get(struct remote *remote, const char *url)
const char *helper;
struct transport *ret = xcalloc(1, sizeof(*ret));
+ ret->progress = isatty(2);
+
if (!remote)
die("No remote provided to transport_get()");
@@ -1012,12 +1014,23 @@ int transport_set_option(struct transport *transport,
return 1;
}
-void transport_set_verbosity(struct transport *transport, int verbosity)
+void transport_set_verbosity(struct transport *transport, int verbosity,
+ int force_progress)
{
if (verbosity >= 2)
transport->verbose = verbosity <= 3 ? verbosity : 3;
if (verbosity < 0)
transport->verbose = -1;
+
+ /**
+ * Rules used to determine whether to report progress (processing aborts
+ * when a rule is satisfied):
+ *
+ * 1. Report progress, if force_progress is 1 (ie. --progress).
+ * 2. Don't report progress, if verbosity < 0 (ie. -q/--quiet ).
+ * 3. Report progress if isatty(2) is 1.
+ **/
+ transport->progress = force_progress || (verbosity >= 0 && isatty(2));
}
int transport_push(struct transport *transport,
diff --git a/transport.h b/transport.h
index d5973ee..531731e 100644
--- a/transport.h
+++ b/transport.h
@@ -80,7 +80,12 @@ struct transport {
int (*disconnect)(struct transport *connection);
char *pack_lockfile;
signed verbose : 3;
- /* Force progress even if stderr is not a tty */
+ /**
+ * Transports should not set this directly, and should use this
+ * value without having to check isatty(2), -q/--quiet
+ * (transport->verbose < 0), etc. - checking has already been done
+ * in transport_set_verbosity().
+ **/
unsigned progress : 1;
/*
* If transport is at least potentially smart, this points to
@@ -127,7 +132,8 @@ struct transport *transport_get(struct remote *, const char *);
**/
int transport_set_option(struct transport *transport, const char *name,
const char *value);
-void transport_set_verbosity(struct transport *transport, int verbosity);
+void transport_set_verbosity(struct transport *transport, int verbosity,
+ int force_progress);
int transport_push(struct transport *connection,
int refspec_nr, const char **refspec, int flags,
--
1.7.0.20.gcb44ed
next prev parent reply other threads:[~2010-02-24 12:51 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-24 12:50 [PATCH v2 00/10] teach --progress to transport-related builtins Tay Ray Chuan
2010-02-24 12:50 ` [PATCH v2 01/10] Documentation/git-clone: mention progress in -v Tay Ray Chuan
2010-02-24 12:50 ` [PATCH v2 02/10] Documentation/git-pull: put verbosity options before merge/fetch ones Tay Ray Chuan
2010-02-24 12:50 ` [PATCH v2 03/10] Documentation/git-push: put --quiet before --verbose Tay Ray Chuan
2010-02-24 12:50 ` [PATCH v2 04/10] fetch: refactor verbosity option handling into transport.[ch] Tay Ray Chuan
2010-02-24 12:50 ` [PATCH v2 05/10] push: support multiple levels of verbosity Tay Ray Chuan
2010-02-24 12:50 ` [PATCH v2 06/10] clone: " Tay Ray Chuan
2010-02-24 12:50 ` Tay Ray Chuan [this message]
2010-02-24 12:50 ` [PATCH v2 08/10] push: learn --progress Tay Ray Chuan
2010-02-24 12:50 ` [PATCH v2 09/10] fetch and pull: " Tay Ray Chuan
2010-02-24 12:50 ` [PATCH v2 10/10] transport: update flags to be in running order Tay Ray Chuan
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=1267015829-5344-8-git-send-email-rctay89@gmail.com \
--to=rctay89@gmail.com \
--cc=byronimo@googlemail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/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).