{"thread":{"id":"58918","subject":"[PATCH] scalar: use verbose mode in clone","startedAt":"2022-12-07T18:11:02Z","lastAt":"2023-01-13T19:52:29Z","messageCount":12,"participants":["ZheNing Hu via GitGitGadget","Taylor Blau","ZheNing Hu","Derrick Stolee","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"468733","messageId":"pull.1441.git.1670436656379.gitgitgadget@gmail.com","threadId":"58918","inReplyTo":null,"subject":"[PATCH] scalar: use verbose mode in clone","fromName":"ZheNing Hu via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-12-07T18:10:56Z","receivedAt":"2022-12-07T18:11:02Z","isPatch":true,"sender":{"key":"adlternative@gmail.com","avatar":"https://avatars.githubusercontent.com/u/58138461?v=4"},"body":"From: ZheNing Hu <adlternative@gmail.com>\n\nSometimes when users use scalar to download a monorepo\nwith a long commit history, they want to check the\nprogress bar to know how long they still need to wait\nduring the fetch process, but scalar suppresses this\noutput by default.\n\nSo add `[--verbose| -v]` to scalar clone, to enable\nfetch's output.\n\nSigned-off-by: ZheNing Hu <adlternative@gmail.com>\n---\n    scalar: use verbose mode in clone\n    \n    When users use scalar to download a monorepo with a long commit history\n    (or the client and server network communication is very poor), we often\n    need to spend a long time in the fetch phase of scalar, some users may\n    want to check this progress bar To understand the progress of fetch and\n    how long they have to wait, so we should enable scalar to display fetch\n    progress.\n    \n    v1. add [--verbose| -v] to scalar clone.\n    \n    Note: output look like this:\n    \n    $ scalar clone -v git@github.com:git/git.git\n    Initialized empty Git repository in /Users/adl/test/git/src/.git/\n    remote: Enumerating objects: 209091, done.\n    remote: Counting objects: 100% (991/991), done.\n    remote: Compressing objects: 100% (944/944), done.\n    Receiving objects: 100% (209085/209085), 81.39 MiB | 126.00 KiB/s, done.\n    remote: Total 209085 (delta 54), reused 979 (delta 47), pack-reused 208094\n    Resolving deltas: 100% (134000/134000), done.\n    From github.com:git/git\n     * [new branch]          jch         -> origin/jch\n     * [new branch]          main        -> origin/main\n     * [new branch]          maint       -> origin/maint\n     * [new branch]          master      -> origin/master\n     * [new branch]          next        -> origin/next\n     * [new branch]          seen        -> origin/seen\n     * [new branch]          todo        -> origin/todo\n     * [new tag]             v2.39.0-rc2 -> v2.39.0-rc2\n     * [new tag]             gitgui-0.10.0    -> gitgui-0.10.0\n     * [new tag]             gitgui-0.10.1    -> gitgui-0.10.1\n     * [new tag]             gitgui-0.10.2    -> gitgui-0.10.2\n     * [new tag]             gitgui-0.11.0    -> gitgui-0.11.0\n     ...\n    \n    \n    \"new branch\", \"new tag\" output is a bit annoying, it would be better to\n    suppress them, but keep the progress.\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-1441%2Fadlternative%2Fzh%2Fscalar-verbosity-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1441/adlternative/zh/scalar-verbosity-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/1441\n\n Documentation/scalar.txt |  7 ++++++-\n scalar.c                 | 11 ++++++++---\n 2 files changed, 14 insertions(+), 4 deletions(-)\n\ndiff --git a/Documentation/scalar.txt b/Documentation/scalar.txt\nindex f33436c7f65..7ff37b43945 100644\n--- a/Documentation/scalar.txt\n+++ b/Documentation/scalar.txt\n@@ -8,7 +8,7 @@ scalar - A tool for managing large Git repositories\n SYNOPSIS\n --------\n [verse]\n-scalar clone [--single-branch] [--branch <main-branch>] [--full-clone] <url> [<enlistment>]\n+scalar clone [--single-branch] [--branch <main-branch>] [--verbose | -v] [--full-clone] <url> [<enlistment>]\n scalar list\n scalar register [<enlistment>]\n scalar unregister [<enlistment>]\n@@ -84,6 +84,11 @@ cloning. If the HEAD at the remote did not point at any branch when\n \tA sparse-checkout is initialized by default. This behavior can be\n \tturned off via `--full-clone`.\n \n+-v::\n+--verbose::\n+\tWhen scalar executes `git fetch`, `--quiet` is used by default to\n+\tsuppress the output of fetch, use verbose mode for cancel this.\n+\n List\n ~~~~\n \ndiff --git a/scalar.c b/scalar.c\nindex 6c52243cdf1..b1d4504d136 100644\n--- a/scalar.c\n+++ b/scalar.c\n@@ -404,7 +404,7 @@ void load_builtin_commands(const char *prefix, struct cmdnames *cmds)\n static int cmd_clone(int argc, const char **argv)\n {\n \tconst char *branch = NULL;\n-\tint full_clone = 0, single_branch = 0;\n+\tint full_clone = 0, single_branch = 0, verbosity = 0;\n \tstruct option clone_options[] = {\n \t\tOPT_STRING('b', \"branch\", &branch, N_(\"<branch>\"),\n \t\t\t   N_(\"branch to checkout after clone\")),\n@@ -413,6 +413,7 @@ static int cmd_clone(int argc, const char **argv)\n \t\tOPT_BOOL(0, \"single-branch\", &single_branch,\n \t\t\t N_(\"only download metadata for the branch that will \"\n \t\t\t    \"be checked out\")),\n+\t\tOPT__VERBOSITY(&verbosity),\n \t\tOPT_END(),\n \t};\n \tconst char * const clone_usage[] = {\n@@ -499,7 +500,9 @@ static int cmd_clone(int argc, const char **argv)\n \tif (set_recommended_config(0))\n \t\treturn error(_(\"could not configure '%s'\"), dir);\n \n-\tif ((res = run_git(\"fetch\", \"--quiet\", \"origin\", NULL))) {\n+\tif ((res = run_git(\"fetch\", \"origin\",\n+\t\t\t   verbosity ? NULL : \"--quiet\",\n+\t\t\t   NULL))) {\n \t\twarning(_(\"partial clone failed; attempting full clone\"));\n \n \t\tif (set_config(\"remote.origin.promisor\") ||\n@@ -508,7 +511,9 @@ static int cmd_clone(int argc, const char **argv)\n \t\t\tgoto cleanup;\n \t\t}\n \n-\t\tif ((res = run_git(\"fetch\", \"--quiet\", \"origin\", NULL)))\n+\t\tif ((res = run_git(\"fetch\", \"origin\",\n+\t\t\t\t   verbosity ? NULL : \"--quiet\",\n+\t\t\t\t   NULL)))\n \t\t\tgoto cleanup;\n \t}\n \n\nbase-commit: 2e71cbbddd64695d43383c25c7a054ac4ff86882\n-- \ngitgitgadget\n"},{"id":"468736","messageId":"Y5EPVpb511wk5Uw/@nand.local","threadId":"58918","inReplyTo":"pull.1441.git.1670436656379.gitgitgadget@gmail.com","subject":"Re: [PATCH] scalar: use verbose mode in clone","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2022-12-07T22:10:30Z","receivedAt":"2022-12-07T22:10:39Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Wed, Dec 07, 2022 at 06:10:56PM +0000, ZheNing Hu via GitGitGadget wrote:\n> So add `[--verbose| -v]` to scalar clone, to enable\n> fetch's output.\n\nSeems reasonable.\n\n> @@ -84,6 +84,11 @@ cloning. If the HEAD at the remote did not point at any branch when\n>  \tA sparse-checkout is initialized by default. This behavior can be\n>  \tturned off via `--full-clone`.\n>\n> +-v::\n> +--verbose::\n> +\tWhen scalar executes `git fetch`, `--quiet` is used by default to\n> +\tsuppress the output of fetch, use verbose mode for cancel this.\n> +\n\nThis description may be exposing a few too many implementation details\nfor our liking. E.g., scalar happens to use `git fetch`, but it might\nnot always. That is probably academic, but a more practical reason to do\nsome hiding here might just be that it's unnecessary detail to expose in\nour documentation.\n\nPerhaps something like:\n\n    -v::\n    --verbose::\n     Enable more verbose output when cloning a repository.\n\nOr something simple like that.\n\n>  List\n>  ~~~~\n>\n> diff --git a/scalar.c b/scalar.c\n> index 6c52243cdf1..b1d4504d136 100644\n> --- a/scalar.c\n> +++ b/scalar.c\n> @@ -404,7 +404,7 @@ void load_builtin_commands(const char *prefix, struct cmdnames *cmds)\n>  static int cmd_clone(int argc, const char **argv)\n>  {\n>  \tconst char *branch = NULL;\n> -\tint full_clone = 0, single_branch = 0;\n> +\tint full_clone = 0, single_branch = 0, verbosity = 0;\n>  \tstruct option clone_options[] = {\n>  \t\tOPT_STRING('b', \"branch\", &branch, N_(\"<branch>\"),\n>  \t\t\t   N_(\"branch to checkout after clone\")),\n> @@ -413,6 +413,7 @@ static int cmd_clone(int argc, const char **argv)\n>  \t\tOPT_BOOL(0, \"single-branch\", &single_branch,\n>  \t\t\t N_(\"only download metadata for the branch that will \"\n>  \t\t\t    \"be checked out\")),\n> +\t\tOPT__VERBOSITY(&verbosity),\n>  \t\tOPT_END(),\n>  \t};\n>  \tconst char * const clone_usage[] = {\n\nLooking good.\n\n> @@ -499,7 +500,9 @@ static int cmd_clone(int argc, const char **argv)\n>  \tif (set_recommended_config(0))\n>  \t\treturn error(_(\"could not configure '%s'\"), dir);\n>\n> -\tif ((res = run_git(\"fetch\", \"--quiet\", \"origin\", NULL))) {\n> +\tif ((res = run_git(\"fetch\", \"origin\",\n> +\t\t\t   verbosity ? NULL : \"--quiet\",\n> +\t\t\t   NULL))) {\n\nHmmph. This and below are a little strange in that they will end up\ncalling:\n\n    run_git(\"fetch\", \"origin\", NULL, NULL);\n\nwhen running without `--verbose`. `run_git()` will still do the right\nthing and stop reading its arguments after the first NULL that it sees.\nSo I doubt that it's a huge deal in practice, but felt worth calling out\nnonetheless.\n\nIs there an opportunity to easily test this new code?\n\nThanks,\nTaylor\n"},{"id":"468791","messageId":"CAOLTT8Qb0euc5WLdi7v_3ovXT4jJ1-t8BO40jjdM4Rj0Ok8Etw@mail.gmail.com","threadId":"58918","inReplyTo":"Y5EPVpb511wk5Uw/@nand.local","subject":"Re: [PATCH] scalar: use verbose mode in clone","fromName":"ZheNing Hu","fromEmail":"adlternative@gmail.com","sentAt":"2022-12-08T15:54:28Z","receivedAt":"2022-12-08T15:54:50Z","isPatch":true,"sender":{"key":"adlternative@gmail.com","avatar":"https://avatars.githubusercontent.com/u/58138461?v=4"},"body":"Taylor Blau <me@ttaylorr.com> 于2022年12月8日周四 06:10写道：\n>\n> On Wed, Dec 07, 2022 at 06:10:56PM +0000, ZheNing Hu via GitGitGadget wrote:\n> > So add `[--verbose| -v]` to scalar clone, to enable\n> > fetch's output.\n>\n> Seems reasonable.\n>\n> > @@ -84,6 +84,11 @@ cloning. If the HEAD at the remote did not point at any branch when\n> >       A sparse-checkout is initialized by default. This behavior can be\n> >       turned off via `--full-clone`.\n> >\n> > +-v::\n> > +--verbose::\n> > +     When scalar executes `git fetch`, `--quiet` is used by default to\n> > +     suppress the output of fetch, use verbose mode for cancel this.\n> > +\n>\n> This description may be exposing a few too many implementation details\n> for our liking. E.g., scalar happens to use `git fetch`, but it might\n> not always. That is probably academic, but a more practical reason to do\n> some hiding here might just be that it's unnecessary detail to expose in\n> our documentation.\n>\n\nHmmm. There are two steps to downloading data from scalar clone:\nthe first step is to let \"git fetch partial clone\"  to  download commits,\ntrees, tags, and the second step is download the blobs corresponding\nto the top-level files of the repository during git checkout. So I'm not sure\nif I should mention \"fetch\" here, since the progress bar for the \"checkout\"\nstep is able to be displayed.\n\n> Perhaps something like:\n>\n>     -v::\n>     --verbose::\n>      Enable more verbose output when cloning a repository.\n>\n\nJust mentioning \"clone\" is fine... But I'm not sure if users will be\nconfused, why they will \"more verbose\" instead of two options\n\"full verbose\" or \"not verbose\".\n\n> Or something simple like that.\n>\n> >  List\n> >  ~~~~\n> >\n> > diff --git a/scalar.c b/scalar.c\n> > index 6c52243cdf1..b1d4504d136 100644\n> > --- a/scalar.c\n> > +++ b/scalar.c\n> > @@ -404,7 +404,7 @@ void load_builtin_commands(const char *prefix, struct cmdnames *cmds)\n> >  static int cmd_clone(int argc, const char **argv)\n> >  {\n> >       const char *branch = NULL;\n> > -     int full_clone = 0, single_branch = 0;\n> > +     int full_clone = 0, single_branch = 0, verbosity = 0;\n> >       struct option clone_options[] = {\n> >               OPT_STRING('b', \"branch\", &branch, N_(\"<branch>\"),\n> >                          N_(\"branch to checkout after clone\")),\n> > @@ -413,6 +413,7 @@ static int cmd_clone(int argc, const char **argv)\n> >               OPT_BOOL(0, \"single-branch\", &single_branch,\n> >                        N_(\"only download metadata for the branch that will \"\n> >                           \"be checked out\")),\n> > +             OPT__VERBOSITY(&verbosity),\n> >               OPT_END(),\n> >       };\n> >       const char * const clone_usage[] = {\n>\n> Looking good.\n>\n> > @@ -499,7 +500,9 @@ static int cmd_clone(int argc, const char **argv)\n> >       if (set_recommended_config(0))\n> >               return error(_(\"could not configure '%s'\"), dir);\n> >\n> > -     if ((res = run_git(\"fetch\", \"--quiet\", \"origin\", NULL))) {\n> > +     if ((res = run_git(\"fetch\", \"origin\",\n> > +                        verbosity ? NULL : \"--quiet\",\n> > +                        NULL))) {\n>\n> Hmmph. This and below are a little strange in that they will end up\n> calling:\n>\n>     run_git(\"fetch\", \"origin\", NULL, NULL);\n>\n> when running without `--verbose`. `run_git()` will still do the right\n> thing and stop reading its arguments after the first NULL that it sees.\n> So I doubt that it's a huge deal in practice, but felt worth calling out\n> nonetheless.\n>\n\nThe reason I'm doing this is seeing that toggle_maintenance() already\ndoes this, and it's not buggy, but it's really inelegant.\n\nMy personal understanding is that the original intention of run_git()\nis to help developers simply put git parameters into the variable parameters\nof the function, and run_git() has no good way to understand null values.\nHere we put it in run_git () The last is an act of desperation.\n\n> Is there an opportunity to easily test this new code?\n>\n\nIt's a bit cumbersome, but I will try.\n\n> Thanks,\n> Taylor\n\nThanks,\nZheNing Hu\n"},{"id":"468793","messageId":"95e92f84-5f83-6439-0d02-f8060669a4d3@github.com","threadId":"58918","inReplyTo":"pull.1441.git.1670436656379.gitgitgadget@gmail.com","subject":"Re: [PATCH] scalar: use verbose mode in clone","fromName":"Derrick Stolee","fromEmail":"derrickstolee@github.com","sentAt":"2022-12-08T16:30:04Z","receivedAt":"2022-12-08T16:30:14Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"On 12/7/2022 1:10 PM, ZheNing Hu via GitGitGadget wrote:\n> From: ZheNing Hu <adlternative@gmail.com>\n> \n> Sometimes when users use scalar to download a monorepo\n> with a long commit history, they want to check the\n> progress bar to know how long they still need to wait\n> during the fetch process, but scalar suppresses this\n> output by default.\n\nI think this is an accurate description of the status quo.\n \n> So add `[--verbose| -v]` to scalar clone, to enable\n> fetch's output.\n\nHowever, this isn't the only thing we could consider doing.\n\nFor instance, we typically use isatty(2) to detect if\nstderr is a terminal to determine if we should carry\nthrough progress indicators. It seems that maybe run_git()\nis not passing through stderr and thus diminishing the\nprogress indicators to the fetch subprocess. It's worth\nlooking into to see if there's a different approach that\nwould get the same goal without needing a new option. It\ncould also make your proposed '--verbose' to be implied\nby isatty(2).\n\nIf being verbose becomes the implied default with isatty(2),\nthen it might be better to add a --quiet option instead, to\nopt-out of the progress.\n\nAlso, I'm not sure your implementation is doing the right\nthing.\n\n> -\tif ((res = run_git(\"fetch\", \"--quiet\", \"origin\", NULL))) {\n> +\tif ((res = run_git(\"fetch\", \"origin\",\n> +\t\t\t   verbosity ? NULL : \"--quiet\",\n> +\t\t\t   NULL))) {\n>  \t\twarning(_(\"partial clone failed; attempting full clone\"));\n>  \n>  \t\tif (set_config(\"remote.origin.promisor\") ||\n> @@ -508,7 +511,9 @@ static int cmd_clone(int argc, const char **argv)\n>  \t\t\tgoto cleanup;\n>  \t\t}\n>  \n> -\t\tif ((res = run_git(\"fetch\", \"--quiet\", \"origin\", NULL)))\n> +\t\tif ((res = run_git(\"fetch\", \"origin\",\n> +\t\t\t\t   verbosity ? NULL : \"--quiet\",\n> +\t\t\t\t   NULL)))\n\nSpecifically, here the \"verbosity\" being on does not change\nthe way we are calling 'git fetch', so I do not expect the\nbehavior to change with this calling pattern.\n\nYou might want to add the \"--progress\" option in the verbose\ncase.\n\nAs Taylor mentioned, a test might be helpful. Here's an\nexample from t7700-repack.sh that sets up the isatty(2)\nconfiguration correctly, as well as sets the progress\ndelay to 0 to be sure some progress indicators are written:\n\ntest_expect_success TTY '--quiet disables progress' '\n\ttest_terminal env GIT_PROGRESS_DELAY=0 \\\n\t\tgit -C midx repack -ad --quiet --write-midx 2>stderr &&\n\ttest_must_be_empty stderr\n'\n\nThanks,\n-Stolee\n"},{"id":"468994","messageId":"CAOLTT8TBtWAoN+etO_tDezN0e5yP1hSSzKn20SqvfDE-0o3pQQ@mail.gmail.com","threadId":"58918","inReplyTo":"95e92f84-5f83-6439-0d02-f8060669a4d3@github.com","subject":"Re: [PATCH] scalar: use verbose mode in clone","fromName":"ZheNing Hu","fromEmail":"adlternative@gmail.com","sentAt":"2022-12-13T16:37:06Z","receivedAt":"2022-12-13T16:37:23Z","isPatch":true,"sender":{"key":"adlternative@gmail.com","avatar":"https://avatars.githubusercontent.com/u/58138461?v=4"},"body":"Hi,\n\nDerrick Stolee <derrickstolee@github.com> 于2022年12月9日周五 00:30写道：\n>\n> On 12/7/2022 1:10 PM, ZheNing Hu via GitGitGadget wrote:\n> > From: ZheNing Hu <adlternative@gmail.com>\n> >\n> > Sometimes when users use scalar to download a monorepo\n> > with a long commit history, they want to check the\n> > progress bar to know how long they still need to wait\n> > during the fetch process, but scalar suppresses this\n> > output by default.\n>\n> I think this is an accurate description of the status quo.\n>\n> > So add `[--verbose| -v]` to scalar clone, to enable\n> > fetch's output.\n>\n> However, this isn't the only thing we could consider doing.\n>\n> For instance, we typically use isatty(2) to detect if\n> stderr is a terminal to determine if we should carry\n> through progress indicators. It seems that maybe run_git()\n> is not passing through stderr and thus diminishing the\n> progress indicators to the fetch subprocess. It's worth\n> looking into to see if there's a different approach that\n> would get the same goal without needing a new option. It\n> could also make your proposed '--verbose' to be implied\n> by isatty(2).\n>\n> If being verbose becomes the implied default with isatty(2),\n> then it might be better to add a --quiet option instead, to\n> opt-out of the progress.\n>\n\nGood point that we should care about atty.\n\nI guess you mean is to add a parameter to run_git(), which can\ncontrol if git commands show stderr/stdout... This solution\nmay be better. Because git checkout should also have the\nsame behavior as git fetch: quiet or verbose.\n\n> Also, I'm not sure your implementation is doing the right\n> thing.\n>\n> > -     if ((res = run_git(\"fetch\", \"--quiet\", \"origin\", NULL))) {\n> > +     if ((res = run_git(\"fetch\", \"origin\",\n> > +                        verbosity ? NULL : \"--quiet\",\n> > +                        NULL))) {\n> >               warning(_(\"partial clone failed; attempting full clone\"));\n> >\n> >               if (set_config(\"remote.origin.promisor\") ||\n> > @@ -508,7 +511,9 @@ static int cmd_clone(int argc, const char **argv)\n> >                       goto cleanup;\n> >               }\n> >\n> > -             if ((res = run_git(\"fetch\", \"--quiet\", \"origin\", NULL)))\n> > +             if ((res = run_git(\"fetch\", \"origin\",\n> > +                                verbosity ? NULL : \"--quiet\",\n> > +                                NULL)))\n>\n> Specifically, here the \"verbosity\" being on does not change\n> the way we are calling 'git fetch', so I do not expect the\n> behavior to change with this calling pattern.\n>\n\nSorry, but I don't understand: I deleted \"--quiet\", and the progress bar can\nalso be displayed. Why do you say \"not change the way we are\ncalling 'git fetch'\"？\n\n> You might want to add the \"--progress\" option in the verbose\n> case.\n>\n\nGood advice.\n\n> As Taylor mentioned, a test might be helpful. Here's an\n> example from t7700-repack.sh that sets up the isatty(2)\n> configuration correctly, as well as sets the progress\n> delay to 0 to be sure some progress indicators are written:\n>\n> test_expect_success TTY '--quiet disables progress' '\n>         test_terminal env GIT_PROGRESS_DELAY=0 \\\n>                 git -C midx repack -ad --quiet --write-midx 2>stderr &&\n>         test_must_be_empty stderr\n> '\n>\n\nThanks for the reminder, I will pay attention to this \"TTY\" and\n\"GIT_PROGRESS_DELAY\" when I write tests later.\n\n> Thanks,\n> -Stolee\n\nThanks,\n-ZheNing Hu\n"},{"id":"469524","messageId":"pull.1441.v2.git.1671974986363.gitgitgadget@gmail.com","threadId":"58918","inReplyTo":"pull.1441.git.1670436656379.gitgitgadget@gmail.com","subject":"[PATCH v2] scalar: show progress if stderr refer to a terminal","fromName":"ZheNing Hu via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-12-25T13:29:46Z","receivedAt":"2022-12-25T13:29:55Z","isPatch":true,"sender":{"key":"adlternative@gmail.com","avatar":"https://avatars.githubusercontent.com/u/58138461?v=4"},"body":"From: ZheNing Hu <adlternative@gmail.com>\n\nSometimes when users use scalar to download a monorepo\nwith a long commit history, they want to check the\nprogress bar to know how long they still need to wait\nduring the fetch process, but scalar suppresses this\noutput by default.\n\nSo let's check whether scalar stderr refer to a terminal,\nif so, show progress, otherwise disable it.\n\nSigned-off-by: ZheNing Hu <adlternative@gmail.com>\n---\n    scalar: show progress if stderr refer to a terminal\n    \n    When users use scalar to download a monorepo with a long commit history\n    (or the client and server network communication is very poor), we often\n    need to spend a long time in the fetch phase of scalar, some users may\n    want to check this progress bar To understand the progress of fetch and\n    how long they have to wait, so we should enable scalar to display fetch\n    progress.\n    \n    v1. add [--verbose| -v] to scalar clone.\n    \n    v2.\n    \n     1. remove --verbose option.\n     2. check if scalar stderr refer to terminal, if so, show progress.\n    \n    Note: output look like this:\n    \n    $ scalar clone git@github.com:git/git.git\n    Initialized empty Git repository in /home/adl/test/git/src/.git/\n    remote: Enumerating objects: 208997, done.\n    remote: Counting objects: 100% (870/870), done.\n    remote: Compressing objects: 100% (870/870), done.\n    remote: Total 208991 (delta 0), reused 870 (delta 0), pack-reused 208121\n    remote: Enumerating objects: 470, done.\n    remote: Counting objects: 100% (418/418), done.\n    remote: Compressing objects: 100% (418/418), done.\n    remote: Total 470 (delta 1), reused 0 (delta 0), pack-reused 52\n    Receiving objects: 100% (470/470), 1.96 MiB | 1.64 MiB/s, done.\n    Resolving deltas: 100% (1/1), done.\n    Updating files: 100% (471/471), done.\n    branch 'master' set up to track 'origin/master'.\n    Switched to a new branch 'master'\n    Your branch is up to date with 'origin/master'.\n    \n    \n    \"new branch\", \"new tag\" output is a bit annoying, it would be better to\n    suppress them, but keep the progress.\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-1441%2Fadlternative%2Fzh%2Fscalar-verbosity-v2\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1441/adlternative/zh/scalar-verbosity-v2\nPull-Request: https://github.com/gitgitgadget/git/pull/1441\n\nRange-diff vs v1:\n\n 1:  6169841190a ! 1:  2e4c296bd19 scalar: use verbose mode in clone\n     @@ Metadata\n      Author: ZheNing Hu <adlternative@gmail.com>\n      \n       ## Commit message ##\n     -    scalar: use verbose mode in clone\n     +    scalar: show progress if stderr refer to a terminal\n      \n          Sometimes when users use scalar to download a monorepo\n          with a long commit history, they want to check the\n     @@ Commit message\n          during the fetch process, but scalar suppresses this\n          output by default.\n      \n     -    So add `[--verbose| -v]` to scalar clone, to enable\n     -    fetch's output.\n     +    So let's check whether scalar stderr refer to a terminal,\n     +    if so, show progress, otherwise disable it.\n      \n          Signed-off-by: ZheNing Hu <adlternative@gmail.com>\n      \n     - ## Documentation/scalar.txt ##\n     -@@ Documentation/scalar.txt: scalar - A tool for managing large Git repositories\n     - SYNOPSIS\n     - --------\n     - [verse]\n     --scalar clone [--single-branch] [--branch <main-branch>] [--full-clone] <url> [<enlistment>]\n     -+scalar clone [--single-branch] [--branch <main-branch>] [--verbose | -v] [--full-clone] <url> [<enlistment>]\n     - scalar list\n     - scalar register [<enlistment>]\n     - scalar unregister [<enlistment>]\n     -@@ Documentation/scalar.txt: cloning. If the HEAD at the remote did not point at any branch when\n     - \tA sparse-checkout is initialized by default. This behavior can be\n     - \tturned off via `--full-clone`.\n     - \n     -+-v::\n     -+--verbose::\n     -+\tWhen scalar executes `git fetch`, `--quiet` is used by default to\n     -+\tsuppress the output of fetch, use verbose mode for cancel this.\n     -+\n     - List\n     - ~~~~\n     - \n     -\n       ## scalar.c ##\n      @@ scalar.c: void load_builtin_commands(const char *prefix, struct cmdnames *cmds)\n       static int cmd_clone(int argc, const char **argv)\n       {\n       \tconst char *branch = NULL;\n      -\tint full_clone = 0, single_branch = 0;\n     -+\tint full_clone = 0, single_branch = 0, verbosity = 0;\n     ++\tint full_clone = 0, single_branch = 0, show_progress = isatty(2);\n       \tstruct option clone_options[] = {\n       \t\tOPT_STRING('b', \"branch\", &branch, N_(\"<branch>\"),\n       \t\t\t   N_(\"branch to checkout after clone\")),\n     -@@ scalar.c: static int cmd_clone(int argc, const char **argv)\n     - \t\tOPT_BOOL(0, \"single-branch\", &single_branch,\n     - \t\t\t N_(\"only download metadata for the branch that will \"\n     - \t\t\t    \"be checked out\")),\n     -+\t\tOPT__VERBOSITY(&verbosity),\n     - \t\tOPT_END(),\n     - \t};\n     - \tconst char * const clone_usage[] = {\n      @@ scalar.c: static int cmd_clone(int argc, const char **argv)\n       \tif (set_recommended_config(0))\n       \t\treturn error(_(\"could not configure '%s'\"), dir);\n       \n      -\tif ((res = run_git(\"fetch\", \"--quiet\", \"origin\", NULL))) {\n     -+\tif ((res = run_git(\"fetch\", \"origin\",\n     -+\t\t\t   verbosity ? NULL : \"--quiet\",\n     -+\t\t\t   NULL))) {\n     ++\tif ((res = run_git(\"fetch\", \"--quiet\",\n     ++\t\t\t\tshow_progress ? \"--progress\" : \"--no-progress\",\n     ++\t\t\t\t\"origin\", NULL))) {\n       \t\twarning(_(\"partial clone failed; attempting full clone\"));\n       \n       \t\tif (set_config(\"remote.origin.promisor\") ||\n     @@ scalar.c: static int cmd_clone(int argc, const char **argv)\n       \t\t}\n       \n      -\t\tif ((res = run_git(\"fetch\", \"--quiet\", \"origin\", NULL)))\n     -+\t\tif ((res = run_git(\"fetch\", \"origin\",\n     -+\t\t\t\t   verbosity ? NULL : \"--quiet\",\n     -+\t\t\t\t   NULL)))\n     ++\t\tif ((res = run_git(\"fetch\", \"--quiet\",\n     ++\t\t\t\t\tshow_progress ? \"--progress\" : \"--no-progress\",\n     ++\t\t\t\t\t\"origin\", NULL)))\n       \t\t\tgoto cleanup;\n       \t}\n       \n     +\n     + ## t/t9211-scalar-clone.sh ##\n     +@@\n     + test_description='test the `scalar clone` subcommand'\n     + \n     + . ./test-lib.sh\n     ++. \"${TEST_DIRECTORY}/lib-terminal.sh\"\n     + \n     + GIT_TEST_MAINT_SCHEDULER=\"crontab:test-tool crontab cron.txt,launchctl:true,schtasks:true\"\n     + export GIT_TEST_MAINT_SCHEDULER\n     +@@ t/t9211-scalar-clone.sh: test_expect_success '--no-single-branch clones all branches' '\n     + \tcleanup_clone $enlistment\n     + '\n     + \n     ++test_expect_success TTY 'progress with tty' '\n     ++\tenlistment=progress1 &&\n     ++\n     ++\ttest_config -C to-clone uploadpack.allowfilter true &&\n     ++\ttest_config -C to-clone uploadpack.allowanysha1inwant true &&\n     ++\n     ++\ttest_terminal env GIT_PROGRESS_DELAY=0 \\\n     ++\t\tscalar clone \"file://$(pwd)/to-clone\" \"$enlistment\" 2>stderr &&\n     ++\tgrep --count \"Enumerating objects\" stderr >actual &&\n     ++\techo 2 >expected &&\n     ++\ttest_cmp expected actual &&\n     ++\tcleanup_clone $enlistment\n     ++'\n     ++\n     ++test_expect_success 'progress without tty' '\n     ++\tenlistment=progress2 &&\n     ++\n     ++\ttest_config -C to-clone uploadpack.allowfilter true &&\n     ++\ttest_config -C to-clone uploadpack.allowanysha1inwant true &&\n     ++\n     ++\tscalar clone \"file://$(pwd)/to-clone\" \"$enlistment\" 2>stderr &&\n     ++\t! grep \"Enumerating objects\" stderr &&\n     ++\t! grep \"Updating files\" stderr &&\n     ++\tcleanup_clone $enlistment\n     ++'\n     + test_done\n\n\n scalar.c                | 10 +++++++---\n t/t9211-scalar-clone.sh | 26 ++++++++++++++++++++++++++\n 2 files changed, 33 insertions(+), 3 deletions(-)\n\ndiff --git a/scalar.c b/scalar.c\nindex 6c52243cdf1..e5cc554c537 100644\n--- a/scalar.c\n+++ b/scalar.c\n@@ -404,7 +404,7 @@ void load_builtin_commands(const char *prefix, struct cmdnames *cmds)\n static int cmd_clone(int argc, const char **argv)\n {\n \tconst char *branch = NULL;\n-\tint full_clone = 0, single_branch = 0;\n+\tint full_clone = 0, single_branch = 0, show_progress = isatty(2);\n \tstruct option clone_options[] = {\n \t\tOPT_STRING('b', \"branch\", &branch, N_(\"<branch>\"),\n \t\t\t   N_(\"branch to checkout after clone\")),\n@@ -499,7 +499,9 @@ static int cmd_clone(int argc, const char **argv)\n \tif (set_recommended_config(0))\n \t\treturn error(_(\"could not configure '%s'\"), dir);\n \n-\tif ((res = run_git(\"fetch\", \"--quiet\", \"origin\", NULL))) {\n+\tif ((res = run_git(\"fetch\", \"--quiet\",\n+\t\t\t\tshow_progress ? \"--progress\" : \"--no-progress\",\n+\t\t\t\t\"origin\", NULL))) {\n \t\twarning(_(\"partial clone failed; attempting full clone\"));\n \n \t\tif (set_config(\"remote.origin.promisor\") ||\n@@ -508,7 +510,9 @@ static int cmd_clone(int argc, const char **argv)\n \t\t\tgoto cleanup;\n \t\t}\n \n-\t\tif ((res = run_git(\"fetch\", \"--quiet\", \"origin\", NULL)))\n+\t\tif ((res = run_git(\"fetch\", \"--quiet\",\n+\t\t\t\t\tshow_progress ? \"--progress\" : \"--no-progress\",\n+\t\t\t\t\t\"origin\", NULL)))\n \t\t\tgoto cleanup;\n \t}\n \ndiff --git a/t/t9211-scalar-clone.sh b/t/t9211-scalar-clone.sh\nindex dd33d87e9be..49f054d5917 100755\n--- a/t/t9211-scalar-clone.sh\n+++ b/t/t9211-scalar-clone.sh\n@@ -3,6 +3,7 @@\n test_description='test the `scalar clone` subcommand'\n \n . ./test-lib.sh\n+. \"${TEST_DIRECTORY}/lib-terminal.sh\"\n \n GIT_TEST_MAINT_SCHEDULER=\"crontab:test-tool crontab cron.txt,launchctl:true,schtasks:true\"\n export GIT_TEST_MAINT_SCHEDULER\n@@ -148,4 +149,29 @@ test_expect_success '--no-single-branch clones all branches' '\n \tcleanup_clone $enlistment\n '\n \n+test_expect_success TTY 'progress with tty' '\n+\tenlistment=progress1 &&\n+\n+\ttest_config -C to-clone uploadpack.allowfilter true &&\n+\ttest_config -C to-clone uploadpack.allowanysha1inwant true &&\n+\n+\ttest_terminal env GIT_PROGRESS_DELAY=0 \\\n+\t\tscalar clone \"file://$(pwd)/to-clone\" \"$enlistment\" 2>stderr &&\n+\tgrep --count \"Enumerating objects\" stderr >actual &&\n+\techo 2 >expected &&\n+\ttest_cmp expected actual &&\n+\tcleanup_clone $enlistment\n+'\n+\n+test_expect_success 'progress without tty' '\n+\tenlistment=progress2 &&\n+\n+\ttest_config -C to-clone uploadpack.allowfilter true &&\n+\ttest_config -C to-clone uploadpack.allowanysha1inwant true &&\n+\n+\tscalar clone \"file://$(pwd)/to-clone\" \"$enlistment\" 2>stderr &&\n+\t! grep \"Enumerating objects\" stderr &&\n+\t! grep \"Updating files\" stderr &&\n+\tcleanup_clone $enlistment\n+'\n test_done\n\nbase-commit: 2e71cbbddd64695d43383c25c7a054ac4ff86882\n-- \ngitgitgadget\n"},{"id":"469814","messageId":"1f8493b0-3f96-c616-1e4e-98b6ed33e8c4@github.com","threadId":"58918","inReplyTo":"pull.1441.v2.git.1671974986363.gitgitgadget@gmail.com","subject":"Re: [PATCH v2] scalar: show progress if stderr refer to a terminal","fromName":"Derrick Stolee","fromEmail":"derrickstolee@github.com","sentAt":"2023-01-05T19:19:11Z","receivedAt":"2023-01-05T19:25:00Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"On 12/25/22 8:29 AM, ZheNing Hu via GitGitGadget wrote:\n> From: ZheNing Hu <adlternative@gmail.com>\n\nSorry for the long wait in getting back to reviewing.\n\n> Sometimes when users use scalar to download a monorepo\n> with a long commit history, they want to check the\n> progress bar to know how long they still need to wait\n> during the fetch process, but scalar suppresses this\n> output by default.\n> \n> So let's check whether scalar stderr refer to a terminal,\n> if so, show progress, otherwise disable it.\n\nThanks for updating to this strategy. I think it's an\neasier change to swallow. We can consider options like\n--progress, --verbose, or --quiet later while this\nchange does the good work of showing terminal users\nhelpful progress.\n\n> +\tint full_clone = 0, single_branch = 0, show_progress = isatty(2);\n\n> -\tif ((res = run_git(\"fetch\", \"--quiet\", \"origin\", NULL))) {\n> +\tif ((res = run_git(\"fetch\", \"--quiet\",\n> +\t\t\t\tshow_progress ? \"--progress\" : \"--no-progress\",\n> +\t\t\t\t\"origin\", NULL))) {\n>  \t\twarning(_(\"partial clone failed; attempting full clone\"));\n>  \n>  \t\tif (set_config(\"remote.origin.promisor\") ||\n> @@ -508,7 +510,9 @@ static int cmd_clone(int argc, const char **argv)\n>  \t\t\tgoto cleanup;\n>  \t\t}\n>  \n> -\t\tif ((res = run_git(\"fetch\", \"--quiet\", \"origin\", NULL)))\n> +\t\tif ((res = run_git(\"fetch\", \"--quiet\",\n> +\t\t\t\t\tshow_progress ? \"--progress\" : \"--no-progress\",\n> +\t\t\t\t\t\"origin\", NULL)))\nImplementation looks correct.\n\n> +test_expect_success TTY 'progress with tty' '\n> +\tenlistment=progress1 &&\n> +\n> +\ttest_config -C to-clone uploadpack.allowfilter true &&\n> +\ttest_config -C to-clone uploadpack.allowanysha1inwant true &&\n> +\n> +\ttest_terminal env GIT_PROGRESS_DELAY=0 \\\n> +\t\tscalar clone \"file://$(pwd)/to-clone\" \"$enlistment\" 2>stderr &&\n\nThank you for creating this test!\n\n> +\tgrep --count \"Enumerating objects\" stderr >actual &&\n> +\techo 2 >expected &&\n> +\ttest_cmp expected actual &&\n\nI think you could use \"test_line_count = 2 actual\" here.\n\n> +\tcleanup_clone $enlistment\n> +'\n> +\n> +test_expect_success 'progress without tty' '\n> +\tenlistment=progress2 &&\n> +\n> +\ttest_config -C to-clone uploadpack.allowfilter true &&\n> +\ttest_config -C to-clone uploadpack.allowanysha1inwant true &&\n> +\n> +\tscalar clone \"file://$(pwd)/to-clone\" \"$enlistment\" 2>stderr &&\n> +\t! grep \"Enumerating objects\" stderr &&\n> +\t! grep \"Updating files\" stderr &&\n\nHere, it would be good to still have the GIT_PROGRESS_DELAY=0\nenvironment variable on the 'scalar clone' command to be sure\nwe are not getting these lines because progress is turned off\nand not because it's running too quickly.\n\n> +\tcleanup_clone $enlistment\n> +'\n>  test_done\n\nA nit: there should be an empty line between the end quote of\nthe last test and \"test_done\".\n\nThanks,\n-Stolee\n"},{"id":"469826","messageId":"xmqqsfgnsv3w.fsf@gitster.g","threadId":"58918","inReplyTo":"1f8493b0-3f96-c616-1e4e-98b6ed33e8c4@github.com","subject":"Re: [PATCH v2] scalar: show progress if stderr refer to a terminal","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-01-06T12:30:59Z","receivedAt":"2023-01-06T12:31:52Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Derrick Stolee <derrickstolee@github.com> writes:\n\n>> +test_expect_success 'progress without tty' '\n>> +\tenlistment=progress2 &&\n>> +\n>> +\ttest_config -C to-clone uploadpack.allowfilter true &&\n>> +\ttest_config -C to-clone uploadpack.allowanysha1inwant true &&\n>> +\n>> +\tscalar clone \"file://$(pwd)/to-clone\" \"$enlistment\" 2>stderr &&\n>> +\t! grep \"Enumerating objects\" stderr &&\n>> +\t! grep \"Updating files\" stderr &&\n>\n> Here, it would be good to still have the GIT_PROGRESS_DELAY=0\n> environment variable on the 'scalar clone' command to be sure\n> we are not getting these lines because progress is turned off\n> and not because it's running too quickly.\n\nGood point.\n"},{"id":"470089","messageId":"CAOLTT8Q6sOkDLm7pnkJ6e7mi4MDu6PYKD6vSd0NZbO9qAWkFmw@mail.gmail.com","threadId":"58918","inReplyTo":"1f8493b0-3f96-c616-1e4e-98b6ed33e8c4@github.com","subject":"Re: [PATCH v2] scalar: show progress if stderr refer to a terminal","fromName":"ZheNing Hu","fromEmail":"adlternative@gmail.com","sentAt":"2023-01-11T11:59:31Z","receivedAt":"2023-01-11T12:03:35Z","isPatch":true,"sender":{"key":"adlternative@gmail.com","avatar":"https://avatars.githubusercontent.com/u/58138461?v=4"},"body":"Derrick Stolee <derrickstolee@github.com> 于2023年1月6日周五 03:19写道：\n>\n> On 12/25/22 8:29 AM, ZheNing Hu via GitGitGadget wrote:\n> > From: ZheNing Hu <adlternative@gmail.com>\n>\n> Sorry for the long wait in getting back to reviewing.\n>\n\nAh, It's okay.\n\n> > Sometimes when users use scalar to download a monorepo\n> > with a long commit history, they want to check the\n> > progress bar to know how long they still need to wait\n> > during the fetch process, but scalar suppresses this\n> > output by default.\n> >\n> > So let's check whether scalar stderr refer to a terminal,\n> > if so, show progress, otherwise disable it.\n>\n> Thanks for updating to this strategy. I think it's an\n> easier change to swallow. We can consider options like\n> --progress, --verbose, or --quiet later while this\n> change does the good work of showing terminal users\n> helpful progress.\n>\n\nYes, but I think something like `--quiet` is difficult to implement.\nWe cannot just add `--no-progress` or `--quiet` to the git checkout\nfor suppressing the progress. Because git checkout will not use it\nto suppress the fetch progress, but only the checkout's progress.\n\n> > +     int full_clone = 0, single_branch = 0, show_progress = isatty(2);\n>\n> > -     if ((res = run_git(\"fetch\", \"--quiet\", \"origin\", NULL))) {\n> > +     if ((res = run_git(\"fetch\", \"--quiet\",\n> > +                             show_progress ? \"--progress\" : \"--no-progress\",\n> > +                             \"origin\", NULL))) {\n> >               warning(_(\"partial clone failed; attempting full clone\"));\n> >\n> >               if (set_config(\"remote.origin.promisor\") ||\n> > @@ -508,7 +510,9 @@ static int cmd_clone(int argc, const char **argv)\n> >                       goto cleanup;\n> >               }\n> >\n> > -             if ((res = run_git(\"fetch\", \"--quiet\", \"origin\", NULL)))\n> > +             if ((res = run_git(\"fetch\", \"--quiet\",\n> > +                                     show_progress ? \"--progress\" : \"--no-progress\",\n> > +                                     \"origin\", NULL)))\n> Implementation looks correct.\n>\n> > +test_expect_success TTY 'progress with tty' '\n> > +     enlistment=progress1 &&\n> > +\n> > +     test_config -C to-clone uploadpack.allowfilter true &&\n> > +     test_config -C to-clone uploadpack.allowanysha1inwant true &&\n> > +\n> > +     test_terminal env GIT_PROGRESS_DELAY=0 \\\n> > +             scalar clone \"file://$(pwd)/to-clone\" \"$enlistment\" 2>stderr &&\n>\n> Thank you for creating this test!\n>\n> > +     grep --count \"Enumerating objects\" stderr >actual &&\n> > +     echo 2 >expected &&\n> > +     test_cmp expected actual &&\n>\n> I think you could use \"test_line_count = 2 actual\" here.\n>\n\nOh, good suggestion. I should also use grep without `--count` too.\n\n> > +     cleanup_clone $enlistment\n> > +'\n> > +\n> > +test_expect_success 'progress without tty' '\n> > +     enlistment=progress2 &&\n> > +\n> > +     test_config -C to-clone uploadpack.allowfilter true &&\n> > +     test_config -C to-clone uploadpack.allowanysha1inwant true &&\n> > +\n> > +     scalar clone \"file://$(pwd)/to-clone\" \"$enlistment\" 2>stderr &&\n> > +     ! grep \"Enumerating objects\" stderr &&\n> > +     ! grep \"Updating files\" stderr &&\n>\n> Here, it would be good to still have the GIT_PROGRESS_DELAY=0\n> environment variable on the 'scalar clone' command to be sure\n> we are not getting these lines because progress is turned off\n> and not because it's running too quickly.\n>\n\nOK, that makes sense.\n\n> > +     cleanup_clone $enlistment\n> > +'\n> >  test_done\n>\n> A nit: there should be an empty line between the end quote of\n> the last test and \"test_done\".\n>\n> Thanks,\n> -Stolee\n\nThanks,\n-ZheNing Hu\n"},{"id":"470090","messageId":"pull.1441.v3.git.1673442860379.gitgitgadget@gmail.com","threadId":"58918","inReplyTo":"pull.1441.v2.git.1671974986363.gitgitgadget@gmail.com","subject":"[PATCH v3] scalar: show progress if stderr refer to a terminal","fromName":"ZheNing Hu via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2023-01-11T13:14:20Z","receivedAt":"2023-01-11T13:14:30Z","isPatch":true,"sender":{"key":"adlternative@gmail.com","avatar":"https://avatars.githubusercontent.com/u/58138461?v=4"},"body":"From: ZheNing Hu <adlternative@gmail.com>\n\nSometimes when users use scalar to download a monorepo\nwith a long commit history, they want to check the\nprogress bar to know how long they still need to wait\nduring the fetch process, but scalar suppresses this\noutput by default.\n\nSo let's check whether scalar stderr refer to a terminal,\nif so, show progress, otherwise disable it.\n\nSigned-off-by: ZheNing Hu <adlternative@gmail.com>\n---\n    scalar: show progress if stderr refer to a terminal\n    \n    When users use scalar to download a monorepo with a long commit history\n    (or the client and server network communication is very poor), we often\n    need to spend a long time in the fetch phase of scalar, some users may\n    want to check this progress bar To understand the progress of fetch and\n    how long they have to wait, so we should enable scalar to display fetch\n    progress.\n    \n    v1. add [--verbose| -v] to scalar clone.\n    \n    v2.\n    \n     1. remove --verbose option.\n     2. check if scalar stderr refer to terminal, if so, show progress.\n    \n    v3.\n    \n     1. fix some tests suggested by Derrick Stolee.\n    \n    Note: output look like this:\n    \n    $ scalar clone git@github.com:git/git.git\n    Initialized empty Git repository in /home/adl/test/git/src/.git/\n    remote: Enumerating objects: 208997, done.\n    remote: Counting objects: 100% (870/870), done.\n    remote: Compressing objects: 100% (870/870), done.\n    remote: Total 208991 (delta 0), reused 870 (delta 0), pack-reused 208121\n    remote: Enumerating objects: 470, done.\n    remote: Counting objects: 100% (418/418), done.\n    remote: Compressing objects: 100% (418/418), done.\n    remote: Total 470 (delta 1), reused 0 (delta 0), pack-reused 52\n    Receiving objects: 100% (470/470), 1.96 MiB | 1.64 MiB/s, done.\n    Resolving deltas: 100% (1/1), done.\n    Updating files: 100% (471/471), done.\n    branch 'master' set up to track 'origin/master'.\n    Switched to a new branch 'master'\n    Your branch is up to date with 'origin/master'.\n    \n    \n    \"new branch\", \"new tag\" output is a bit annoying, it would be better to\n    suppress them, but keep the progress.\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-1441%2Fadlternative%2Fzh%2Fscalar-verbosity-v3\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1441/adlternative/zh/scalar-verbosity-v3\nPull-Request: https://github.com/gitgitgadget/git/pull/1441\n\nRange-diff vs v2:\n\n 1:  2e4c296bd19 ! 1:  38e7e0d44d1 scalar: show progress if stderr refer to a terminal\n     @@ t/t9211-scalar-clone.sh: test_expect_success '--no-single-branch clones all bran\n      +\n      +\ttest_terminal env GIT_PROGRESS_DELAY=0 \\\n      +\t\tscalar clone \"file://$(pwd)/to-clone\" \"$enlistment\" 2>stderr &&\n     -+\tgrep --count \"Enumerating objects\" stderr >actual &&\n     -+\techo 2 >expected &&\n     -+\ttest_cmp expected actual &&\n     ++\tgrep \"Enumerating objects\" stderr >actual &&\n     ++\ttest_line_count = 2 actual &&\n      +\tcleanup_clone $enlistment\n      +'\n      +\n     -+test_expect_success 'progress without tty' '\n     ++test_expect_success TTY 'progress without tty' '\n      +\tenlistment=progress2 &&\n      +\n      +\ttest_config -C to-clone uploadpack.allowfilter true &&\n      +\ttest_config -C to-clone uploadpack.allowanysha1inwant true &&\n      +\n     -+\tscalar clone \"file://$(pwd)/to-clone\" \"$enlistment\" 2>stderr &&\n     ++\tGIT_PROGRESS_DELAY=0 scalar clone \"file://$(pwd)/to-clone\" \"$enlistment\" 2>stderr &&\n      +\t! grep \"Enumerating objects\" stderr &&\n      +\t! grep \"Updating files\" stderr &&\n      +\tcleanup_clone $enlistment\n      +'\n     ++\n       test_done\n\n\n scalar.c                | 10 +++++++---\n t/t9211-scalar-clone.sh | 26 ++++++++++++++++++++++++++\n 2 files changed, 33 insertions(+), 3 deletions(-)\n\ndiff --git a/scalar.c b/scalar.c\nindex 6c52243cdf1..e5cc554c537 100644\n--- a/scalar.c\n+++ b/scalar.c\n@@ -404,7 +404,7 @@ void load_builtin_commands(const char *prefix, struct cmdnames *cmds)\n static int cmd_clone(int argc, const char **argv)\n {\n \tconst char *branch = NULL;\n-\tint full_clone = 0, single_branch = 0;\n+\tint full_clone = 0, single_branch = 0, show_progress = isatty(2);\n \tstruct option clone_options[] = {\n \t\tOPT_STRING('b', \"branch\", &branch, N_(\"<branch>\"),\n \t\t\t   N_(\"branch to checkout after clone\")),\n@@ -499,7 +499,9 @@ static int cmd_clone(int argc, const char **argv)\n \tif (set_recommended_config(0))\n \t\treturn error(_(\"could not configure '%s'\"), dir);\n \n-\tif ((res = run_git(\"fetch\", \"--quiet\", \"origin\", NULL))) {\n+\tif ((res = run_git(\"fetch\", \"--quiet\",\n+\t\t\t\tshow_progress ? \"--progress\" : \"--no-progress\",\n+\t\t\t\t\"origin\", NULL))) {\n \t\twarning(_(\"partial clone failed; attempting full clone\"));\n \n \t\tif (set_config(\"remote.origin.promisor\") ||\n@@ -508,7 +510,9 @@ static int cmd_clone(int argc, const char **argv)\n \t\t\tgoto cleanup;\n \t\t}\n \n-\t\tif ((res = run_git(\"fetch\", \"--quiet\", \"origin\", NULL)))\n+\t\tif ((res = run_git(\"fetch\", \"--quiet\",\n+\t\t\t\t\tshow_progress ? \"--progress\" : \"--no-progress\",\n+\t\t\t\t\t\"origin\", NULL)))\n \t\t\tgoto cleanup;\n \t}\n \ndiff --git a/t/t9211-scalar-clone.sh b/t/t9211-scalar-clone.sh\nindex dd33d87e9be..2da8ca6f2bb 100755\n--- a/t/t9211-scalar-clone.sh\n+++ b/t/t9211-scalar-clone.sh\n@@ -3,6 +3,7 @@\n test_description='test the `scalar clone` subcommand'\n \n . ./test-lib.sh\n+. \"${TEST_DIRECTORY}/lib-terminal.sh\"\n \n GIT_TEST_MAINT_SCHEDULER=\"crontab:test-tool crontab cron.txt,launchctl:true,schtasks:true\"\n export GIT_TEST_MAINT_SCHEDULER\n@@ -148,4 +149,29 @@ test_expect_success '--no-single-branch clones all branches' '\n \tcleanup_clone $enlistment\n '\n \n+test_expect_success TTY 'progress with tty' '\n+\tenlistment=progress1 &&\n+\n+\ttest_config -C to-clone uploadpack.allowfilter true &&\n+\ttest_config -C to-clone uploadpack.allowanysha1inwant true &&\n+\n+\ttest_terminal env GIT_PROGRESS_DELAY=0 \\\n+\t\tscalar clone \"file://$(pwd)/to-clone\" \"$enlistment\" 2>stderr &&\n+\tgrep \"Enumerating objects\" stderr >actual &&\n+\ttest_line_count = 2 actual &&\n+\tcleanup_clone $enlistment\n+'\n+\n+test_expect_success TTY 'progress without tty' '\n+\tenlistment=progress2 &&\n+\n+\ttest_config -C to-clone uploadpack.allowfilter true &&\n+\ttest_config -C to-clone uploadpack.allowanysha1inwant true &&\n+\n+\tGIT_PROGRESS_DELAY=0 scalar clone \"file://$(pwd)/to-clone\" \"$enlistment\" 2>stderr &&\n+\t! grep \"Enumerating objects\" stderr &&\n+\t! grep \"Updating files\" stderr &&\n+\tcleanup_clone $enlistment\n+'\n+\n test_done\n\nbase-commit: a38d39a4c50d1275833aba54c4dbdfce9e2e9ca1\n-- \ngitgitgadget\n"},{"id":"470091","messageId":"9d8e38fd-f001-5aa5-ab78-cc6d314df09a@github.com","threadId":"58918","inReplyTo":"pull.1441.v3.git.1673442860379.gitgitgadget@gmail.com","subject":"Re: [PATCH v3] scalar: show progress if stderr refer to a terminal","fromName":"Derrick Stolee","fromEmail":"derrickstolee@github.com","sentAt":"2023-01-11T14:55:05Z","receivedAt":"2023-01-11T14:56:03Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"On 1/11/2023 8:14 AM, ZheNing Hu via GitGitGadget wrote:\n> From: ZheNing Hu <adlternative@gmail.com>\n\n> Range-diff vs v2:\n\n>      -+test_expect_success 'progress without tty' '\n>      ++test_expect_success TTY 'progress without tty' '\n\nI think this addition of the TTY prerequisite is not necessary...\n\n> +test_expect_success TTY 'progress without tty' '\n> +\tenlistment=progress2 &&\n> +\n> +\ttest_config -C to-clone uploadpack.allowfilter true &&\n> +\ttest_config -C to-clone uploadpack.allowanysha1inwant true &&\n> +\n> +\tGIT_PROGRESS_DELAY=0 scalar clone \"file://$(pwd)/to-clone\" \"$enlistment\" 2>stderr &&\n> +\t! grep \"Enumerating objects\" stderr &&\n> +\t! grep \"Updating files\" stderr &&\n> +\tcleanup_clone $enlistment\n> +'\n\n...because the test doesn't use the environment details for\nmimicing a TTY. The point is that stderr is redirected to a\nfile and isatty(2) would report false.\n\nI don't think this is worth a re-roll, though, so I'm happy\nwith this version.\n\nThanks,\n-Stolee\n"},{"id":"470301","messageId":"xmqqh6wu2ow9.fsf@gitster.g","threadId":"58918","inReplyTo":"9d8e38fd-f001-5aa5-ab78-cc6d314df09a@github.com","subject":"Re: [PATCH v3] scalar: show progress if stderr refer to a terminal","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-01-13T19:52:22Z","receivedAt":"2023-01-13T19:52:29Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Derrick Stolee <derrickstolee@github.com> writes:\n\n> On 1/11/2023 8:14 AM, ZheNing Hu via GitGitGadget wrote:\n>> From: ZheNing Hu <adlternative@gmail.com>\n>\n>> Range-diff vs v2:\n>\n>>      -+test_expect_success 'progress without tty' '\n>>      ++test_expect_success TTY 'progress without tty' '\n>\n> I think this addition of the TTY prerequisite is not necessary...\n>\n>> +test_expect_success TTY 'progress without tty' '\n>> +\tenlistment=progress2 &&\n>> +\n>> +\ttest_config -C to-clone uploadpack.allowfilter true &&\n>> +\ttest_config -C to-clone uploadpack.allowanysha1inwant true &&\n>> +\n>> +\tGIT_PROGRESS_DELAY=0 scalar clone \"file://$(pwd)/to-clone\" \"$enlistment\" 2>stderr &&\n>> +\t! grep \"Enumerating objects\" stderr &&\n>> +\t! grep \"Updating files\" stderr &&\n>> +\tcleanup_clone $enlistment\n>> +'\n>\n> ...because the test doesn't use the environment details for\n> mimicing a TTY. The point is that stderr is redirected to a\n> file and isatty(2) would report false.\n\nYup, the prerequisite was uttering misleading.  I may queue it with\nlocal tweaks, but if I forget please send in an update.\n\nThanks.\n\n> I don't think this is worth a re-roll, though, so I'm happy\n> with this version.\n>\n> Thanks,\n> -Stolee\n"}]}