summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--builtin-clone.c5
-rw-r--r--builtin-fetch.c2
-rw-r--r--builtin-push.c2
-rw-r--r--transport-helper.c3
-rw-r--r--transport.c17
-rw-r--r--transport.h10
6 files changed, 27 insertions, 12 deletions
diff --git a/builtin-clone.c b/builtin-clone.c
index 959fe4b59e..05f8fb4771 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 d23ea2a53e..6b96b41382 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 0082dadb73..dce3152fec 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 3d33697a4b..3e69ebd188 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 0655f65c1b..e2cfabd7ee 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++)
@@ -915,6 +915,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()");
@@ -1013,12 +1015,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 c0743b1086..de2745a6ed 100644
--- a/transport.h
+++ b/transport.h
@@ -74,7 +74,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
@@ -120,7 +125,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,