threads / patch / 15870

patchTeach/Fix git-pull/git-merge --quiet and --verbose

Subject: [PATCH] Teach/Fix git-pull/git-merge --quiet and --verbose

## tl;dr

10 messages between Oct 12, 2008 and Oct 13, 2008. Diffs are folded; open one to read it.

replies: 9people: 2as markdown or json

Tuncer Ayaz· Oct 12, 2008, 16:54 UTC · lore

After fixing clone -q I noticed that pull -q is does not do what it's supposed to do and implemented --quiet/--verbose by adding it to builtin-merge and fixing two places in builtin-fetch.

I have not touched/adjusted contrib/completion/git-completion.bash but can take a look if wanted. I think it needs one or two adjustions anyway caused by recent --OPTIONS changes in master.

I've tested the following invocations with the below changes applied: $ git pull $ git pull -q $ git pull -v

Signed-off-by: Tuncer Ayaz <tuncer.ayaz@gmail.com>
---
 Documentation/merge-options.txt |    8 ++++++
 builtin-fetch.c                 |    5 ++-
 builtin-merge.c                 |   52 +++++++++++++++++++++++---------------
 git-pull.sh                     |   10 +++++--
 4 files changed, 49 insertions(+), 26 deletions(-)
Show changes to 4 files +49 −26

Documentation/merge-options.txt, builtin-fetch.c, builtin-merge.c, git-pull.sh

diff --git a/Documentation/merge-options.txt b/Documentation/merge-options.txt
index 007909a..427cdef 100644
--- a/Documentation/merge-options.txt
+++ b/Documentation/merge-options.txt
@@ -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.
diff --git a/builtin-fetch.c b/builtin-fetch.c
index ee93d3a..b5c2885 100644
--- a/builtin-fetch.c
+++ b/builtin-fetch.c
@@ -372,12 +372,13 @@ static int store_updated_refs(const char *url,
const char *remote_name,
 				SUMMARY_WIDTH, *kind ? kind : "branch",
 				 REFCOL_WIDTH, *what ? what : "HEAD");
 		if (*note) {
-			if (!shown_url) {
+			if ((verbose || !quiet) && !shown_url) {
 				fprintf(stderr, "From %.*s\n",
 						url_len, url);
 				shown_url = 1;
 			}
-			fprintf(stderr, " %s\n", note);
+			if(verbose || !quiet)
+				fprintf(stderr, " %s\n", note);
 		}
 	}
 	fclose(fp);
diff --git a/builtin-merge.c b/builtin-merge.c
index 38266ba..1f601d4 100644
--- a/builtin-merge.c
+++ b/builtin-merge.c
@@ -44,6 +44,7 @@ static const char * const builtin_merge_usage[] = {
 static int show_diffstat = 1, option_log, squash;
 static int option_commit = 1, allow_fast_forward = 1;
 static int allow_trivial = 1, have_message;
+static int quiet, verbose;
 static struct strbuf merge_msg;
 static struct commit_list *remoteheads;
 static unsigned char head[20], stash[20];
@@ -101,7 +102,7 @@ static struct strategy *get_strategy(const char *name)
 			struct cmdname *ent = main_cmds.names[i];
 			for (j = 0; j < ARRAY_SIZE(all_strategy); j++)
 				if (!strncmp(ent->name, all_strategy[j].name, ent->len)
-						&& !all_strategy[j].name[ent->len])
+					&& !all_strategy[j].name[ent->len])
 					found = 1;
 			if (!found)
 				add_cmdname(&not_strategies, ent->name, ent->len);
@@ -152,6 +153,8 @@ static int option_parse_n(const struct option *opt,
 }

 static struct option builtin_merge_options[] = {
+	OPT__QUIET(&quiet),
+	OPT__VERBOSE(&verbose),
 	{ OPTION_CALLBACK, 'n', NULL, NULL, NULL,
 		"do not show a diffstat at the end of the merge",
 		PARSE_OPT_NOARG, option_parse_n },
@@ -250,7 +253,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(verbose || !quiet)
+		printf("%s%s\n", squash ? " (nothing to squash)" : "", msg);
 	drop_save();
 }

