threads / discuss / 15777

Forcing progerss output for clone

Subject: Forcing progerss output for clone

## tl;dr

11 messages between Oct 3, 2008 and Oct 9, 2008.

replies: 10people: 5as markdown or json

Constantine Plotnikov· Oct 3, 2008, 20:01 UTC · lore
Hello!

Is there a way to force a progress output on stderr for git clone preferably using options or environment variables?

The clone command in the git 1.6.0.2 does not print a progress information to stderr if stdout and stderr are redirected (even if no "-q" option is specified).

Such information would have been useful for displaying progress information when cloning from IDE. IDE run git with streams redirected, and this progress information could have been displayed to user to indicate current status of operation.

Best Regards, Constantine

Alex Riesen· Oct 4, 2008, 21:42 UTC · re: Constantine Plotnikov · lore

Re: Forcing progerss output for clone

2008/10/3 Constantine Plotnikov <constantine.plotnikov@gmail.com>:
> Is there a way to force a progress output on stderr for git clone
> preferably using options or environment variables?

No, but "-v" option is not used for anything yet, so you are free to implement it.

Miklos Vajna· Oct 6, 2008, 22:19 UTC · re: Alex Riesen · lore

[PATCH] Implement git clone -v

The new -v option forces the progressbar, even in case the output is not a terminal.

Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>
---
On Sat, Oct 04, 2008 at 11:42:15PM +0200, Alex Riesen <raa.lkml@gmail.com> wrote:
Show 6 quoted lines
> 2008/10/3 Constantine Plotnikov <constantine.plotnikov@gmail.com>:
> > Is there a way to force a progress output on stderr for git clone
> > preferably using options or environment variables?
>
> No, but "-v" option is not used for anything yet, so you are free to
> implement it.
Something like this?
 Documentation/git-clone.txt |    5 +++++
 builtin-clone.c             |    4 ++++
 transport.c                 |    2 +-
 transport.h                 |    2 ++
 4 files changed, 12 insertions(+), 1 deletions(-)
