@matheusbsbs / matheus-bagliano / commits / 7f87aff22c
Fork 0

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

Tuncer Ayaz committed Nov 15, 2008 at 01:14 UTC 7f87aff22c0232a5ce327ea3d2923776936c97f4
7 files changed +126 -20
Documentation/merge-options.txt
+8
@@ -1,3 +1,11 @@
1 +-q::
2 +--quiet::
3 + Operate quietly.
4 +
5 +-v::
6 +--verbose::
7 + Be verbose.
8 +
9 --stat::
10 Show a diffstat at the end of the merge. The diffstat is also
11 controlled by the configuration option merge.stat.
builtin-fetch.c
+9 -10
@@ -22,7 +22,7 @@ enum {
22 TAGS_SET = 2
23 };
24
25 -static int append, force, keep, update_head_ok, verbose, quiet;
25 +static int append, force, keep, update_head_ok, verbosity;
26 static int tags = TAGS_DEFAULT;
27 static const char *depth;
28 static const char *upload_pack;
@@ -30,8 +30,7 @@ static struct strbuf default_rla = STRBUF_INIT;
30 static struct transport *transport;
31
32 static struct option builtin_fetch_options[] = {
33 - OPT__QUIET(&quiet),
34 - OPT__VERBOSE(&verbose),
33 + OPT__VERBOSITY(&verbosity),
34 OPT_BOOLEAN('a', "append", &append,
35 "append to .git/FETCH_HEAD instead of overwriting"),
36 OPT_STRING(0, "upload-pack", &upload_pack, "PATH",
@@ -192,7 +191,6 @@ static int s_update_ref(const char *action,
191
192 static int update_local_ref(struct ref *ref,
193 const char *remote,
195 - int verbose,
194 char *display)
195 {
196 struct commit *current = NULL, *updated;
@@ -210,7 +208,7 @@ static int update_local_ref(struct ref *ref,
208 die("object %s not found", sha1_to_hex(ref->new_sha1));
209
210 if (!hashcmp(ref->old_sha1, ref->new_sha1)) {
213 - if (verbose)
211 + if (verbosity > 0)
212 sprintf(display, "= %-*s %-*s -> %s", SUMMARY_WIDTH,
213 "[up to date]", REFCOL_WIDTH, remote,
214 pretty_ref);
@@ -366,18 +364,19 @@ static int store_updated_refs(const char *url, const char *remote_name,
364 note);
365
366 if (ref)
369 - rc |= update_local_ref(ref, what, verbose, note);
367 + rc |= update_local_ref(ref, what, note);
368 else
369 sprintf(note, "* %-*s %-*s -> FETCH_HEAD",
370 SUMMARY_WIDTH, *kind ? kind : "branch",
371 REFCOL_WIDTH, *what ? what : "HEAD");
372 if (*note) {
375 - if (!shown_url) {
373 + if (verbosity >= 0 && !shown_url) {
374 fprintf(stderr, "From %.*s\n",
375 url_len, url);
376 shown_url = 1;
377 }
380 - fprintf(stderr, " %s\n", note);
378 + if (verbosity >= 0)
379 + fprintf(stderr, " %s\n", note);
380 }
381 }
382 fclose(fp);
@@ -637,9 +636,9 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
636 remote = remote_get(argv[0]);
637
638 transport = transport_get(remote, remote->url[0]);
640 - if (verbose >= 2)
639 + if (verbosity >= 2)
640 transport->verbose = 1;
642 - if (quiet)
641 + if (verbosity < 0)
642 transport->verbose = -1;
643 if (upload_pack)
644 set_option(TRANS_OPT_UPLOADPACK, upload_pack);
builtin-merge.c
+14 -7
@@ -50,6 +50,7 @@ static unsigned char head[20], stash[20];
50 static struct strategy **use_strategies;
51 static size_t use_strategies_nr, use_strategies_alloc;
52 static const char *branch;
53 +static int verbosity;
54
55 static struct strategy all_strategy[] = {
56 { "recursive", DEFAULT_TWOHEAD | NO_TRIVIAL },
@@ -171,6 +172,7 @@ static struct option builtin_merge_options[] = {
172 OPT_CALLBACK('m', "message", &merge_msg, "message",
173 "message to be used for the merge commit (if any)",
174 option_parse_message),
175 + OPT__VERBOSITY(&verbosity),
176 OPT_END()
177 };
178
@@ -250,7 +252,8 @@ static void restore_state(void)
252 /* This is called when no merge was necessary. */
253 static void finish_up_to_date(const char *msg)
254 {
253 - printf("%s%s\n", squash ? " (nothing to squash)" : "", msg);
255 + if (verbosity >= 0)
256 + printf("%s%s\n", squash ? " (nothing to squash)" : "", msg);
257 drop_save();
258 }
259
@@ -331,14 +334,15 @@ static void finish(const unsigned char *new_head, const char *msg)
334 if (!msg)
335 strbuf_addstr(&reflog_message, getenv("GIT_REFLOG_ACTION"));
336 else {
334 - printf("%s\n", msg);
337 + if (verbosity >= 0)
338 + printf("%s\n", msg);
339 strbuf_addf(&reflog_message, "%s: %s",
340 getenv("GIT_REFLOG_ACTION"), msg);
341 }
342 if (squash) {
343 squash_message();
344 } else {
341 - if (!merge_msg.len)
345 + if (verbosity >= 0 && !merge_msg.len)
346 printf("No merge message -- not updating HEAD\n");
347 else {
348 const char *argv_gc_auto[] = { "gc", "--auto", NULL };
@@ -872,6 +876,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
876
877 argc = parse_options(argc, argv, builtin_merge_options,
878 builtin_merge_usage, 0);
879 + if (verbosity < 0)
880 + show_diffstat = 0;
881
882 if (squash) {
883 if (!allow_fast_forward)
@@ -1013,10 +1019,11 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1019
1020 strcpy(hex, find_unique_abbrev(head, DEFAULT_ABBREV));
1021
1016 - printf("Updating %s..%s\n",
1017 - hex,
1018 - find_unique_abbrev(remoteheads->item->object.sha1,
1019 - DEFAULT_ABBREV));
1022 + if (verbosity >= 0)
1023 + printf("Updating %s..%s\n",
1024 + hex,
1025 + find_unique_abbrev(remoteheads->item->object.sha1,
1026 + DEFAULT_ABBREV));
1027 strbuf_addstr(&msg, "Fast forward");
1028 if (have_message)
1029 strbuf_addstr(&msg,
git-pull.sh
+7 -3
@@ -16,13 +16,17 @@ cd_to_toplevel
16 test -z "$(git ls-files -u)" ||
17 die "You are in the middle of a conflicted merge."
18
19 -strategy_args= no_stat= no_commit= squash= no_ff= log_arg=
19 +strategy_args= no_stat= no_commit= squash= no_ff= log_arg= verbosity=
20 curr_branch=$(git symbolic-ref -q HEAD)
21 curr_branch_short=$(echo "$curr_branch" | sed "s|refs/heads/||")
22 rebase=$(git config --bool branch.$curr_branch_short.rebase)
23 while :
24 do
25 case "$1" in
26 + -q|--quiet)
27 + verbosity=-q ;;
28 + -v|--verbose)
29 + verbosity=-v ;;
30 -n|--no-stat|--no-summary)
31 no_stat=-n ;;
32 --stat|--summary)
@@ -121,7 +125,7 @@ test true = "$rebase" && {
125 "refs/remotes/$origin/$reflist" 2>/dev/null)"
126 }
127 orig_head=$(git rev-parse --verify HEAD 2>/dev/null)
124 -git fetch --update-head-ok "$@" || exit 1
128 +git fetch $verbosity --update-head-ok "$@" || exit 1
129
130 curr_head=$(git rev-parse --verify HEAD 2>/dev/null)
131 if test -n "$orig_head" && test "$curr_head" != "$orig_head"
@@ -182,4 +186,4 @@ test true = "$rebase" &&
186 exec git-rebase $strategy_args --onto $merge_head \
187 ${oldremoteref:-$merge_head}
188 exec git-merge $no_stat $no_commit $squash $no_ff $log_arg $strategy_args \
185 - "$merge_name" HEAD $merge_head
189 + "$merge_name" HEAD $merge_head $verbosity
parse-options.c
+22
@@ -484,6 +484,28 @@ int parse_opt_approxidate_cb(const struct option *opt, const char *arg,
484 return 0;
485 }
486
487 +int parse_opt_verbosity_cb(const struct option *opt, const char *arg,
488 + int unset)
489 +{
490 + int *target = opt->value;
491 +
492 + if (unset)
493 + /* --no-quiet, --no-verbose */
494 + *target = 0;
495 + else if (opt->short_name == 'v') {
496 + if (*target >= 0)
497 + (*target)++;
498 + else
499 + *target = 1;
500 + } else {
501 + if (*target <= 0)
502 + (*target)--;
503 + else
504 + *target = -1;
505 + }
506 + return 0;
507 +}
508 +
509 /*
510 * This should really be OPTION_FILENAME type as a part of
511 * parse_options that take prefix to do this while parsing.
parse-options.h
+6
@@ -150,9 +150,15 @@ extern int parse_options_end(struct parse_opt_ctx_t *ctx);
150 /*----- some often used options -----*/
151 extern int parse_opt_abbrev_cb(const struct option *, const char *, int);
152 extern int parse_opt_approxidate_cb(const struct option *, const char *, int);
153 +extern int parse_opt_verbosity_cb(const struct option *, const char *, int);
154
155 #define OPT__VERBOSE(var) OPT_BOOLEAN('v', "verbose", (var), "be verbose")
156 #define OPT__QUIET(var) OPT_BOOLEAN('q', "quiet", (var), "be quiet")
157 +#define OPT__VERBOSITY(var) \
158 + { OPTION_CALLBACK, 'v', "verbose", (var), NULL, "be more verbose", \
159 + PARSE_OPT_NOARG, &parse_opt_verbosity_cb, 0 }, \
160 + { OPTION_CALLBACK, 'q', "quiet", (var), NULL, "be more quiet", \
161 + PARSE_OPT_NOARG, &parse_opt_verbosity_cb, 0 }
162 #define OPT__DRY_RUN(var) OPT_BOOLEAN('n', "dry-run", (var), "dry run")
163 #define OPT__ABBREV(var) \
164 { OPTION_CALLBACK, 0, "abbrev", (var), "n", \
t/t5521-pull-options.sh new
+60
@@ -0,0 +1,60 @@
1 +#!/bin/sh
2 +
3 +test_description='pull options'
4 +
5 +. ./test-lib.sh
6 +
7 +D=`pwd`
8 +
9 +test_expect_success 'setup' '
10 + mkdir parent &&
11 + (cd parent && git init &&
12 + echo one >file && git add file &&
13 + git commit -m one)
14 +'
15 +
16 +cd "$D"
17 +
18 +test_expect_success 'git pull -q' '
19 + mkdir clonedq &&
20 + cd clonedq &&
21 + git pull -q "$D/parent" >out 2>err &&
22 + test ! -s out
23 +'
24 +
25 +cd "$D"
26 +
27 +test_expect_success 'git pull' '
28 + mkdir cloned &&
29 + cd cloned &&
30 + git pull "$D/parent" >out 2>err &&
31 + test -s out
32 +'
33 +cd "$D"
34 +
35 +test_expect_success 'git pull -v' '
36 + mkdir clonedv &&
37 + cd clonedv &&
38 + git pull -v "$D/parent" >out 2>err &&
39 + test -s out
40 +'
41 +
42 +cd "$D"
43 +
44 +test_expect_success 'git pull -v -q' '
45 + mkdir clonedvq &&
46 + cd clonedvq &&
47 + git pull -v -q "$D/parent" >out 2>err &&
48 + test ! -s out
49 +'
50 +
51 +cd "$D"
52 +
53 +test_expect_success 'git pull -q -v' '
54 + mkdir clonedqv &&
55 + cd clonedqv &&
56 + git pull -q -v "$D/parent" >out 2>err &&
57 + test -s out
58 +'
59 +
60 +test_done