@@ -262,7 +266,8 @@ static void squash_message(void)
 	struct commit_list *j;
 	int fd;

-	printf("Squash commit -- not updating HEAD\n");
+	if(verbose || !quiet)
+		printf("Squash commit -- not updating HEAD\n");
 	fd = open(git_path("SQUASH_MSG"), O_WRONLY | O_CREAT, 0666);
 	if (fd < 0)
 		die("Could not write to %s", git_path("SQUASH_MSG"));
@@ -282,18 +287,20 @@ static void squash_message(void)
 	if (prepare_revision_walk(&rev))
 		die("revision walk setup failed");

-	strbuf_init(&out, 0);
-	strbuf_addstr(&out, "Squashed commit of the following:\n");
-	while ((commit = get_revision(&rev)) != NULL) {
-		strbuf_addch(&out, '\n');
-		strbuf_addf(&out, "commit %s\n",
-			sha1_to_hex(commit->object.sha1));
-		pretty_print_commit(rev.commit_format, commit, &out, rev.abbrev,
-			NULL, NULL, rev.date_mode, 0);
+	if(verbose || !quiet) {
+		strbuf_init(&out, 0);
+		strbuf_addstr(&out, "Squashed commit of the following:\n");
+		while ((commit = get_revision(&rev)) != NULL) {
+			strbuf_addch(&out, '\n');
+			strbuf_addf(&out, "commit %s\n",
+						sha1_to_hex(commit->object.sha1));
+			pretty_print_commit(rev.commit_format, commit, &out, rev.abbrev,
+								NULL, NULL, rev.date_mode, 0);
+		}
+		write(fd, out.buf, out.len);
+		close(fd);
+		strbuf_release(&out);
 	}
-	write(fd, out.buf, out.len);
-	close(fd);
-	strbuf_release(&out);
 }

 static int run_hook(const char *name)
@@ -333,14 +340,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(verbose || !quiet)
+			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 ((verbose || !quiet) && !merge_msg.len)
 			printf("No merge message -- not updating HEAD\n");
 		else {
 			const char *argv_gc_auto[] = { "gc", "--auto", NULL };
@@ -877,6 +885,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(!verbose && quiet)
+		show_diffstat = 0;

 	if (squash) {
 		if (!allow_fast_forward)
@@ -1019,11 +1029,11 @@ int cmd_merge(int argc, const char **argv,
const char *prefix)
 		char hex[41];

 		strcpy(hex, find_unique_abbrev(head, DEFAULT_ABBREV));
-
-		printf("Updating %s..%s\n",
-			hex,
-			find_unique_abbrev(remoteheads->item->object.sha1,
-			DEFAULT_ABBREV));
+		if(verbose || !quiet)
+			printf("Updating %s..%s\n",
+				   hex,
+				   find_unique_abbrev(remoteheads->item->object.sha1,
+									  DEFAULT_ABBREV));
 		strbuf_init(&msg, 0);
 		strbuf_addstr(&msg, "Fast forward");
 		if (have_message)
diff --git a/git-pull.sh b/git-pull.sh
index 75c3610..d84ceb5 100755
--- a/git-pull.sh
+++ b/git-pull.sh
@@ -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=
+quiet= verbose= strategy_args= no_stat= no_commit= squash= no_ff= log_arg=
 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)
+		quiet=-q ;;
+	-v|--verbose)
+		verbose=-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 $verbose $quiet --update-head-ok "$@" || exit 1

 curr_head=$(git rev-parse --verify HEAD 2>/dev/null)
 if test "$curr_head" != "$orig_head"
@@ -181,5 +185,5 @@ merge_name=$(git fmt-merge-msg $log_arg
<"$GIT_DIR/FETCH_HEAD") || exit
 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 \
+exec git-merge $quiet $verbose $no_stat $no_commit $squash $no_ff
$log_arg $strategy_args \
 	"$merge_name" HEAD $merge_head
-- 
1.6.0.2.GIT
Shawn O. Pearce· Oct 12, 2008, 20:08 UTC · re: Tuncer Ayaz · lore

Re: [PATCH] Teach/Fix git-pull/git-merge --quiet and --verbose

