Skip to content

Commit 98cdf78

Browse files
committed
Merge branch 'ta/quiet-pull'
* ta/quiet-pull: Retain multiple -q/-v occurrences in git pull Teach/Fix pull/fetch -q/-v options
2 parents 496db64 + c6576f9 commit 98cdf78

File tree

7 files changed

+126
-20
lines changed

7 files changed

+126
-20
lines changed

Documentation/merge-options.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
-q::
2+
--quiet::
3+
Operate quietly.
4+
5+
-v::
6+
--verbose::
7+
Be verbose.
8+
19
--stat::
210
Show a diffstat at the end of the merge. The diffstat is also
311
controlled by the configuration option merge.stat.

builtin-fetch.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,15 @@ enum {
2222
TAGS_SET = 2
2323
};
2424

25-
static int append, force, keep, update_head_ok, verbose, quiet;
25+
static int append, force, keep, update_head_ok, verbosity;
2626
static int tags = TAGS_DEFAULT;
2727
static const char *depth;
2828
static const char *upload_pack;
2929
static struct strbuf default_rla = STRBUF_INIT;
3030
static struct transport *transport;
3131

3232
static struct option builtin_fetch_options[] = {
33-
OPT__QUIET(&quiet),
34-
OPT__VERBOSE(&verbose),
33+
OPT__VERBOSITY(&verbosity),
3534
OPT_BOOLEAN('a', "append", &append,
3635
"append to .git/FETCH_HEAD instead of overwriting"),
3736
OPT_STRING(0, "upload-pack", &upload_pack, "PATH",
@@ -192,7 +191,6 @@ static int s_update_ref(const char *action,
192191

193192
static int update_local_ref(struct ref *ref,
194193
const char *remote,
195-
int verbose,
196194
char *display)
197195
{
198196
struct commit *current = NULL, *updated;
@@ -210,7 +208,7 @@ static int update_local_ref(struct ref *ref,
210208
die("object %s not found", sha1_to_hex(ref->new_sha1));
211209

212210
if (!hashcmp(ref->old_sha1, ref->new_sha1)) {
213-
if (verbose)
211+
if (verbosity > 0)
214212
sprintf(display, "= %-*s %-*s -> %s", SUMMARY_WIDTH,
215213
"[up to date]", REFCOL_WIDTH, remote,
216214
pretty_ref);
@@ -366,18 +364,19 @@ static int store_updated_refs(const char *url, const char *remote_name,
366364
note);
367365

368366
if (ref)
369-
rc |= update_local_ref(ref, what, verbose, note);
367+
rc |= update_local_ref(ref, what, note);
370368
else
371369
sprintf(note, "* %-*s %-*s -> FETCH_HEAD",
372370
SUMMARY_WIDTH, *kind ? kind : "branch",
373371
REFCOL_WIDTH, *what ? what : "HEAD");
374372
if (*note) {
375-
if (!shown_url) {
373+
if (verbosity >= 0 && !shown_url) {
376374
fprintf(stderr, "From %.*s\n",
377375
url_len, url);
378376
shown_url = 1;
379377
}
380-
fprintf(stderr, " %s\n", note);
378+
if (verbosity >= 0)
379+
fprintf(stderr, " %s\n", note);
381380
}
382381
}
383382
fclose(fp);
@@ -637,9 +636,9 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
637636
remote = remote_get(argv[0]);
638637

639638
transport = transport_get(remote, remote->url[0]);
640-
if (verbose >= 2)
639+
if (verbosity >= 2)
641640
transport->verbose = 1;
642-
if (quiet)
641+
if (verbosity < 0)
643642
transport->verbose = -1;
644643
if (upload_pack)
645644
set_option(TRANS_OPT_UPLOADPACK, upload_pack);

builtin-merge.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ static unsigned char head[20], stash[20];
5050
static struct strategy **use_strategies;
5151
static size_t use_strategies_nr, use_strategies_alloc;
5252
static const char *branch;
53+
static int verbosity;
5354

5455
static struct strategy all_strategy[] = {
5556
{ "recursive", DEFAULT_TWOHEAD | NO_TRIVIAL },
@@ -171,6 +172,7 @@ static struct option builtin_merge_options[] = {
171172
OPT_CALLBACK('m', "message", &merge_msg, "message",
172173
"message to be used for the merge commit (if any)",
173174
option_parse_message),
175+
OPT__VERBOSITY(&verbosity),
174176
OPT_END()
175177
};
176178

@@ -250,7 +252,8 @@ static void restore_state(void)
250252
/* This is called when no merge was necessary. */
251253
static void finish_up_to_date(const char *msg)
252254
{
253-
printf("%s%s\n", squash ? " (nothing to squash)" : "", msg);
255+
if (verbosity >= 0)
256+
printf("%s%s\n", squash ? " (nothing to squash)" : "", msg);
254257
drop_save();
255258
}
256259

@@ -331,14 +334,15 @@ static void finish(const unsigned char *new_head, const char *msg)
331334
if (!msg)
332335
strbuf_addstr(&reflog_message, getenv("GIT_REFLOG_ACTION"));
333336
else {
334-
printf("%s\n", msg);
337+
if (verbosity >= 0)
338+
printf("%s\n", msg);
335339
strbuf_addf(&reflog_message, "%s: %s",
336340
getenv("GIT_REFLOG_ACTION"), msg);
337341
}
338342
if (squash) {
339343
squash_message();
340344
} else {
341-
if (!merge_msg.len)
345+
if (verbosity >= 0 && !merge_msg.len)
342346
printf("No merge message -- not updating HEAD\n");
343347
else {
344348
const char *argv_gc_auto[] = { "gc", "--auto", NULL };
@@ -872,6 +876,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
872876

873877
argc = parse_options(argc, argv, builtin_merge_options,
874878
builtin_merge_usage, 0);
879+
if (verbosity < 0)
880+
show_diffstat = 0;
875881

876882
if (squash) {
877883
if (!allow_fast_forward)
@@ -1013,10 +1019,11 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
10131019

10141020
strcpy(hex, find_unique_abbrev(head, DEFAULT_ABBREV));
10151021

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));
10201027
strbuf_addstr(&msg, "Fast forward");
10211028
if (have_message)
10221029
strbuf_addstr(&msg,

git-pull.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@ cd_to_toplevel
1616
test -z "$(git ls-files -u)" ||
1717
die "You are in the middle of a conflicted merge."
1818

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=
2020
curr_branch=$(git symbolic-ref -q HEAD)
2121
curr_branch_short=$(echo "$curr_branch" | sed "s|refs/heads/||")
2222
rebase=$(git config --bool branch.$curr_branch_short.rebase)
2323
while :
2424
do
2525
case "$1" in
26+
-q|--quiet)
27+
verbosity="$verbosity -q" ;;
28+
-v|--verbose)
29+
verbosity="$verbosity -v" ;;
2630
-n|--no-stat|--no-summary)
2731
no_stat=-n ;;
2832
--stat|--summary)
@@ -121,7 +125,7 @@ test true = "$rebase" && {
121125
"refs/remotes/$origin/$reflist" 2>/dev/null)"
122126
}
123127
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
125129

126130
curr_head=$(git rev-parse --verify HEAD 2>/dev/null)
127131
if test -n "$orig_head" && test "$curr_head" != "$orig_head"
@@ -182,4 +186,4 @@ test true = "$rebase" &&
182186
exec git-rebase $strategy_args --onto $merge_head \
183187
${oldremoteref:-$merge_head}
184188
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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,28 @@ int parse_opt_approxidate_cb(const struct option *opt, const char *arg,
484484
return 0;
485485
}
486486

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+
487509
/*
488510
* This should really be OPTION_FILENAME type as a part of
489511
* parse_options that take prefix to do this while parsing.

parse-options.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,15 @@ extern int parse_options_end(struct parse_opt_ctx_t *ctx);
150150
/*----- some often used options -----*/
151151
extern int parse_opt_abbrev_cb(const struct option *, const char *, int);
152152
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);
153154

154155
#define OPT__VERBOSE(var) OPT_BOOLEAN('v', "verbose", (var), "be verbose")
155156
#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 }
156162
#define OPT__DRY_RUN(var) OPT_BOOLEAN('n', "dry-run", (var), "dry run")
157163
#define OPT__ABBREV(var) \
158164
{ OPTION_CALLBACK, 0, "abbrev", (var), "n", \

t/t5521-pull-options.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

0 commit comments

Comments
 (0)