@matheusbsbs / matheus-bagliano / commits / d01b3c02e8
Fork 0

transport->progress: use flag authoritatively

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Tay Ray Chuan committed Feb 24, 2010 at 20:50 UTC d01b3c02e8a066054c308ee2ce521a2ea44738d3
6 files changed +27 -12
builtin-clone.c
+1 -4
@@ -525,10 +525,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
525 transport_set_option(transport, TRANS_OPT_DEPTH,
526 option_depth);
527
528 - transport_set_verbosity(transport, option_verbosity);
529 -
530 - if (option_progress)
531 - transport->progress = 1;
528 + transport_set_verbosity(transport, option_verbosity, option_progress);
529
530 if (option_upload_pack)
531 transport_set_option(transport, TRANS_OPT_UPLOADPACK,
builtin-fetch.c
+1 -1
@@ -823,7 +823,7 @@ static int fetch_one(struct remote *remote, int argc, const char **argv)
823 die("Where do you want to fetch from today?");
824
825 transport = transport_get(remote, NULL);
826 - transport_set_verbosity(transport, verbosity);
826 + transport_set_verbosity(transport, verbosity, 0);
827 if (upload_pack)
828 set_option(TRANS_OPT_UPLOADPACK, upload_pack);
829 if (keep)
builtin-push.c
+1 -1
@@ -107,7 +107,7 @@ static int push_with_options(struct transport *transport, int flags)
107 int err;
108 int nonfastforward;
109
110 - transport_set_verbosity(transport, verbosity);
110 + transport_set_verbosity(transport, verbosity, 0);
111
112 if (receivepack)
113 transport_set_option(transport,
transport-helper.c
+1 -2
@@ -279,9 +279,8 @@ static void standard_options(struct transport *t)
279 char buf[16];
280 int n;
281 int v = t->verbose;
282 - int no_progress = v < 0 || (!t->progress && !isatty(2));
282
284 - set_helper_option(t, "progress", !no_progress ? "true" : "false");
283 + set_helper_option(t, "progress", t->progress ? "true" : "false");
284
285 n = snprintf(buf, sizeof(buf), "%d", v + 1);
286 if (n >= sizeof(buf))
transport.c
+15 -2
@@ -526,7 +526,7 @@ static int fetch_refs_via_pack(struct transport *transport,
526 args.include_tag = data->options.followtags;
527 args.verbose = (transport->verbose > 0);
528 args.quiet = (transport->verbose < 0);
529 - args.no_progress = args.quiet || (!transport->progress && !isatty(2));
529 + args.no_progress = !transport->progress;
530 args.depth = data->options.depth;
531
532 for (i = 0; i < nr_heads; i++)
@@ -915,6 +915,8 @@ struct transport *transport_get(struct remote *remote, const char *url)
915 const char *helper;
916 struct transport *ret = xcalloc(1, sizeof(*ret));
917
918 + ret->progress = isatty(2);
919 +
920 if (!remote)
921 die("No remote provided to transport_get()");
922
@@ -1013,12 +1015,23 @@ int transport_set_option(struct transport *transport,
1015 return 1;
1016 }
1017
1016 -void transport_set_verbosity(struct transport *transport, int verbosity)
1018 +void transport_set_verbosity(struct transport *transport, int verbosity,
1019 + int force_progress)
1020 {
1021 if (verbosity >= 2)
1022 transport->verbose = verbosity <= 3 ? verbosity : 3;
1023 if (verbosity < 0)
1024 transport->verbose = -1;
1025 +
1026 + /**
1027 + * Rules used to determine whether to report progress (processing aborts
1028 + * when a rule is satisfied):
1029 + *
1030 + * 1. Report progress, if force_progress is 1 (ie. --progress).
1031 + * 2. Don't report progress, if verbosity < 0 (ie. -q/--quiet ).
1032 + * 3. Report progress if isatty(2) is 1.
1033 + **/
1034 + transport->progress = force_progress || (verbosity >= 0 && isatty(2));
1035 }
1036
1037 int transport_push(struct transport *transport,
transport.h
+8 -2
@@ -74,7 +74,12 @@ struct transport {
74 int (*disconnect)(struct transport *connection);
75 char *pack_lockfile;
76 signed verbose : 3;
77 - /* Force progress even if stderr is not a tty */
77 + /**
78 + * Transports should not set this directly, and should use this
79 + * value without having to check isatty(2), -q/--quiet
80 + * (transport->verbose < 0), etc. - checking has already been done
81 + * in transport_set_verbosity().
82 + **/
83 unsigned progress : 1;
84 /*
85 * If transport is at least potentially smart, this points to
@@ -120,7 +125,8 @@ struct transport *transport_get(struct remote *, const char *);
125 **/
126 int transport_set_option(struct transport *transport, const char *name,
127 const char *value);
123 -void transport_set_verbosity(struct transport *transport, int verbosity);
128 +void transport_set_verbosity(struct transport *transport, int verbosity,
129 + int force_progress);
130
131 int transport_push(struct transport *connection,
132 int refspec_nr, const char **refspec, int flags,