Tuncer Ayaz <tuncer.ayaz@gmail.com> wrote:
> After fixing clone -q I noticed that pull -q is does not do what
> it's supposed to do and implemented --quiet/--verbose by
> adding it to builtin-merge and fixing two places in builtin-fetch.
Show 10 quoted lines
> diff --git a/builtin-merge.c b/builtin-merge.c
> index 38266ba..1f601d4 100644
> --- a/builtin-merge.c
> +++ b/builtin-merge.c
> @@ -101,7 +102,7 @@ static struct strategy *get_strategy(const char *name)
>  			struct cmdname *ent = main_cmds.names[i];
>  			for (j = 0; j < ARRAY_SIZE(all_strategy); j++)
>  				if (!strncmp(ent->name, all_strategy[j].name, ent->len)
> -						&& !all_strategy[j].name[ent->len])
> +					&& !all_strategy[j].name[ent->len])

This hunk seems to just be whitespace formatting. I'd rather not see it in a patch that is otherwise about --quiet/--verbose changes. One change per patch, please. ;-)

Show 29 quoted lines
> @@ -282,18 +287,20 @@ static void squash_message(void)
>  	if (prepare_revision_walk(&rev))
>  		die("revision walk setup failed");
> 
> -	strbuf_init(&out, 0);
> -	strbuf_addstr(&out, "Squashed commit of the following:\n");
> -	while ((commit = get_revision(&rev)) != NULL) {
> -		strbuf_addch(&out, '\n');
> -		strbuf_addf(&out, "commit %s\n",
> -			sha1_to_hex(commit->object.sha1));
> -		pretty_print_commit(rev.commit_format, commit, &out, rev.abbrev,
> -			NULL, NULL, rev.date_mode, 0);
> +	if(verbose || !quiet) {
> +		strbuf_init(&out, 0);
> +		strbuf_addstr(&out, "Squashed commit of the following:\n");
> +		while ((commit = get_revision(&rev)) != NULL) {
> +			strbuf_addch(&out, '\n');
> +			strbuf_addf(&out, "commit %s\n",
> +						sha1_to_hex(commit->object.sha1));
> +			pretty_print_commit(rev.commit_format, commit, &out, rev.abbrev,
> +								NULL, NULL, rev.date_mode, 0);
> +		}
> +		write(fd, out.buf, out.len);
> +		close(fd);
> +		strbuf_release(&out);
>  	}
> -	write(fd, out.buf, out.len);
> -	close(fd);
> -	strbuf_release(&out);

This entire hunk strikes me as being completely wrong. The fd we are writing to is SQUASH_MSG. It was opened earlier in the function and should be closed, even if we put nothing into the file. Your change causes --quiet to leak the file descriptor.

But even worse, I think your change causes SQUASH_MSG to lose its entire content, which makes "git merge --quiet --squash" behave very differently from what it does today, where it at least gives you a summary of the commits in the SQUASH_MSG file.

IMHO this hunk shouldn't be here.
Show 7 quoted lines
> @@ -877,6 +885,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(!verbose && quiet)
> +		show_diffstat = 0;
Formatting nit, use "if (".
Show 11 quoted lines
> @@ -1019,11 +1029,11 @@ int cmd_merge(int argc, const char **argv,
> const char *prefix)
>  		char hex[41];
> 
>  		strcpy(hex, find_unique_abbrev(head, DEFAULT_ABBREV));
> -
> -		printf("Updating %s..%s\n",
> -			hex,
> -			find_unique_abbrev(remoteheads->item->object.sha1,
> -			DEFAULT_ABBREV));
> +		if(verbose || !quiet)
Formatting nit, use "if (".
Show 10 quoted lines
> diff --git a/git-pull.sh b/git-pull.sh
> index 75c3610..d84ceb5 100755
> --- a/git-pull.sh
> +++ b/git-pull.sh
> @@ -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=
> +quiet= verbose= strategy_args= no_stat= no_commit= squash= no_ff= log_arg=

This line got a little long, maybe put the two new ones on a new line so we don't overrun the 80 column margin and there's an easier to read diff?

-- 
Shawn.
Tuncer Ayaz· Oct 12, 2008, 20:29 UTC · re: Shawn O. Pearce · lore

Re: [PATCH] Teach/Fix git-pull/git-merge --quiet and --verbose

On Sun, Oct 12, 2008 at 10:08 PM, Shawn O. Pearce <spearce@spearce.org> wrote:
Show 19 quoted lines
> Tuncer Ayaz <tuncer.ayaz@gmail.com> wrote:
>> After fixing clone -q I noticed that pull -q is does not do what
>> it's supposed to do and implemented --quiet/--verbose by
>> adding it to builtin-merge and fixing two places in builtin-fetch.
>
>> diff --git a/builtin-merge.c b/builtin-merge.c
>> index 38266ba..1f601d4 100644
>> --- a/builtin-merge.c
>> +++ b/builtin-merge.c
>> @@ -101,7 +102,7 @@ static struct strategy *get_strategy(const char *name)
>>                       struct cmdname *ent = main_cmds.names[i];
>>                       for (j = 0; j < ARRAY_SIZE(all_strategy); j++)
>>                               if (!strncmp(ent->name, all_strategy[j].name, ent->len)
>> -                                             && !all_strategy[j].name[ent->len])
>> +                                     && !all_strategy[j].name[ent->len])
>
> This hunk seems to just be whitespace formatting.  I'd rather not
> see it in a patch that is otherwise about --quiet/--verbose changes.
> One change per patch, please.  ;-)
Hi Shawn, thanks for the quick review.

