Teach/Fix pull/fetch -q/-v options
PATCH 1/1 Teach/Fix pull/fetch -q/-v options
Implement git-pull --quiet and git-pull --verbose by adding the options to git-pull and fixing verbosity handling in git-fetch.
--- Documentation/merge-options.txt | 8 +++++ builtin-fetch.c | 19 ++++++------ builtin-merge.c | 21 +++++++++---- git-pull.sh | 10 ++++-- parse-options.c | 22 ++++++++++++++ parse-options.h | 6 ++++ t/t5521-pull-options.sh | 60 +++++++++++++++++++++++++++++++++++++++ 7 files changed, 126 insertions(+), 20 deletions(-) create mode 100755 t/t5521-pull-options.sh
Documentation/merge-options.txt +8 -0
@@ -1,3 +1,11 @@ +-q:: +--quiet:: + Operate quietly. + +-v:: +--verbose:: + Be verbose. + --stat:: Show a diffstat at the end of the merge. The diffstat is also controlled by the configuration option merge.stat.
builtin-fetch.c +9 -10
@@ -22,7 +22,7 @@ enum { TAGS_SET = 2 }; -static int append, force, keep, update_head_ok, verbose, quiet; +static int append, force, keep, update_head_ok, verbosity;static int tags =TAGS_DEFAULT ;static const char *depth;static const char *upload_pack;
@@ -30,8 +30,7 @@ static struct strbuf default_rla = STRBUF_INIT;static struct transport *transport;static struct option builtin_fetch_options[] = { -OPT__QUIET (&quiet), -OPT__VERBOSE (&verbose), +OPT__VERBOSITY (&verbosity),OPT_BOOLEAN ('a' ,"append" , &append,"append to .git/FETCH_HEAD instead of overwriting" ), OPT_STRING(0, "upload-pack", &upload_pack, "PATH",
@@ -192,7 +191,6 @@ static int s_update_ref(const char *action,static int update_local_ref (struct ref *ref,const char *remote, -int verbose,char *display) {struct commit *current =NULL , *updated;
@@ -210,7 +208,7 @@ static int update_local_ref(struct ref *ref,die ("object %s not found" ,sha1_to_hex (ref->new_sha1));if (!hashcmp (ref->old_sha1, ref->new_sha1)) { -if (verbose) +if (verbosity >0 )sprintf (display,"= %-*s %-*s -> %s" ,SUMMARY_WIDTH ,"[up to date]" ,REFCOL_WIDTH , remote, pretty_ref);
@@ -366,18 +364,19 @@ static int store_updated_refs(const char *url, const char *remote_name, note);if (ref) - rc |=update_local_ref (ref, what, verbose, note); + rc |=update_local_ref (ref, what, note);else sprintf (note,"* %-*s %-*s -> FETCH_HEAD" ,SUMMARY_WIDTH , *kind ? kind :"branch" ,REFCOL_WIDTH , *what ? what :"HEAD" );if (*note) { -if (!shown_url) { +if (verbosity >=0 && !shown_url) {fprintf (stderr,"From %.*s\n" , url_len, url); shown_url =1 ; } -fprintf (stderr," %s\n" , note); +if (verbosity >=0 ) +fprintf (stderr," %s\n" , note); } }fclose (fp);
@@ -637,9 +636,9 @@ int cmd_fetch(int argc, const char **argv, const char *prefix) remote =remote_get (argv[0 ]); transport =transport_get (remote, remote->url[0 ]); -if (verbose >=2 ) +if (verbosity >=2 ) transport->verbose =1 ; -if (quiet) +if (verbosity <0 ) transport->verbose =-1 ;if (upload_pack)set_option (TRANS_OPT_UPLOADPACK , upload_pack);
builtin-merge.c +14 -7
@@ -50,6 +50,7 @@ static unsigned char head[20], stash[20];static struct strategy **use_strategies;static size_t use_strategies_nr, use_strategies_alloc;static const char *branch; +static int verbosity;static struct strategy all_strategy[] = { {"recursive" ,DEFAULT_TWOHEAD |NO_TRIVIAL },
@@ -171,6 +172,7 @@ static struct option builtin_merge_options[] = {OPT_CALLBACK ('m' ,"message" , &merge_msg,"message" ,"message to be used for the merge commit (if any)" , option_parse_message), +OPT__VERBOSITY (&verbosity), OPT_END() };
@@ -250,7 +252,8 @@ static void restore_state(void)/* This is called when no merge was necessary. */ static void finish_up_to_date (const char *msg) { -printf ("%s%s\n" , squash ?" (nothing to squash)" :"" , msg); +if (verbosity >=0 ) +printf ("%s%s\n" , squash ?" (nothing to squash)" :"" , msg);drop_save (); }
@@ -331,14 +334,15 @@ static void finish(const unsigned char *new_head, const char *msg)if (!msg)strbuf_addstr (&reflog_message,getenv ("GIT_REFLOG_ACTION" ));else { -printf ("%s\n" , msg); +if (verbosity >=0 ) +printf ("%s\n" , msg);strbuf_addf (&reflog_message,"%s: %s" ,getenv ("GIT_REFLOG_ACTION" ), msg); }if (squash) {squash_message (); }else { -if (!merge_msg.len) +if (verbosity >=0 && !merge_msg.len)printf ("No merge message -- not updating HEAD\n" );else {const char *argv_gc_auto[] = {"gc" ,"--auto" ,NULL };
@@ -872,6 +876,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix) argc =parse_options (argc, argv, builtin_merge_options, builtin_merge_usage,0 ); +if (verbosity <0 ) + show_diffstat =0 ;if (squash) {if (!allow_fast_forward)
@@ -1013,10 +1019,11 @@ int cmd_merge(int argc, const char **argv, const char *prefix)strcpy (hex,find_unique_abbrev (head,DEFAULT_ABBREV )); -printf ("Updating %s..%s\n" , - hex, -find_unique_abbrev (remoteheads->item->object.sha1, -DEFAULT_ABBREV )); +if (verbosity >=0 ) +printf ("Updating %s..%s\n" , + hex, +find_unique_abbrev (remoteheads->item->object.sha1, +DEFAULT_ABBREV ));strbuf_addstr (&msg,"Fast forward" );if (have_message) strbuf_addstr(&msg,
git-pull.sh +7 -3
@@ -16,13 +16,17 @@ cd_to_toplevel test -z "$(git ls-files -u)" || die "You are in the middle of a conflicted merge." -strategy_args= no_stat= no_commit= squash= no_ff= log_arg= +strategy_args= no_stat= no_commit= squash= no_ff= log_arg= verbosity= curr_branch=$(git symbolic-ref -q HEAD) curr_branch_short=$(echo "$curr_branch" | sed "s|refs/heads/||") rebase=$(git config --bool branch.$curr_branch_short.rebase) while : do case "$1" in + -q|--quiet) + verbosity=-q ;; + -v|--verbose) + verbosity="$verbosity -v" ;; -n|--no-stat|--no-summary) no_stat=-n ;; --stat|--summary)
@@ -121,7 +125,7 @@ test true = "$rebase" && { "refs/remotes/$origin/$reflist" 2>/dev/null)" } orig_head=$(git rev-parse --verify HEAD 2>/dev/null) -git fetch --update-head-ok "$@" || exit 1 +git fetch $verbosity --update-head-ok "$@" || exit 1 curr_head=$(git rev-parse --verify HEAD 2>/dev/null) if test -n "$orig_head" && test "$curr_head" != "$orig_head"
@@ -182,4 +186,4 @@ test true = "$rebase" && exec git-rebase $strategy_args --onto $merge_head \ ${oldremoteref:-$merge_head} exec git-merge $no_stat $no_commit $squash $no_ff $log_arg $strategy_args \ - "$merge_name" HEAD $merge_head + "$merge_name" HEAD $merge_head $verbosity
parse-options.c +22 -0
@@ -484,6 +484,28 @@ int parse_opt_approxidate_cb(const struct option *opt, const char *arg,return 0 ; } +int parse_opt_verbosity_cb (const struct option *opt,const char *arg, +int unset) +{ +int *target = opt->value; + +if (unset) +/* --no-quiet, --no-verbose */ + *target =0 ; +else if (opt->short_name =='v' ) { +if (*target >=0 ) + (*target)++; +else + *target =1 ; + }else { +if (*target <=0 ) + (*target)--; +else + *target =-1 ; + } +return 0 ; +} +/* * This should really be OPTION_FILENAME type as a part of * parse_options that take prefix to do this while parsing.
parse-options.h +6 -0
@@ -150,9 +150,15 @@ extern int parse_options_end(struct parse_opt_ctx_t *ctx);/*----- some often used options -----*/ extern int parse_opt_abbrev_cb (const struct option *,const char *,int );extern int parse_opt_approxidate_cb (const struct option *,const char *,int ); +extern int parse_opt_verbosity_cb (const struct option *,const char *,int );#define OPT__VERBOSE (var) OPT_BOOLEAN('v', "verbose", (var), "be verbose")#define OPT__QUIET (var) OPT_BOOLEAN('q', "quiet", (var), "be quiet") +#define OPT__VERBOSITY (var) \ + { OPTION_CALLBACK, 'v', "verbose", (var), NULL, "be more verbose", \ + PARSE_OPT_NOARG, &parse_opt_verbosity_cb, 0 }, \ + { OPTION_CALLBACK, 'q', "quiet", (var), NULL, "be more quiet", \ + PARSE_OPT_NOARG, &parse_opt_verbosity_cb, 0 }#define OPT__DRY_RUN (var) OPT_BOOLEAN('n', "dry-run", (var), "dry run")#define OPT__ABBREV (var) \ { OPTION_CALLBACK, 0, "abbrev", (var), "n", \
t/t5521-pull-options.sh new file +60 -0
60 lines not on this page · raw message
Signature · 1 line
1.6.0.2.GIT
Junio,
I think you need to have something like the following applied on top of what's in pu to be able to use "pull -v -v -v" and be able to count the occurrences via parse-options.c. What do you think?
git-pull.sh.b 2008-11-17 11:33:03.000000000 +0100 renamed from git-pull.sh 2008-11-17 11:32:19.000000000 +0100 +1 -1
@@ -26,7 +26,7 @@ -q|--quiet) verbosity=-q ;; -v|--verbose) - verbosity=-v ;; + verbosity="$verbosity -v" ;; -n|--no-stat|--no-summary) no_stat=-n ;; --stat|--summary)
Quoted 3 lines · Tuncer Ayaz
I think you need to have something like the following applied on top of what's in pu to be able to use "pull -v -v -v" and be able to count the occurrences via
parse-options.c. What do you think?
Makes sense, except that as a futureproofing we may be better off doing the same for -q as well.
Quoted 13 lines
git-pull.sh.b 2008-11-17 11:33:03.000000000 +0100 renamed from git-pull.sh 2008-11-17 11:32:19.000000000 +0100 +1
-1@@ -26,7 +26,7 @@ -q|--quiet) verbosity=-q ;; -v|--verbose) - verbosity=-v ;; + verbosity="$verbosity -v" ;; -n|--no-stat|--no-summary) no_stat=-n ;; --stat|--summary)Signed-off-by Tuncer Ayaz <[email protected]>
Quoted 8 lines · Junio C Hamano
Quoted 3 lines · Tuncer Ayaz
I think you need to have something like the following applied on top of what's in pu to be able to use "pull -v -v -v" and be able to count the occurrences via
parse-options.c. What do you think?Makes sense, except that as a futureproofing we may be better off doing the same for -q as well.
What's funny is that my original patch to git-pull.sh had both :).
Quoted 14 lines
Quoted 13 lines
git-pull.sh.b 2008-11-17 11:33:03.000000000 +0100 renamed from git-pull.sh 2008-11-17 11:32:19.000000000 +0100 +1
-1@@ -26,7 +26,7 @@ -q|--quiet) verbosity=-q ;; -v|--verbose) - verbosity=-v ;; + verbosity="$verbosity -v" ;; -n|--no-stat|--no-summary) no_stat=-n ;; --stat|--summary)Signed-off-by Tuncer Ayaz <[email protected]>
Quoted 8 lines · Junio C Hamano
Quoted 3 lines · Tuncer Ayaz
I think you need to have something like the following applied on top of what's in pu to be able to use "pull -v -v -v" and be able to count the occurrences via
parse-options.c. What do you think?Makes sense, except that as a futureproofing we may be better off doing the same for -q as well.
Please see my patch with the following subject arriving here soonish:
"[PATCH] Retain multiple -q/-v occurrences in git pull"
Quoted 14 lines
Quoted 13 lines
git-pull.sh.b 2008-11-17 11:33:03.000000000 +0100 renamed from git-pull.sh 2008-11-17 11:32:19.000000000 +0100 +1
-1@@ -26,7 +26,7 @@ -q|--quiet) verbosity=-q ;; -v|--verbose) - verbosity=-v ;; + verbosity="$verbosity -v" ;; -n|--no-stat|--no-summary) no_stat=-n ;; --stat|--summary)Signed-off-by Tuncer Ayaz <[email protected]>
Quoted 6 lines · Junio C Hamano
Quoted 3 lines · Tuncer Ayaz
I think you need to have something like the following applied on top of what's in pu to be able to use "pull -v -v -v" and be able to count the occurrences via
parse-options.c. What do you think?
I'm just interested why not just optional level argument to verbosity like --verbose=2 or -v2?
Regards,
Constantine
Quoted 9 lines · Constantine Plotnikov
Quoted 6 lines · Junio C Hamano
Quoted 3 lines · Tuncer Ayaz
I think you need to have something like the following applied on top of what's in pu to be able to use "pull -v -v -v" and be able to count the occurrences via
parse-options.c. What do you think?I'm just interested why not just optional level argument to verbosity like --verbose=2 or -v2?
I'm not really sure which one is better but do prefer the "-v -v -v" way as it seems to be common practice in tools that support it. Also I don't want to make git cli different than most other cli tools. This does not mean that common practice is the best choice.
I think allowing an integer param makes our cli worse and allows usage like --verbose=25. verbose=25 is not sane in my personal view.
$ git pull --verbose # same as --verbose=1? $ git pull --verbose=42 # will do the right thing always by AI? $ git pull --verbose=0 # will do what? maybe quiet=1?
I say let's keep it simple so that no one starts getting the idea that it's fine to have more than a handful occurrences of -v or -q.