diff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt
index 0e14e73..95f08b9 100644
--- a/Documentation/git-clone.txt
+++ b/Documentation/git-clone.txt
@@ -90,6 +90,11 @@ then the cloned repository will become corrupt.
 	Operate quietly.  This flag is also passed to the `rsync'
 	command when given.
 
+--verbose::
+-v::
+	Display the progressbar, even in case the standard output is not
+	a terminal.
+
 --no-checkout::
 -n::
 	No checkout of HEAD is performed after the clone is complete.
diff --git a/builtin-clone.c b/builtin-clone.c
index 49d2eb9..df71b23 100644
--- a/builtin-clone.c
+++ b/builtin-clone.c
@@ -38,9 +38,11 @@ static int option_local, option_no_hardlinks, option_shared;
 static char *option_template, *option_reference, *option_depth;
 static char *option_origin = NULL;
 static char *option_upload_pack = "git-upload-pack";
+static int option_verbose;
 
 static struct option builtin_clone_options[] = {
 	OPT__QUIET(&option_quiet),
+	OPT__VERBOSE(&option_verbose),
 	OPT_BOOLEAN('n', "no-checkout", &option_no_checkout,
 		    "don't create a checkout"),
 	OPT_BOOLEAN(0, "bare", &option_bare, "create a bare repository"),
@@ -506,6 +508,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 
 		if (option_quiet)
 			transport->verbose = -1;
+		else if (option_verbose)
+			transport->progress = 1;
 
 		if (option_upload_pack)
 			transport_set_option(transport, TRANS_OPT_UPLOADPACK,
diff --git a/transport.c b/transport.c
index 5110c56..1c510a3 100644
--- a/transport.c
+++ b/transport.c
@@ -644,7 +644,7 @@ static int fetch_refs_via_pack(struct transport *transport,
 	args.include_tag = data->followtags;
 	args.verbose = (transport->verbose > 0);
 	args.quiet = (transport->verbose < 0);
-	args.no_progress = args.quiet || !isatty(1);
+	args.no_progress = args.quiet || (!transport->progress && !isatty(1));
 	args.depth = data->depth;
 
 	for (i = 0; i < nr_heads; i++)
diff --git a/transport.h b/transport.h
index d0b5205..6bbc1a8 100644
--- a/transport.h
+++ b/transport.h
@@ -25,6 +25,8 @@ struct transport {
 	int (*disconnect)(struct transport *connection);
 	char *pack_lockfile;
 	signed verbose : 2;
+	/* Force progress even if the output is not a tty */
+	unsigned progress : 1;
 };
 
 #define TRANSPORT_PUSH_ALL 1
-- 
1.6.0.2
Alex Riesen· Oct 7, 2008, 06:21 UTC · re: Miklos Vajna · lore

Re: [PATCH] Implement git clone -v

2008/10/7 Miklos Vajna <vmiklos@frugalware.org>:
Show 16 quoted lines
> The new -v option forces the progressbar, even in case the output is not
> a terminal.
>
> Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>
> ---
>
> On Sat, Oct 04, 2008 at 11:42:15PM +0200, Alex Riesen <raa.lkml@gmail.com> wrote:
>> 2008/10/3 Constantine Plotnikov <constantine.plotnikov@gmail.com>:
>> > Is there a way to force a progress output on stderr for git clone
>> > preferably using options or environment variables?
>>
>> No, but "-v" option is not used for anything yet, so you are free to
>> implement it.
>
> Something like this?
>
Yes. Does it work? :)
Miklos Vajna· Oct 7, 2008, 19:39 UTC · re: Alex Riesen · lore

Re: [PATCH] Implement git clone -v

On Tue, Oct 07, 2008 at 08:21:28AM +0200, Alex Riesen <raa.lkml@gmail.com> wrote:
> Yes. Does it work? :)

Yes, it does. I'm not sure how to test it from the testsuite, maybe redirect the output to a file and grep in it? It's ugly, that's why I did not do so, but if you think a testcase is a musthave for this feature then that's the way to go, I guess.

Shawn O. Pearce· Oct 8, 2008, 06:02 UTC · re: Miklos Vajna · lore

Re: [PATCH] Implement git clone -v

Miklos Vajna <vmiklos@frugalware.org> wrote:
Show 7 quoted lines
> On Tue, Oct 07, 2008 at 08:21:28AM +0200, Alex Riesen <raa.lkml@gmail.com> wrote:
> > Yes. Does it work? :)
> 
> Yes, it does. I'm not sure how to test it from the testsuite, maybe
> redirect the output to a file and grep in it? It's ugly, that's why I
> did not do so, but if you think a testcase is a musthave for this
> feature then that's the way to go, I guess.

Actually its not a bad way to test the feature. Normally we disable progress if stdout is not a tty. If you redirect to a file then -v should be needed to get anything at all on stderr.

You may be able to just test the size of the file:
	git fetch -v ... >out 2>err &&
	test -s err
-- 
Shawn.
Alex Riesen· Oct 8, 2008, 06:25 UTC · re: Shawn O. Pearce · lore

Re: [PATCH] Implement git clone -v

Shawn O. Pearce, Wed, Oct 08, 2008 08:02:57 +0200:
Show 16 quoted lines
> Miklos Vajna <vmiklos@frugalware.org> wrote:
> > On Tue, Oct 07, 2008 at 08:21:28AM +0200, Alex Riesen <raa.lkml@gmail.com> wrote:
> > > Yes. Does it work? :)
> > 
> > Yes, it does. I'm not sure how to test it from the testsuite, maybe
> > redirect the output to a file and grep in it? It's ugly, that's why I
> > did not do so, but if you think a testcase is a musthave for this
> > feature then that's the way to go, I guess.
> 
> Actually its not a bad way to test the feature.  Normally we disable
> progress if stdout is not a tty.  If you redirect to a file then
> -v should be needed to get anything at all on stderr.
> 
> You may be able to just test the size of the file:
> 
> 	git fetch -v ... >out 2>err &&
git clone
> 	test -s err

Right, but I don't think you need tests for progress bar. As a typical eye candy, it tends to change often enough to be too annoying to test.

Miklos Vajna· Oct 8, 2008, 23:40 UTC · re: Shawn O. Pearce · lore

[PATCH] Implement git clone -v

The new -v option forces the progressbar, even in case the output is not a terminal.

Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>
---
On Tue, Oct 07, 2008 at 11:02:57PM -0700, "Shawn O. Pearce" <spearce@spearce.org> wrote:
> You may be able to just test the size of the file:
>
>       git fetch -v ... >out 2>err &&
>       test -s err
Here is an updated patch, now with testcases.
 Documentation/git-clone.txt |    5 +++++
 builtin-clone.c             |    4 ++++
 t/t5702-clone-options.sh    |   13 +++++++++++++
 transport.c                 |    2 +-
 transport.h                 |    2 ++
 5 files changed, 25 insertions(+), 1 deletions(-)
diff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt
index 0e14e73..95f08b9 100644
--- a/Documentation/git-clone.txt
+++ b/Documentation/git-clone.txt
@@ -90,6 +90,11 @@ then the cloned repository will become corrupt.
 	Operate quietly.  This flag is also passed to the `rsync'
 	command when given.
 
+--verbose::
+-v::
+	Display the progressbar, even in case the standard output is not
+	a terminal.
+
 --no-checkout::
 -n::
 	No checkout of HEAD is performed after the clone is complete.
diff --git a/builtin-clone.c b/builtin-clone.c
index 49d2eb9..df71b23 100644
--- a/builtin-clone.c
+++ b/builtin-clone.c
@@ -38,9 +38,11 @@ static int option_local, option_no_hardlinks, option_shared;
 static char *option_template, *option_reference, *option_depth;
 static char *option_origin = NULL;
 static char *option_upload_pack = "git-upload-pack";