This is a problem caused by my automagic editor configuration and an oversight. ACK.

Show 41 quoted lines
>> @@ -282,18 +287,20 @@ static void squash_message(void)
>>       if (prepare_revision_walk(&rev))
>>               die("revision walk setup failed");
>>
>> -     strbuf_init(&out, 0);
>> -     strbuf_addstr(&out, "Squashed commit of the following:\n");
>> -     while ((commit = get_revision(&rev)) != NULL) {
>> -             strbuf_addch(&out, '\n');
>> -             strbuf_addf(&out, "commit %s\n",
>> -                     sha1_to_hex(commit->object.sha1));
>> -             pretty_print_commit(rev.commit_format, commit, &out, rev.abbrev,
>> -                     NULL, NULL, rev.date_mode, 0);
>> +     if(verbose || !quiet) {
>> +             strbuf_init(&out, 0);
>> +             strbuf_addstr(&out, "Squashed commit of the following:\n");
>> +             while ((commit = get_revision(&rev)) != NULL) {
>> +                     strbuf_addch(&out, '\n');
>> +                     strbuf_addf(&out, "commit %s\n",
>> +                                             sha1_to_hex(commit->object.sha1));
>> +                     pretty_print_commit(rev.commit_format, commit, &out, rev.abbrev,
>> +                                                             NULL, NULL, rev.date_mode, 0);
>> +             }
>> +             write(fd, out.buf, out.len);
>> +             close(fd);
>> +             strbuf_release(&out);
>>       }
>> -     write(fd, out.buf, out.len);
>> -     close(fd);
>> -     strbuf_release(&out);
>
> This entire hunk strikes me as being completely wrong.  The fd
> we are writing to is SQUASH_MSG.  It was opened earlier in the
> function and should be closed, even if we put nothing into the
> file.  Your change causes --quiet to leak the file descriptor.
>
> But even worse, I think your change causes SQUASH_MSG to lose its
> entire content, which makes "git merge --quiet --squash" behave
> very differently from what it does today, where it at least gives
> you a summary of the commits in the SQUASH_MSG file.
>
> IMHO this hunk shouldn't be here.

You are right, I was not 100% sure whether the assembled message is only displayed or possibly also stored somewhere. What would be the right place to quieten this one? I should have tagged the mail as an RFC :-).

