{"thread":{"id":"15973","subject":"[PATCH] Teach/Fix -q/-v to pull/fetch","startedAt":"2008-10-19T18:17:57Z","lastAt":"2008-10-20T23:52:08Z","messageCount":4,"participants":["Tuncer Ayaz","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"93471","messageId":"1224440277-2469-1-git-send-email-tuncer.ayaz@gmail.com","threadId":"15973","inReplyTo":null,"subject":"[PATCH] Teach/Fix -q/-v to pull/fetch","fromName":"Tuncer Ayaz","fromEmail":"tuncer.ayaz@gmail.com","sentAt":"2008-10-19T18:17:57Z","receivedAt":"2008-10-19T18:17:57Z","isPatch":true,"sender":{"key":"tuncer.ayaz@gmail.com","avatar":null},"body":"After fixing clone -q I noticed that pull -q does not do what\nit's supposed to do and implemented --quiet/--verbose by\nadding it to builtin-merge and fixing two places in builtin-fetch.\n\nI have not touched/adjusted contrib/completion/git-completion.bash\nbut can take a look if wanted. I think it already needs one or two\nadjustments caused by recent --OPTIONS changes in master.\n\nI've tested the following invocations with the below changes applied:\n$ git pull\n$ git pull -q\n$ git pull -v\n\nThis is the next attempt trying to incorporate Junio's\nsuggestions and I'm not sure about the following:\n1) having the same option callback function in both modules\n2) my adaption of the following two lines from\nbuiltin-fetch.c to the new verbosity option:\n    if (verbosity == VERBOSE)\n        transport->verbose = 1;\n    if (verbosity == QUIET)\n        transport->verbose = -1;\n3) my usage of OPTION_CALLBACK. therefore please\ncorrect me if I did it wrong or my cb fun has an\nobvious defect. it may very well have one :)\n\nSigned-off-by: Tuncer Ayaz <tuncer.ayaz@gmail.com>\n---\n Documentation/merge-options.txt |    8 ++++++++\n builtin-fetch.c                 |   35 +++++++++++++++++++++++++----------\n builtin-merge.c                 |   36 +++++++++++++++++++++++++++++-------\n git-pull.sh                     |   10 ++++++++--\n 4 files changed, 70 insertions(+), 19 deletions(-)\n\ndiff --git a/Documentation/merge-options.txt b/Documentation/merge-options.txt\nindex 007909a..427cdef 100644\n--- a/Documentation/merge-options.txt\n+++ b/Documentation/merge-options.txt\n@@ -1,3 +1,11 @@\n+-q::\n+--quiet::\n+\tOperate quietly.\n+\n+-v::\n+--verbose::\n+\tBe verbose.\n+\n --stat::\n \tShow a diffstat at the end of the merge. The diffstat is also\n \tcontrolled by the configuration option merge.stat.\ndiff --git a/builtin-fetch.c b/builtin-fetch.c\nindex ee93d3a..717e833 100644\n--- a/builtin-fetch.c\n+++ b/builtin-fetch.c\n@@ -22,16 +22,31 @@ enum {\n \tTAGS_SET = 2\n };\n \n-static int append, force, keep, update_head_ok, verbose, quiet;\n+static int append, force, keep, update_head_ok;\n static int tags = TAGS_DEFAULT;\n static const char *depth;\n static const char *upload_pack;\n static struct strbuf default_rla = STRBUF_INIT;\n static struct transport *transport;\n+static enum { QUIET, NORMAL, VERBOSE } verbosity = NORMAL;\n+\n+static int option_parse_verbosity(const struct option *opt,\n+\t\t\t  const char *arg, int unset)\n+{\n+\tif (!strcmp(\"quiet\", opt->long_name))\n+\t\tverbosity = QUIET;\n+\telse if (!strcmp(\"verbose\", opt->long_name))\n+\t\tverbosity = VERBOSE;\n+\treturn 0;\n+}\n \n static struct option builtin_fetch_options[] = {\n-\tOPT__QUIET(&quiet),\n-\tOPT__VERBOSE(&verbose),\n+\t{ OPTION_CALLBACK, 'q', \"quiet\", NULL, NULL,\n+\t\t\"operate quietly\",\n+\t\tPARSE_OPT_NOARG, option_parse_verbosity },\n+\t{ OPTION_CALLBACK, 'v', \"verbose\", NULL, NULL,\n+\t\t\"be verbose\",\n+\t\tPARSE_OPT_NOARG, option_parse_verbosity },\n \tOPT_BOOLEAN('a', \"append\", &append,\n \t\t    \"append to .git/FETCH_HEAD instead of overwriting\"),\n \tOPT_STRING(0, \"upload-pack\", &upload_pack, \"PATH\",\n@@ -192,7 +207,6 @@ static int s_update_ref(const char *action,\n \n static int update_local_ref(struct ref *ref,\n \t\t\t    const char *remote,\n-\t\t\t    int verbose,\n \t\t\t    char *display)\n {\n \tstruct commit *current = NULL, *updated;\n@@ -210,7 +224,7 @@ static int update_local_ref(struct ref *ref,\n \t\tdie(\"object %s not found\", sha1_to_hex(ref->new_sha1));\n \n \tif (!hashcmp(ref->old_sha1, ref->new_sha1)) {\n-\t\tif (verbose)\n+\t\tif (verbosity == VERBOSE)\n \t\t\tsprintf(display, \"= %-*s %-*s -> %s\", SUMMARY_WIDTH,\n \t\t\t\t\"[up to date]\", REFCOL_WIDTH, remote,\n \t\t\t\tpretty_ref);\n@@ -366,18 +380,19 @@ static int store_updated_refs(const char *url, const char *remote_name,\n \t\t\tnote);\n \n \t\tif (ref)\n-\t\t\trc |= update_local_ref(ref, what, verbose, note);\n+\t\t\trc |= update_local_ref(ref, what, note);\n \t\telse\n \t\t\tsprintf(note, \"* %-*s %-*s -> FETCH_HEAD\",\n \t\t\t\tSUMMARY_WIDTH, *kind ? kind : \"branch\",\n \t\t\t\t REFCOL_WIDTH, *what ? what : \"HEAD\");\n \t\tif (*note) {\n-\t\t\tif (!shown_url) {\n+\t\t\tif (verbosity > QUIET && !shown_url) {\n \t\t\t\tfprintf(stderr, \"From %.*s\\n\",\n \t\t\t\t\t\turl_len, url);\n \t\t\t\tshown_url = 1;\n \t\t\t}\n-\t\t\tfprintf(stderr, \" %s\\n\", note);\n+\t\t\tif (verbosity > QUIET)\n+\t\t\t\tfprintf(stderr, \" %s\\n\", note);\n \t\t}\n \t}\n \tfclose(fp);\n@@ -622,9 +637,9 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)\n \t\tremote = remote_get(argv[0]);\n \n \ttransport = transport_get(remote, remote->url[0]);\n-\tif (verbose >= 2)\n+\tif (verbosity == VERBOSE)\n \t\ttransport->verbose = 1;\n-\tif (quiet)\n+\tif (verbosity == QUIET)\n \t\ttransport->verbose = -1;\n \tif (upload_pack)\n \t\tset_option(TRANS_OPT_UPLOADPACK, upload_pack);\ndiff --git a/builtin-merge.c b/builtin-merge.c\nindex 5e2b7f1..6966831 100644\n--- a/builtin-merge.c\n+++ b/builtin-merge.c\n@@ -50,6 +50,7 @@ static unsigned char head[20], stash[20];\n static struct strategy **use_strategies;\n static size_t use_strategies_nr, use_strategies_alloc;\n static const char *branch;\n+static enum { QUIET, NORMAL, VERBOSE } verbosity = NORMAL;\n \n static struct strategy all_strategy[] = {\n \t{ \"recursive\",  DEFAULT_TWOHEAD | NO_TRIVIAL },\n@@ -151,7 +152,23 @@ static int option_parse_n(const struct option *opt,\n \treturn 0;\n }\n \n+static int option_parse_verbosity(const struct option *opt,\n+\t\t\t  const char *arg, int unset)\n+{\n+\tif (!strcmp(\"quiet\", opt->long_name))\n+\t\tverbosity = QUIET;\n+\telse if (!strcmp(\"verbose\", opt->long_name))\n+\t\tverbosity = VERBOSE;\n+\treturn 0;\n+}\n+\n static struct option builtin_merge_options[] = {\n+\t{ OPTION_CALLBACK, 'q', \"quiet\", NULL, NULL,\n+\t\t\"operate quietly\",\n+\t\tPARSE_OPT_NOARG, option_parse_verbosity },\n+\t{ OPTION_CALLBACK, 'v', \"verbose\", NULL, NULL,\n+\t\t\"be verbose\",\n+\t\tPARSE_OPT_NOARG, option_parse_verbosity },\n \t{ OPTION_CALLBACK, 'n', NULL, NULL, NULL,\n \t\t\"do not show a diffstat at the end of the merge\",\n \t\tPARSE_OPT_NOARG, option_parse_n },\n@@ -249,7 +266,8 @@ static void restore_state(void)\n /* This is called when no merge was necessary. */\n static void finish_up_to_date(const char *msg)\n {\n-\tprintf(\"%s%s\\n\", squash ? \" (nothing to squash)\" : \"\", msg);\n+\tif (verbosity > QUIET)\n+\t\tprintf(\"%s%s\\n\", squash ? \" (nothing to squash)\" : \"\", msg);\n \tdrop_save();\n }\n \n@@ -330,14 +348,15 @@ static void finish(const unsigned char *new_head, const char *msg)\n \tif (!msg)\n \t\tstrbuf_addstr(&reflog_message, getenv(\"GIT_REFLOG_ACTION\"));\n \telse {\n-\t\tprintf(\"%s\\n\", msg);\n+\t\tif (verbosity > QUIET)\n+\t\t\tprintf(\"%s\\n\", msg);\n \t\tstrbuf_addf(&reflog_message, \"%s: %s\",\n \t\t\tgetenv(\"GIT_REFLOG_ACTION\"), msg);\n \t}\n \tif (squash) {\n \t\tsquash_message();\n \t} else {\n-\t\tif (!merge_msg.len)\n+\t\tif (verbosity > QUIET && !merge_msg.len)\n \t\t\tprintf(\"No merge message -- not updating HEAD\\n\");\n \t\telse {\n \t\t\tconst char *argv_gc_auto[] = { \"gc\", \"--auto\", NULL };\n@@ -871,6 +890,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \n \targc = parse_options(argc, argv, builtin_merge_options,\n \t\t\tbuiltin_merge_usage, 0);\n+\tif (verbosity > QUIET)\n+\t\tshow_diffstat = 0;\n \n \tif (squash) {\n \t\tif (!allow_fast_forward)\n@@ -1012,10 +1033,11 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \n \t\tstrcpy(hex, find_unique_abbrev(head, DEFAULT_ABBREV));\n \n-\t\tprintf(\"Updating %s..%s\\n\",\n-\t\t\thex,\n-\t\t\tfind_unique_abbrev(remoteheads->item->object.sha1,\n-\t\t\tDEFAULT_ABBREV));\n+\t\tif (verbosity > QUIET)\n+\t\t\tprintf(\"Updating %s..%s\\n\",\n+\t\t\t\thex,\n+\t\t\t\tfind_unique_abbrev(remoteheads->item->object.sha1,\n+\t\t\t\tDEFAULT_ABBREV));\n \t\tstrbuf_addstr(&msg, \"Fast forward\");\n \t\tif (have_message)\n \t\t\tstrbuf_addstr(&msg,\ndiff --git a/git-pull.sh b/git-pull.sh\nindex 75c3610..8e25d44 100755\n--- a/git-pull.sh\n+++ b/git-pull.sh\n@@ -16,6 +16,7 @@ cd_to_toplevel\n test -z \"$(git ls-files -u)\" ||\n \tdie \"You are in the middle of a conflicted merge.\"\n \n+quiet= verbose=\n strategy_args= no_stat= no_commit= squash= no_ff= log_arg=\n curr_branch=$(git symbolic-ref -q HEAD)\n curr_branch_short=$(echo \"$curr_branch\" | sed \"s|refs/heads/||\")\n@@ -23,6 +24,10 @@ rebase=$(git config --bool branch.$curr_branch_short.rebase)\n while :\n do\n \tcase \"$1\" in\n+\t-q|--quiet)\n+\t\tquiet=-q ;;\n+\t-v|--verbose)\n+\t\tverbose=-v ;;\n \t-n|--no-stat|--no-summary)\n \t\tno_stat=-n ;;\n \t--stat|--summary)\n@@ -121,7 +126,7 @@ test true = \"$rebase\" && {\n \t\t\"refs/remotes/$origin/$reflist\" 2>/dev/null)\"\n }\n orig_head=$(git rev-parse --verify HEAD 2>/dev/null)\n-git fetch --update-head-ok \"$@\" || exit 1\n+git fetch $verbose $quiet --update-head-ok \"$@\" || exit 1\n \n curr_head=$(git rev-parse --verify HEAD 2>/dev/null)\n if test \"$curr_head\" != \"$orig_head\"\n@@ -181,5 +186,6 @@ merge_name=$(git fmt-merge-msg $log_arg <\"$GIT_DIR/FETCH_HEAD\") || exit\n test true = \"$rebase\" &&\n \texec git-rebase $strategy_args --onto $merge_head \\\n \t${oldremoteref:-$merge_head}\n-exec git-merge $no_stat $no_commit $squash $no_ff $log_arg $strategy_args \\\n+exec git-merge $quiet $verbose $no_stat $no_commit \\\n+\t$squash $no_ff $log_arg $strategy_args \\\n \t\"$merge_name\" HEAD $merge_head\n-- \n1.6.0.2.GIT\n"},{"id":"93476","messageId":"4ac8254d0810191133v79ed73b7tf09a282f44d302dd@mail.gmail.com","threadId":"15973","inReplyTo":"1224440277-2469-1-git-send-email-tuncer.ayaz@gmail.com","subject":"Re: [PATCH] Teach/Fix -q/-v to pull/fetch","fromName":"Tuncer Ayaz","fromEmail":"tuncer.ayaz@gmail.com","sentAt":"2008-10-19T18:33:38Z","receivedAt":"2008-10-19T18:33:38Z","isPatch":true,"sender":{"key":"tuncer.ayaz@gmail.com","avatar":null},"body":"On Sun, Oct 19, 2008 at 8:17 PM, Tuncer Ayaz <tuncer.ayaz@gmail.com> wrote:\n> After fixing clone -q I noticed that pull -q does not do what\n> it's supposed to do and implemented --quiet/--verbose by\n> adding it to builtin-merge and fixing two places in builtin-fetch.\n>\n> I have not touched/adjusted contrib/completion/git-completion.bash\n> but can take a look if wanted. I think it already needs one or two\n> adjustments caused by recent --OPTIONS changes in master.\n>\n> I've tested the following invocations with the below changes applied:\n> $ git pull\n> $ git pull -q\n> $ git pull -v\n>\n> This is the next attempt trying to incorporate Junio's\n> suggestions and I'm not sure about the following:\n> 1) having the same option callback function in both modules\n> 2) my adaption of the following two lines from\n> builtin-fetch.c to the new verbosity option:\n>    if (verbosity == VERBOSE)\n>        transport->verbose = 1;\n>    if (verbosity == QUIET)\n>        transport->verbose = -1;\n> 3) my usage of OPTION_CALLBACK. therefore please\n> correct me if I did it wrong or my cb fun has an\n> obvious defect. it may very well have one :)\n\nit doesn't work as I expected when you supply -q and -v.\nI have to redo it, I guess.\n\n> Signed-off-by: Tuncer Ayaz <tuncer.ayaz@gmail.com>\n> ---\n>  Documentation/merge-options.txt |    8 ++++++++\n>  builtin-fetch.c                 |   35 +++++++++++++++++++++++++----------\n>  builtin-merge.c                 |   36 +++++++++++++++++++++++++++++-------\n>  git-pull.sh                     |   10 ++++++++--\n>  4 files changed, 70 insertions(+), 19 deletions(-)\n>\n> diff --git a/Documentation/merge-options.txt b/Documentation/merge-options.txt\n> index 007909a..427cdef 100644\n> --- a/Documentation/merge-options.txt\n> +++ b/Documentation/merge-options.txt\n> @@ -1,3 +1,11 @@\n> +-q::\n> +--quiet::\n> +       Operate quietly.\n> +\n> +-v::\n> +--verbose::\n> +       Be verbose.\n> +\n>  --stat::\n>        Show a diffstat at the end of the merge. The diffstat is also\n>        controlled by the configuration option merge.stat.\n> diff --git a/builtin-fetch.c b/builtin-fetch.c\n> index ee93d3a..717e833 100644\n> --- a/builtin-fetch.c\n> +++ b/builtin-fetch.c\n> @@ -22,16 +22,31 @@ enum {\n>        TAGS_SET = 2\n>  };\n>\n> -static int append, force, keep, update_head_ok, verbose, quiet;\n> +static int append, force, keep, update_head_ok;\n>  static int tags = TAGS_DEFAULT;\n>  static const char *depth;\n>  static const char *upload_pack;\n>  static struct strbuf default_rla = STRBUF_INIT;\n>  static struct transport *transport;\n> +static enum { QUIET, NORMAL, VERBOSE } verbosity = NORMAL;\n> +\n> +static int option_parse_verbosity(const struct option *opt,\n> +                         const char *arg, int unset)\n> +{\n> +       if (!strcmp(\"quiet\", opt->long_name))\n> +               verbosity = QUIET;\n> +       else if (!strcmp(\"verbose\", opt->long_name))\n> +               verbosity = VERBOSE;\n> +       return 0;\n> +}\n>\n>  static struct option builtin_fetch_options[] = {\n> -       OPT__QUIET(&quiet),\n> -       OPT__VERBOSE(&verbose),\n> +       { OPTION_CALLBACK, 'q', \"quiet\", NULL, NULL,\n> +               \"operate quietly\",\n> +               PARSE_OPT_NOARG, option_parse_verbosity },\n> +       { OPTION_CALLBACK, 'v', \"verbose\", NULL, NULL,\n> +               \"be verbose\",\n> +               PARSE_OPT_NOARG, option_parse_verbosity },\n>        OPT_BOOLEAN('a', \"append\", &append,\n>                    \"append to .git/FETCH_HEAD instead of overwriting\"),\n>        OPT_STRING(0, \"upload-pack\", &upload_pack, \"PATH\",\n> @@ -192,7 +207,6 @@ static int s_update_ref(const char *action,\n>\n>  static int update_local_ref(struct ref *ref,\n>                            const char *remote,\n> -                           int verbose,\n>                            char *display)\n>  {\n>        struct commit *current = NULL, *updated;\n> @@ -210,7 +224,7 @@ static int update_local_ref(struct ref *ref,\n>                die(\"object %s not found\", sha1_to_hex(ref->new_sha1));\n>\n>        if (!hashcmp(ref->old_sha1, ref->new_sha1)) {\n> -               if (verbose)\n> +               if (verbosity == VERBOSE)\n>                        sprintf(display, \"= %-*s %-*s -> %s\", SUMMARY_WIDTH,\n>                                \"[up to date]\", REFCOL_WIDTH, remote,\n>                                pretty_ref);\n> @@ -366,18 +380,19 @@ static int store_updated_refs(const char *url, const char *remote_name,\n>                        note);\n>\n>                if (ref)\n> -                       rc |= update_local_ref(ref, what, verbose, note);\n> +                       rc |= update_local_ref(ref, what, note);\n>                else\n>                        sprintf(note, \"* %-*s %-*s -> FETCH_HEAD\",\n>                                SUMMARY_WIDTH, *kind ? kind : \"branch\",\n>                                 REFCOL_WIDTH, *what ? what : \"HEAD\");\n>                if (*note) {\n> -                       if (!shown_url) {\n> +                       if (verbosity > QUIET && !shown_url) {\n>                                fprintf(stderr, \"From %.*s\\n\",\n>                                                url_len, url);\n>                                shown_url = 1;\n>                        }\n> -                       fprintf(stderr, \" %s\\n\", note);\n> +                       if (verbosity > QUIET)\n> +                               fprintf(stderr, \" %s\\n\", note);\n>                }\n>        }\n>        fclose(fp);\n> @@ -622,9 +637,9 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)\n>                remote = remote_get(argv[0]);\n>\n>        transport = transport_get(remote, remote->url[0]);\n> -       if (verbose >= 2)\n> +       if (verbosity == VERBOSE)\n>                transport->verbose = 1;\n> -       if (quiet)\n> +       if (verbosity == QUIET)\n>                transport->verbose = -1;\n>        if (upload_pack)\n>                set_option(TRANS_OPT_UPLOADPACK, upload_pack);\n> diff --git a/builtin-merge.c b/builtin-merge.c\n> index 5e2b7f1..6966831 100644\n> --- a/builtin-merge.c\n> +++ b/builtin-merge.c\n> @@ -50,6 +50,7 @@ static unsigned char head[20], stash[20];\n>  static struct strategy **use_strategies;\n>  static size_t use_strategies_nr, use_strategies_alloc;\n>  static const char *branch;\n> +static enum { QUIET, NORMAL, VERBOSE } verbosity = NORMAL;\n>\n>  static struct strategy all_strategy[] = {\n>        { \"recursive\",  DEFAULT_TWOHEAD | NO_TRIVIAL },\n> @@ -151,7 +152,23 @@ static int option_parse_n(const struct option *opt,\n>        return 0;\n>  }\n>\n> +static int option_parse_verbosity(const struct option *opt,\n> +                         const char *arg, int unset)\n> +{\n> +       if (!strcmp(\"quiet\", opt->long_name))\n> +               verbosity = QUIET;\n> +       else if (!strcmp(\"verbose\", opt->long_name))\n> +               verbosity = VERBOSE;\n> +       return 0;\n> +}\n> +\n>  static struct option builtin_merge_options[] = {\n> +       { OPTION_CALLBACK, 'q', \"quiet\", NULL, NULL,\n> +               \"operate quietly\",\n> +               PARSE_OPT_NOARG, option_parse_verbosity },\n> +       { OPTION_CALLBACK, 'v', \"verbose\", NULL, NULL,\n> +               \"be verbose\",\n> +               PARSE_OPT_NOARG, option_parse_verbosity },\n>        { OPTION_CALLBACK, 'n', NULL, NULL, NULL,\n>                \"do not show a diffstat at the end of the merge\",\n>                PARSE_OPT_NOARG, option_parse_n },\n> @@ -249,7 +266,8 @@ static void restore_state(void)\n>  /* This is called when no merge was necessary. */\n>  static void finish_up_to_date(const char *msg)\n>  {\n> -       printf(\"%s%s\\n\", squash ? \" (nothing to squash)\" : \"\", msg);\n> +       if (verbosity > QUIET)\n> +               printf(\"%s%s\\n\", squash ? \" (nothing to squash)\" : \"\", msg);\n>        drop_save();\n>  }\n>\n> @@ -330,14 +348,15 @@ static void finish(const unsigned char *new_head, const char *msg)\n>        if (!msg)\n>                strbuf_addstr(&reflog_message, getenv(\"GIT_REFLOG_ACTION\"));\n>        else {\n> -               printf(\"%s\\n\", msg);\n> +               if (verbosity > QUIET)\n> +                       printf(\"%s\\n\", msg);\n>                strbuf_addf(&reflog_message, \"%s: %s\",\n>                        getenv(\"GIT_REFLOG_ACTION\"), msg);\n>        }\n>        if (squash) {\n>                squash_message();\n>        } else {\n> -               if (!merge_msg.len)\n> +               if (verbosity > QUIET && !merge_msg.len)\n>                        printf(\"No merge message -- not updating HEAD\\n\");\n>                else {\n>                        const char *argv_gc_auto[] = { \"gc\", \"--auto\", NULL };\n> @@ -871,6 +890,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n>\n>        argc = parse_options(argc, argv, builtin_merge_options,\n>                        builtin_merge_usage, 0);\n> +       if (verbosity > QUIET)\n> +               show_diffstat = 0;\n>\n>        if (squash) {\n>                if (!allow_fast_forward)\n> @@ -1012,10 +1033,11 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n>\n>                strcpy(hex, find_unique_abbrev(head, DEFAULT_ABBREV));\n>\n> -               printf(\"Updating %s..%s\\n\",\n> -                       hex,\n> -                       find_unique_abbrev(remoteheads->item->object.sha1,\n> -                       DEFAULT_ABBREV));\n> +               if (verbosity > QUIET)\n> +                       printf(\"Updating %s..%s\\n\",\n> +                               hex,\n> +                               find_unique_abbrev(remoteheads->item->object.sha1,\n> +                               DEFAULT_ABBREV));\n>                strbuf_addstr(&msg, \"Fast forward\");\n>                if (have_message)\n>                        strbuf_addstr(&msg,\n> diff --git a/git-pull.sh b/git-pull.sh\n> index 75c3610..8e25d44 100755\n> --- a/git-pull.sh\n> +++ b/git-pull.sh\n> @@ -16,6 +16,7 @@ cd_to_toplevel\n>  test -z \"$(git ls-files -u)\" ||\n>        die \"You are in the middle of a conflicted merge.\"\n>\n> +quiet= verbose=\n>  strategy_args= no_stat= no_commit= squash= no_ff= log_arg=\n>  curr_branch=$(git symbolic-ref -q HEAD)\n>  curr_branch_short=$(echo \"$curr_branch\" | sed \"s|refs/heads/||\")\n> @@ -23,6 +24,10 @@ rebase=$(git config --bool branch.$curr_branch_short.rebase)\n>  while :\n>  do\n>        case \"$1\" in\n> +       -q|--quiet)\n> +               quiet=-q ;;\n> +       -v|--verbose)\n> +               verbose=-v ;;\n>        -n|--no-stat|--no-summary)\n>                no_stat=-n ;;\n>        --stat|--summary)\n> @@ -121,7 +126,7 @@ test true = \"$rebase\" && {\n>                \"refs/remotes/$origin/$reflist\" 2>/dev/null)\"\n>  }\n>  orig_head=$(git rev-parse --verify HEAD 2>/dev/null)\n> -git fetch --update-head-ok \"$@\" || exit 1\n> +git fetch $verbose $quiet --update-head-ok \"$@\" || exit 1\n>\n>  curr_head=$(git rev-parse --verify HEAD 2>/dev/null)\n>  if test \"$curr_head\" != \"$orig_head\"\n> @@ -181,5 +186,6 @@ merge_name=$(git fmt-merge-msg $log_arg <\"$GIT_DIR/FETCH_HEAD\") || exit\n>  test true = \"$rebase\" &&\n>        exec git-rebase $strategy_args --onto $merge_head \\\n>        ${oldremoteref:-$merge_head}\n> -exec git-merge $no_stat $no_commit $squash $no_ff $log_arg $strategy_args \\\n> +exec git-merge $quiet $verbose $no_stat $no_commit \\\n> +       $squash $no_ff $log_arg $strategy_args \\\n>        \"$merge_name\" HEAD $merge_head\n> --\n> 1.6.0.2.GIT\n>\n>\n"},{"id":"93475","messageId":"4ac8254d0810191137n5b4eb288o6908ba460b6880e4@mail.gmail.com","threadId":"15973","inReplyTo":"4ac8254d0810191133v79ed73b7tf09a282f44d302dd@mail.gmail.com","subject":"Re: [PATCH] Teach/Fix -q/-v to pull/fetch","fromName":"Tuncer Ayaz","fromEmail":"tuncer.ayaz@gmail.com","sentAt":"2008-10-19T18:37:02Z","receivedAt":"2008-10-19T18:37:02Z","isPatch":true,"sender":{"key":"tuncer.ayaz@gmail.com","avatar":null},"body":"On Sun, Oct 19, 2008 at 8:33 PM, Tuncer Ayaz <tuncer.ayaz@gmail.com> wrote:\n> On Sun, Oct 19, 2008 at 8:17 PM, Tuncer Ayaz <tuncer.ayaz@gmail.com> wrote:\n>> After fixing clone -q I noticed that pull -q does not do what\n>> it's supposed to do and implemented --quiet/--verbose by\n>> adding it to builtin-merge and fixing two places in builtin-fetch.\n>>\n>> I have not touched/adjusted contrib/completion/git-completion.bash\n>> but can take a look if wanted. I think it already needs one or two\n>> adjustments caused by recent --OPTIONS changes in master.\n>>\n>> I've tested the following invocations with the below changes applied:\n>> $ git pull\n>> $ git pull -q\n>> $ git pull -v\n>>\n>> This is the next attempt trying to incorporate Junio's\n>> suggestions and I'm not sure about the following:\n>> 1) having the same option callback function in both modules\n>> 2) my adaption of the following two lines from\n>> builtin-fetch.c to the new verbosity option:\n>>    if (verbosity == VERBOSE)\n>>        transport->verbose = 1;\n>>    if (verbosity == QUIET)\n>>        transport->verbose = -1;\n>> 3) my usage of OPTION_CALLBACK. therefore please\n>> correct me if I did it wrong or my cb fun has an\n>> obvious defect. it may very well have one :)\n>\n> it doesn't work as I expected when you supply -q and -v.\n> I have to redo it, I guess.\n\nJunio, what do you think?\nif I call \"git pull -q -v\" or \"git pull -v -q\" verbosity will be VERBOSE.\nis that ok or should I make sure that the last one overrides\nverbosity?\n\n>> Signed-off-by: Tuncer Ayaz <tuncer.ayaz@gmail.com>\n>> ---\n>>  Documentation/merge-options.txt |    8 ++++++++\n>>  builtin-fetch.c                 |   35 +++++++++++++++++++++++++----------\n>>  builtin-merge.c                 |   36 +++++++++++++++++++++++++++++-------\n>>  git-pull.sh                     |   10 ++++++++--\n>>  4 files changed, 70 insertions(+), 19 deletions(-)\n>>\n>> diff --git a/Documentation/merge-options.txt b/Documentation/merge-options.txt\n>> index 007909a..427cdef 100644\n>> --- a/Documentation/merge-options.txt\n>> +++ b/Documentation/merge-options.txt\n>> @@ -1,3 +1,11 @@\n>> +-q::\n>> +--quiet::\n>> +       Operate quietly.\n>> +\n>> +-v::\n>> +--verbose::\n>> +       Be verbose.\n>> +\n>>  --stat::\n>>        Show a diffstat at the end of the merge. The diffstat is also\n>>        controlled by the configuration option merge.stat.\n>> diff --git a/builtin-fetch.c b/builtin-fetch.c\n>> index ee93d3a..717e833 100644\n>> --- a/builtin-fetch.c\n>> +++ b/builtin-fetch.c\n>> @@ -22,16 +22,31 @@ enum {\n>>        TAGS_SET = 2\n>>  };\n>>\n>> -static int append, force, keep, update_head_ok, verbose, quiet;\n>> +static int append, force, keep, update_head_ok;\n>>  static int tags = TAGS_DEFAULT;\n>>  static const char *depth;\n>>  static const char *upload_pack;\n>>  static struct strbuf default_rla = STRBUF_INIT;\n>>  static struct transport *transport;\n>> +static enum { QUIET, NORMAL, VERBOSE } verbosity = NORMAL;\n>> +\n>> +static int option_parse_verbosity(const struct option *opt,\n>> +                         const char *arg, int unset)\n>> +{\n>> +       if (!strcmp(\"quiet\", opt->long_name))\n>> +               verbosity = QUIET;\n>> +       else if (!strcmp(\"verbose\", opt->long_name))\n>> +               verbosity = VERBOSE;\n>> +       return 0;\n>> +}\n>>\n>>  static struct option builtin_fetch_options[] = {\n>> -       OPT__QUIET(&quiet),\n>> -       OPT__VERBOSE(&verbose),\n>> +       { OPTION_CALLBACK, 'q', \"quiet\", NULL, NULL,\n>> +               \"operate quietly\",\n>> +               PARSE_OPT_NOARG, option_parse_verbosity },\n>> +       { OPTION_CALLBACK, 'v', \"verbose\", NULL, NULL,\n>> +               \"be verbose\",\n>> +               PARSE_OPT_NOARG, option_parse_verbosity },\n>>        OPT_BOOLEAN('a', \"append\", &append,\n>>                    \"append to .git/FETCH_HEAD instead of overwriting\"),\n>>        OPT_STRING(0, \"upload-pack\", &upload_pack, \"PATH\",\n>> @@ -192,7 +207,6 @@ static int s_update_ref(const char *action,\n>>\n>>  static int update_local_ref(struct ref *ref,\n>>                            const char *remote,\n>> -                           int verbose,\n>>                            char *display)\n>>  {\n>>        struct commit *current = NULL, *updated;\n>> @@ -210,7 +224,7 @@ static int update_local_ref(struct ref *ref,\n>>                die(\"object %s not found\", sha1_to_hex(ref->new_sha1));\n>>\n>>        if (!hashcmp(ref->old_sha1, ref->new_sha1)) {\n>> -               if (verbose)\n>> +               if (verbosity == VERBOSE)\n>>                        sprintf(display, \"= %-*s %-*s -> %s\", SUMMARY_WIDTH,\n>>                                \"[up to date]\", REFCOL_WIDTH, remote,\n>>                                pretty_ref);\n>> @@ -366,18 +380,19 @@ static int store_updated_refs(const char *url, const char *remote_name,\n>>                        note);\n>>\n>>                if (ref)\n>> -                       rc |= update_local_ref(ref, what, verbose, note);\n>> +                       rc |= update_local_ref(ref, what, note);\n>>                else\n>>                        sprintf(note, \"* %-*s %-*s -> FETCH_HEAD\",\n>>                                SUMMARY_WIDTH, *kind ? kind : \"branch\",\n>>                                 REFCOL_WIDTH, *what ? what : \"HEAD\");\n>>                if (*note) {\n>> -                       if (!shown_url) {\n>> +                       if (verbosity > QUIET && !shown_url) {\n>>                                fprintf(stderr, \"From %.*s\\n\",\n>>                                                url_len, url);\n>>                                shown_url = 1;\n>>                        }\n>> -                       fprintf(stderr, \" %s\\n\", note);\n>> +                       if (verbosity > QUIET)\n>> +                               fprintf(stderr, \" %s\\n\", note);\n>>                }\n>>        }\n>>        fclose(fp);\n>> @@ -622,9 +637,9 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)\n>>                remote = remote_get(argv[0]);\n>>\n>>        transport = transport_get(remote, remote->url[0]);\n>> -       if (verbose >= 2)\n>> +       if (verbosity == VERBOSE)\n>>                transport->verbose = 1;\n>> -       if (quiet)\n>> +       if (verbosity == QUIET)\n>>                transport->verbose = -1;\n>>        if (upload_pack)\n>>                set_option(TRANS_OPT_UPLOADPACK, upload_pack);\n>> diff --git a/builtin-merge.c b/builtin-merge.c\n>> index 5e2b7f1..6966831 100644\n>> --- a/builtin-merge.c\n>> +++ b/builtin-merge.c\n>> @@ -50,6 +50,7 @@ static unsigned char head[20], stash[20];\n>>  static struct strategy **use_strategies;\n>>  static size_t use_strategies_nr, use_strategies_alloc;\n>>  static const char *branch;\n>> +static enum { QUIET, NORMAL, VERBOSE } verbosity = NORMAL;\n>>\n>>  static struct strategy all_strategy[] = {\n>>        { \"recursive\",  DEFAULT_TWOHEAD | NO_TRIVIAL },\n>> @@ -151,7 +152,23 @@ static int option_parse_n(const struct option *opt,\n>>        return 0;\n>>  }\n>>\n>> +static int option_parse_verbosity(const struct option *opt,\n>> +                         const char *arg, int unset)\n>> +{\n>> +       if (!strcmp(\"quiet\", opt->long_name))\n>> +               verbosity = QUIET;\n>> +       else if (!strcmp(\"verbose\", opt->long_name))\n>> +               verbosity = VERBOSE;\n>> +       return 0;\n>> +}\n>> +\n>>  static struct option builtin_merge_options[] = {\n>> +       { OPTION_CALLBACK, 'q', \"quiet\", NULL, NULL,\n>> +               \"operate quietly\",\n>> +               PARSE_OPT_NOARG, option_parse_verbosity },\n>> +       { OPTION_CALLBACK, 'v', \"verbose\", NULL, NULL,\n>> +               \"be verbose\",\n>> +               PARSE_OPT_NOARG, option_parse_verbosity },\n>>        { OPTION_CALLBACK, 'n', NULL, NULL, NULL,\n>>                \"do not show a diffstat at the end of the merge\",\n>>                PARSE_OPT_NOARG, option_parse_n },\n>> @@ -249,7 +266,8 @@ static void restore_state(void)\n>>  /* This is called when no merge was necessary. */\n>>  static void finish_up_to_date(const char *msg)\n>>  {\n>> -       printf(\"%s%s\\n\", squash ? \" (nothing to squash)\" : \"\", msg);\n>> +       if (verbosity > QUIET)\n>> +               printf(\"%s%s\\n\", squash ? \" (nothing to squash)\" : \"\", msg);\n>>        drop_save();\n>>  }\n>>\n>> @@ -330,14 +348,15 @@ static void finish(const unsigned char *new_head, const char *msg)\n>>        if (!msg)\n>>                strbuf_addstr(&reflog_message, getenv(\"GIT_REFLOG_ACTION\"));\n>>        else {\n>> -               printf(\"%s\\n\", msg);\n>> +               if (verbosity > QUIET)\n>> +                       printf(\"%s\\n\", msg);\n>>                strbuf_addf(&reflog_message, \"%s: %s\",\n>>                        getenv(\"GIT_REFLOG_ACTION\"), msg);\n>>        }\n>>        if (squash) {\n>>                squash_message();\n>>        } else {\n>> -               if (!merge_msg.len)\n>> +               if (verbosity > QUIET && !merge_msg.len)\n>>                        printf(\"No merge message -- not updating HEAD\\n\");\n>>                else {\n>>                        const char *argv_gc_auto[] = { \"gc\", \"--auto\", NULL };\n>> @@ -871,6 +890,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n>>\n>>        argc = parse_options(argc, argv, builtin_merge_options,\n>>                        builtin_merge_usage, 0);\n>> +       if (verbosity > QUIET)\n>> +               show_diffstat = 0;\n>>\n>>        if (squash) {\n>>                if (!allow_fast_forward)\n>> @@ -1012,10 +1033,11 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n>>\n>>                strcpy(hex, find_unique_abbrev(head, DEFAULT_ABBREV));\n>>\n>> -               printf(\"Updating %s..%s\\n\",\n>> -                       hex,\n>> -                       find_unique_abbrev(remoteheads->item->object.sha1,\n>> -                       DEFAULT_ABBREV));\n>> +               if (verbosity > QUIET)\n>> +                       printf(\"Updating %s..%s\\n\",\n>> +                               hex,\n>> +                               find_unique_abbrev(remoteheads->item->object.sha1,\n>> +                               DEFAULT_ABBREV));\n>>                strbuf_addstr(&msg, \"Fast forward\");\n>>                if (have_message)\n>>                        strbuf_addstr(&msg,\n>> diff --git a/git-pull.sh b/git-pull.sh\n>> index 75c3610..8e25d44 100755\n>> --- a/git-pull.sh\n>> +++ b/git-pull.sh\n>> @@ -16,6 +16,7 @@ cd_to_toplevel\n>>  test -z \"$(git ls-files -u)\" ||\n>>        die \"You are in the middle of a conflicted merge.\"\n>>\n>> +quiet= verbose=\n>>  strategy_args= no_stat= no_commit= squash= no_ff= log_arg=\n>>  curr_branch=$(git symbolic-ref -q HEAD)\n>>  curr_branch_short=$(echo \"$curr_branch\" | sed \"s|refs/heads/||\")\n>> @@ -23,6 +24,10 @@ rebase=$(git config --bool branch.$curr_branch_short.rebase)\n>>  while :\n>>  do\n>>        case \"$1\" in\n>> +       -q|--quiet)\n>> +               quiet=-q ;;\n>> +       -v|--verbose)\n>> +               verbose=-v ;;\n>>        -n|--no-stat|--no-summary)\n>>                no_stat=-n ;;\n>>        --stat|--summary)\n>> @@ -121,7 +126,7 @@ test true = \"$rebase\" && {\n>>                \"refs/remotes/$origin/$reflist\" 2>/dev/null)\"\n>>  }\n>>  orig_head=$(git rev-parse --verify HEAD 2>/dev/null)\n>> -git fetch --update-head-ok \"$@\" || exit 1\n>> +git fetch $verbose $quiet --update-head-ok \"$@\" || exit 1\n>>\n>>  curr_head=$(git rev-parse --verify HEAD 2>/dev/null)\n>>  if test \"$curr_head\" != \"$orig_head\"\n>> @@ -181,5 +186,6 @@ merge_name=$(git fmt-merge-msg $log_arg <\"$GIT_DIR/FETCH_HEAD\") || exit\n>>  test true = \"$rebase\" &&\n>>        exec git-rebase $strategy_args --onto $merge_head \\\n>>        ${oldremoteref:-$merge_head}\n>> -exec git-merge $no_stat $no_commit $squash $no_ff $log_arg $strategy_args \\\n>> +exec git-merge $quiet $verbose $no_stat $no_commit \\\n>> +       $squash $no_ff $log_arg $strategy_args \\\n>>        \"$merge_name\" HEAD $merge_head\n>> --\n>> 1.6.0.2.GIT\n>>\n>>\n>\n"},{"id":"93565","messageId":"7v1vya3jvb.fsf@gitster.siamese.dyndns.org","threadId":"15973","inReplyTo":"4ac8254d0810191133v79ed73b7tf09a282f44d302dd@mail.gmail.com","subject":"Re: [PATCH] Teach/Fix -q/-v to pull/fetch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-10-20T23:52:08Z","receivedAt":"2008-10-20T23:52:08Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Tuncer Ayaz\" <tuncer.ayaz@gmail.com> writes:\n\n> it doesn't work as I expected when you supply -q and -v.\n> I have to redo it, I guess.\n\nProbably adding a few new tests to one of the test scripts in t/ is in\norder, then.\n"}]}