+static int option_verbose;
 
 static struct option builtin_clone_options[] = {
 	OPT__QUIET(&option_quiet),
+	OPT__VERBOSE(&option_verbose),
 	OPT_BOOLEAN('n', "no-checkout", &option_no_checkout,
 		    "don't create a checkout"),
 	OPT_BOOLEAN(0, "bare", &option_bare, "create a bare repository"),
@@ -506,6 +508,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 
 		if (option_quiet)
 			transport->verbose = -1;
+		else if (option_verbose)
+			transport->progress = 1;
 
 		if (option_upload_pack)
 			transport_set_option(transport, TRANS_OPT_UPLOADPACK,
diff --git a/t/t5702-clone-options.sh b/t/t5702-clone-options.sh
index 328e4d9..27825f5 100755
--- a/t/t5702-clone-options.sh
+++ b/t/t5702-clone-options.sh
@@ -19,4 +19,17 @@ test_expect_success 'clone -o' '
 
 '
 
+test_expect_success 'redirected clone' '
+
+	git clone "file://$(pwd)/parent" clone-redirected >out 2>err &&
+	test ! -s err
+
+'
+test_expect_success 'redirected clone -v' '
+
+	git clone -v "file://$(pwd)/parent" clone-redirected-v >out 2>err &&
+	test -s err
+
+'
+
 test_done
diff --git a/transport.c b/transport.c
index 5110c56..1c510a3 100644
--- a/transport.c
+++ b/transport.c
@@ -644,7 +644,7 @@ static int fetch_refs_via_pack(struct transport *transport,
 	args.include_tag = data->followtags;
 	args.verbose = (transport->verbose > 0);
 	args.quiet = (transport->verbose < 0);
-	args.no_progress = args.quiet || !isatty(1);
+	args.no_progress = args.quiet || (!transport->progress && !isatty(1));
 	args.depth = data->depth;
 
 	for (i = 0; i < nr_heads; i++)
diff --git a/transport.h b/transport.h
index d0b5205..6bbc1a8 100644
--- a/transport.h
+++ b/transport.h
@@ -25,6 +25,8 @@ struct transport {
 	int (*disconnect)(struct transport *connection);
 	char *pack_lockfile;
 	signed verbose : 2;
+	/* Force progress even if the output is not a tty */
+	unsigned progress : 1;
 };
 
 #define TRANSPORT_PUSH_ALL 1
-- 
1.6.0.2
Junio C Hamano· Oct 9, 2008, 11:06 UTC · re: Miklos Vajna · lore

Re: [PATCH] Implement git clone -v

Miklos Vajna <vmiklos@frugalware.org> writes:
> The new -v option forces the progressbar, even in case the output is not
> a terminal.
>
> Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>

The patch made me wonder why this new feature had to be implemented in the first place and had me look up the message the patch was an follow-up to. For somebody who would not recall the original request-for-feature (that includes you 6 months from now), it would have been easier to understand the context if the commit message said what the intended purpose of this (i.e. "have it read by an IDE").

Shawn O. Pearce· Oct 9, 2008, 15:20 UTC · re: Junio C Hamano · lore

Re: [PATCH] Implement git clone -v

Junio C Hamano <gitster@pobox.com> wrote:
Show 13 quoted lines
> Miklos Vajna <vmiklos@frugalware.org> writes:
> 
> > The new -v option forces the progressbar, even in case the output is not
> > a terminal.
> >
> > Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>
> 
> The patch made me wonder why this new feature had to be implemented in the
> first place and had me look up the message the patch was an follow-up to.
> For somebody who would not recall the original request-for-feature (that
> includes you 6 months from now), it would have been easier to understand
> the context if the commit message said what the intended purpose of this
> (i.e. "have it read by an IDE").
I'm amending the message as the following:

--8<-- Implement git clone -v

The new -v option forces the progressbar, even in case the output is not a terminal. This can be useful if the caller is an IDE or wrapper which wants to scrape the progressbar from stderr and show its information in a different format.

Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
--
-- 
Shawn.
Miklos Vajna· Oct 9, 2008, 21:26 UTC · re: Shawn O. Pearce · lore

Re: [PATCH] Implement git clone -v

On Thu, Oct 09, 2008 at 08:20:28AM -0700, "Shawn O. Pearce" <spearce@spearce.org> wrote:
Show 9 quoted lines
> I'm amending the message as the following:
> 
> --8<--
> Implement git clone -v
> 
> The new -v option forces the progressbar, even in case the output
> is not a terminal.  This can be useful if the caller is an IDE or
> wrapper which wants to scrape the progressbar from stderr and show
> its information in a different format.
Thanks!

← back to recent threads