Show 9 quoted lines
>> @@ -877,6 +885,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(!verbose && quiet)
>> +             show_diffstat = 0;
>
> Formatting nit, use "if (".
ACK.
Show 13 quoted lines
>> @@ -1019,11 +1029,11 @@ int cmd_merge(int argc, const char **argv,
>> const char *prefix)
>>               char hex[41];
>>
>>               strcpy(hex, find_unique_abbrev(head, DEFAULT_ABBREV));
>> -
>> -             printf("Updating %s..%s\n",
>> -                     hex,
>> -                     find_unique_abbrev(remoteheads->item->object.sha1,
>> -                     DEFAULT_ABBREV));
>> +             if(verbose || !quiet)
>
> Formatting nit, use "if (".
ACK.
Show 14 quoted lines
>> diff --git a/git-pull.sh b/git-pull.sh
>> index 75c3610..d84ceb5 100755
>> --- a/git-pull.sh
>> +++ b/git-pull.sh
>> @@ -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=
>> +quiet= verbose= strategy_args= no_stat= no_commit= squash= no_ff= log_arg=
>
> This line got a little long, maybe put the two new ones on a new
> line so we don't overrun the 80 column margin and there's an easier
> to read diff?
ACK.

I will fix the obvious and see what I can come up with for the pretty_print hunk.

Tuncer Ayaz· Oct 12, 2008, 21:31 UTC · re: Shawn O. Pearce · lore

Re: [PATCH] Teach/Fix git-pull/git-merge --quiet and --verbose

On Sun, Oct 12, 2008 at 10:08 PM, Shawn O. Pearce <spearce@spearce.org> wrote:
> Tuncer Ayaz <tuncer.ayaz@gmail.com> wrote:
<snip>

I've incorporated all defects as noticed by Shawn and thanks to him found out that the changes in squash_message() are definitely not needed and are more of a left-over of my tryout/devel session. Moreover I've avoided further whitespace changes.

---
>From 31fd16eccf2df334aef8fb59d4e48cf97cca93eb Mon Sep 17 00:00:00 2001
From: Tuncer Ayaz <tuncer.ayaz@gmail.com>
Date: Sun, 12 Oct 2008 23:27:14 +0200
Subject: [PATCH] Teach/Fix git-pull/git-merge --quiet and --verbose
Signed-off-by: Tuncer Ayaz <tuncer.ayaz@gmail.com>
---
 Documentation/merge-options.txt |    8 ++++++++
 builtin-fetch.c                 |    5 +++--
 builtin-merge.c                 |   22 +++++++++++++++-------
 git-pull.sh                     |   10 ++++++++--
 4 files changed, 34 insertions(+), 11 deletions(-)
Show changes to 4 files +34 −11

Documentation/merge-options.txt, builtin-fetch.c, builtin-merge.c, git-pull.sh

diff --git a/Documentation/merge-options.txt b/Documentation/merge-options.txt
index 007909a..427cdef 100644
--- a/Documentation/merge-options.txt
+++ b/Documentation/merge-options.txt
@@ -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.
diff --git a/builtin-fetch.c b/builtin-fetch.c
index ee93d3a..287ce33 100644
--- a/builtin-fetch.c
+++ b/builtin-fetch.c
@@ -372,12 +372,13 @@ static int store_updated_refs(const char *url,
const char *remote_name,
 				SUMMARY_WIDTH, *kind ? kind : "branch",
 				 REFCOL_WIDTH, *what ? what : "HEAD");
 		if (*note) {
-			if (!shown_url) {
+			if ((verbose || !quiet) && !shown_url) {
 				fprintf(stderr, "From %.*s\n",
 						url_len, url);
 				shown_url = 1;
 			}
-			fprintf(stderr, " %s\n", note);
+			if (verbose || !quiet)
+				fprintf(stderr, " %s\n", note);
 		}
 	}
 	fclose(fp);
diff --git a/builtin-merge.c b/builtin-merge.c
index 38266ba..dc12a2a 100644
--- a/builtin-merge.c
+++ b/builtin-merge.c
@@ -44,6 +44,7 @@ static const char * const builtin_merge_usage[] = {
 static int show_diffstat = 1, option_log, squash;
 static int option_commit = 1, allow_fast_forward = 1;
 static int allow_trivial = 1, have_message;
+static int quiet, verbose;
 static struct strbuf merge_msg;
 static struct commit_list *remoteheads;
 static unsigned char head[20], stash[20];
@@ -152,6 +153,8 @@ static int option_parse_n(const struct option *opt,
 }

 static struct option builtin_merge_options[] = {
+	OPT__QUIET(&quiet),
+	OPT__VERBOSE(&verbose),
 	{ OPTION_CALLBACK, 'n', NULL, NULL, NULL,
 		"do not show a diffstat at the end of the merge",
 		PARSE_OPT_NOARG, option_parse_n },
@@ -250,7 +253,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 (verbose || !quiet)
+		printf("%s%s\n", squash ? " (nothing to squash)" : "", msg);
 	drop_save();
 }

@@ -333,14 +337,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 (verbose || !quiet)
+			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 ((verbose || !quiet) && !merge_msg.len)
 			printf("No merge message -- not updating HEAD\n");
 		else {
 			const char *argv_gc_auto[] = { "gc", "--auto", NULL };
@@ -877,6 +882,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 (!verbose && quiet)
+		show_diffstat = 0;

 	if (squash) {
 		if (!allow_fast_forward)
@@ -1020,10 +1027,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 (verbose || !quiet)
+			printf("Updating %s..%s\n",
+				hex,
+				find_unique_abbrev(remoteheads->item->object.sha1,
+				DEFAULT_ABBREV));
 		strbuf_init(&msg, 0);
 		strbuf_addstr(&msg, "Fast forward");
 		if (have_message)
diff --git a/git-pull.sh b/git-pull.sh
index 75c3610..8e25d44 100755
--- a/git-pull.sh
+++ b/git-pull.sh
@@ -16,6 +16,7 @@ cd_to_toplevel
 test -z "$(git ls-files -u)" ||
 	die "You are in the middle of a conflicted merge."

+quiet= verbose=
 strategy_args= no_stat= no_commit= squash= no_ff= log_arg=
 curr_branch=$(git symbolic-ref -q HEAD)
 curr_branch_short=$(echo "$curr_branch" | sed "s|refs/heads/||")
@@ -23,6 +24,10 @@ rebase=$(git config --bool branch.$curr_branch_short.rebase)
 while :
 do
 	case "$1" in
+	-q|--quiet)
+		quiet=-q ;;
+	-v|--verbose)
+		verbose=-v ;;
 	-n|--no-stat|--no-summary)
 		no_stat=-n ;;
 	--stat|--summary)
@@ -121,7 +126,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 $verbose $quiet --update-head-ok "$@" || exit 1

 curr_head=$(git rev-parse --verify HEAD 2>/dev/null)
 if test "$curr_head" != "$orig_head"
@@ -181,5 +186,6 @@ merge_name=$(git fmt-merge-msg $log_arg
<"$GIT_DIR/FETCH_HEAD") || exit
 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 \
+exec git-merge $quiet $verbose $no_stat $no_commit \
+	$squash $no_ff $log_arg $strategy_args \
 	"$merge_name" HEAD $merge_head
-- 
1.6.0.2.GIT
Tuncer Ayaz· Oct 12, 2008, 21:36 UTC · re: Tuncer Ayaz · lore

Re: [PATCH] Teach/Fix git-pull/git-merge --quiet and --verbose

On Sun, Oct 12, 2008 at 11:31 PM, Tuncer Ayaz <tuncer.ayaz@gmail.com> wrote:
Show 6 quoted lines
> On Sun, Oct 12, 2008 at 10:08 PM, Shawn O. Pearce <spearce@spearce.org> wrote:
>> Tuncer Ayaz <tuncer.ayaz@gmail.com> wrote:
>
> <snip>
>
> I've incorporated all defects as noticed by Shawn and

I did of course intend to write s/incorporated/repaired/ :-)

> thanks to him found out that the changes in
> squash_message() are definitely not needed and are
> more of a left-over of my tryout/devel session.
> Moreover I've avoided further whitespace changes.
<snip>
Tuncer Ayaz· Oct 13, 2008, 21:03 UTC · re: Tuncer Ayaz · lore

Re: [PATCH] Teach/Fix git-pull/git-merge --quiet and --verbose

Hi Shawn and list,
I've updated the patch to current Junio master.
Signed-off-by: Tuncer Ayaz <tuncer.ayaz@gmail.com>
---
 Documentation/merge-options.txt |    8 ++++++++
 builtin-fetch.c                 |    5 +++--
 builtin-merge.c                 |   22 +++++++++++++++-------
 git-pull.sh                     |   10 ++++++++--
 4 files changed, 34 insertions(+), 11 deletions(-)
Show changes to 4 files +34 −11

Documentation/merge-options.txt, builtin-fetch.c, builtin-merge.c, git-pull.sh

diff --git a/Documentation/merge-options.txt b/Documentation/merge-options.txt
index 007909a..427cdef 100644
--- a/Documentation/merge-options.txt
+++ b/Documentation/merge-options.txt
@@ -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.
diff --git a/builtin-fetch.c b/builtin-fetch.c
index ee93d3a..287ce33 100644
--- a/builtin-fetch.c
+++ b/builtin-fetch.c
@@ -372,12 +372,13 @@ static int store_updated_refs(const char *url,
const char *remote_name,
 				SUMMARY_WIDTH, *kind ? kind : "branch",
 				 REFCOL_WIDTH, *what ? what : "HEAD");
 		if (*note) {
-			if (!shown_url) {
+			if ((verbose || !quiet) && !shown_url) {
 				fprintf(stderr, "From %.*s\n",
 						url_len, url);
 				shown_url = 1;
 			}
-			fprintf(stderr, " %s\n", note);
+			if (verbose || !quiet)
+				fprintf(stderr, " %s\n", note);
 		}
 	}
 	fclose(fp);
diff --git a/builtin-merge.c b/builtin-merge.c
index 5e2b7f1..4f90501 100644
--- a/builtin-merge.c
+++ b/builtin-merge.c
@@ -44,6 +44,7 @@ static const char * const builtin_merge_usage[] = {
 static int show_diffstat = 1, option_log, squash;
 static int option_commit = 1, allow_fast_forward = 1;
 static int allow_trivial = 1, have_message;
+static int quiet, verbose;
 static struct strbuf merge_msg;
 static struct commit_list *remoteheads;
 static unsigned char head[20], stash[20];
@@ -152,6 +153,8 @@ static int option_parse_n(const struct option *opt,
 }

 static struct option builtin_merge_options[] = {
+	OPT__QUIET(&quiet),
+	OPT__VERBOSE(&verbose),
 	{ OPTION_CALLBACK, 'n', NULL, NULL, NULL,
 		"do not show a diffstat at the end of the merge",
 		PARSE_OPT_NOARG, option_parse_n },
@@ -249,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 (verbose || !quiet)
+		printf("%s%s\n", squash ? " (nothing to squash)" : "", msg);
 	drop_save();
 }

@@ -330,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 (verbose || !quiet)
+			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 ((verbose || !quiet) && !merge_msg.len)
 			printf("No merge message -- not updating HEAD\n");
 		else {
 			const char *argv_gc_auto[] = { "gc", "--auto", NULL };
@@ -871,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 (!verbose && quiet)
+		show_diffstat = 0;

 	if (squash) {
 		if (!allow_fast_forward)
@@ -1012,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 (verbose || !quiet)
+			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,
diff --git a/git-pull.sh b/git-pull.sh
index 75c3610..8e25d44 100755
--- a/git-pull.sh
+++ b/git-pull.sh
@@ -16,6 +16,7 @@ cd_to_toplevel
 test -z "$(git ls-files -u)" ||
 	die "You are in the middle of a conflicted merge."

+quiet= verbose=
 strategy_args= no_stat= no_commit= squash= no_ff= log_arg=
 curr_branch=$(git symbolic-ref -q HEAD)
 curr_branch_short=$(echo "$curr_branch" | sed "s|refs/heads/||")
@@ -23,6 +24,10 @@ rebase=$(git config --bool branch.$curr_branch_short.rebase)
 while :
 do
 	case "$1" in
+	-q|--quiet)
+		quiet=-q ;;
+	-v|--verbose)
+		verbose=-v ;;
 	-n|--no-stat|--no-summary)
 		no_stat=-n ;;
 	--stat|--summary)
@@ -121,7 +126,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 $verbose $quiet --update-head-ok "$@" || exit 1

 curr_head=$(git rev-parse --verify HEAD 2>/dev/null)
 if test "$curr_head" != "$orig_head"
@@ -181,5 +186,6 @@ merge_name=$(git fmt-merge-msg $log_arg
<"$GIT_DIR/FETCH_HEAD") || exit
 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 \
+exec git-merge $quiet $verbose $no_stat $no_commit \
+	$squash $no_ff $log_arg $strategy_args \
 	"$merge_name" HEAD $merge_head
-- 
1.6.0.2.GIT
Shawn O. Pearce· Oct 13, 2008, 21:06 UTC · re: Tuncer Ayaz · lore

Re: [PATCH] Teach/Fix git-pull/git-merge --quiet and --verbose

Tuncer Ayaz <tuncer.ayaz@gmail.com> wrote:
Show 5 quoted lines
> Hi Shawn and list,
> 
> I've updated the patch to current Junio master.
> 
> Signed-off-by: Tuncer Ayaz <tuncer.ayaz@gmail.com>
Looks good to me.
-- 
Shawn.
Tuncer Ayaz· Oct 13, 2008, 21:12 UTC · re: Shawn O. Pearce · lore

Re: [PATCH] Teach/Fix git-pull/git-merge --quiet and --verbose

On Mon, Oct 13, 2008 at 11:06 PM, Shawn O. Pearce <spearce@spearce.org> wrote:
Show 8 quoted lines
> Tuncer Ayaz <tuncer.ayaz@gmail.com> wrote:
>> Hi Shawn and list,
>>
>> I've updated the patch to current Junio master.
>>
>> Signed-off-by: Tuncer Ayaz <tuncer.ayaz@gmail.com>
>
> Looks good to me.

GMail borked it by inserting some linebreaks :( is that a problem for this single diff or should I first resend it properly via SMTP?

Shawn O. Pearce· Oct 13, 2008, 21:13 UTC · re: Tuncer Ayaz · lore

Re: [PATCH] Teach/Fix git-pull/git-merge --quiet and --verbose

Tuncer Ayaz <tuncer.ayaz@gmail.com> wrote:
Show 13 quoted lines
> On Mon, Oct 13, 2008 at 11:06 PM, Shawn O. Pearce <spearce@spearce.org> wrote:
> > Tuncer Ayaz <tuncer.ayaz@gmail.com> wrote:
> >> Hi Shawn and list,
> >>
> >> I've updated the patch to current Junio master.
> >>
> >> Signed-off-by: Tuncer Ayaz <tuncer.ayaz@gmail.com>
> >
> > Looks good to me.
> 
> GMail borked it by inserting some linebreaks :(
> is that a problem for this single diff or should
> I first resend it properly via SMTP?

I would resend it. For a one line diff its easy to hand apply, but with multiple hunks like this you don't to waste Junio's time by trying to fix up the patch by hand.

-- 
Shawn.
Tuncer Ayaz· Oct 13, 2008, 21:44 UTC · re: Shawn O. Pearce · lore

Re: [PATCH] Teach/Fix git-pull/git-merge --quiet and --verbose

On Mon, Oct 13, 2008 at 11:13 PM, Shawn O. Pearce <spearce@spearce.org> wrote:
Show 18 quoted lines
> Tuncer Ayaz <tuncer.ayaz@gmail.com> wrote:
>> On Mon, Oct 13, 2008 at 11:06 PM, Shawn O. Pearce <spearce@spearce.org> wrote:
>> > Tuncer Ayaz <tuncer.ayaz@gmail.com> wrote:
>> >> Hi Shawn and list,
>> >>
>> >> I've updated the patch to current Junio master.
>> >>
>> >> Signed-off-by: Tuncer Ayaz <tuncer.ayaz@gmail.com>
>> >
>> > Looks good to me.
>>
>> GMail borked it by inserting some linebreaks :(
>> is that a problem for this single diff or should
>> I first resend it properly via SMTP?
>
> I would resend it.  For a one line diff its easy to hand apply,
> but with multiple hunks like this you don't to waste Junio's time
> by trying to fix up the patch by hand.

OK, configured my local setup for send-email to work and used that.

← back to recent threads