git-rebase, sequencer: extend --quiet option for the interactive machinery

While 'quiet' and 'interactive' may sound like antonyms, the interactive machinery actually has logic that implements several interactive_rebase=implied cases (--exec, --keep-empty, --rebase-merges) which won't pop up an editor. The rewrite of interactive rebase in C added a quiet option, though it only turns stats off. Since we want to make the interactive machinery also take over for git-rebase--merge, it should fully implement the --quiet option. git-rebase--interactive was already somewhat quieter than git-rebase--merge and git-rebase--am, possibly because cherry-pick has just traditionally been quieter. As such, we only drop a few informational messages -- "Rebasing (n/m)" and "Successfully rebased..." Also, for simplicity, remove the differences in how quiet and verbose options were recorded. Having one be signalled by the presence of a "verbose" file in the state_dir, while the other was signalled by the contents of a "quiet" file was just weirdly inconsistent. (This inconsistency pre-dated the rewrite into C.) Make them consistent by having them both key off the presence of the file. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Dec 11, 2018 at 08:11 UTC 899b49c446fa645419676899c9409e2975a5dd26
5 files changed +17 -16
builtin/rebase.c
+1 -4
@@ -185,10 +185,7 @@ static int read_basic_state(struct rebase_options *opts)
185 if (get_oid(buf.buf, &opts->orig_head))
186 return error(_("invalid orig-head: '%s'"), buf.buf);
187
188 - strbuf_reset(&buf);
189 - if (read_one(state_dir_path("quiet", opts), &buf))
190 - return -1;
191 - if (buf.len)
188 + if (file_exists(state_dir_path("quiet", opts)))
189 opts->flags &= ~REBASE_NO_QUIET;
190 else
191 opts->flags |= REBASE_NO_QUIET;
git-legacy-rebase.sh
+1 -1
@@ -113,7 +113,7 @@ read_basic_state () {
113 else
114 orig_head=$(cat "$state_dir"/head)
115 fi &&
116 - GIT_QUIET=$(cat "$state_dir"/quiet) &&
116 + test -f "$state_dir"/quiet && GIT_QUIET=t
117 test -f "$state_dir"/verbose && verbose=t
118 test -f "$state_dir"/strategy && strategy="$(cat "$state_dir"/strategy)"
119 test -f "$state_dir"/strategy_opts &&
git-rebase--common.sh
+1 -1
@@ -10,7 +10,7 @@ write_basic_state () {
10 echo "$head_name" > "$state_dir"/head-name &&
11 echo "$onto" > "$state_dir"/onto &&
12 echo "$orig_head" > "$state_dir"/orig-head &&
13 - echo "$GIT_QUIET" > "$state_dir"/quiet &&
13 + test t = "$GIT_QUIET" && : > "$state_dir"/quiet
14 test t = "$verbose" && : > "$state_dir"/verbose
15 test -n "$strategy" && echo "$strategy" > "$state_dir"/strategy
16 test -n "$strategy_opts" && echo "$strategy_opts" > \
sequencer.c
+13 -10
@@ -150,6 +150,7 @@ static GIT_PATH_FUNC(rebase_path_refs_to_delete, "rebase-merge/refs-to-delete")
150 static GIT_PATH_FUNC(rebase_path_gpg_sign_opt, "rebase-merge/gpg_sign_opt")
151 static GIT_PATH_FUNC(rebase_path_orig_head, "rebase-merge/orig-head")
152 static GIT_PATH_FUNC(rebase_path_verbose, "rebase-merge/verbose")
153 +static GIT_PATH_FUNC(rebase_path_quiet, "rebase-merge/quiet")
154 static GIT_PATH_FUNC(rebase_path_signoff, "rebase-merge/signoff")
155 static GIT_PATH_FUNC(rebase_path_head_name, "rebase-merge/head-name")
156 static GIT_PATH_FUNC(rebase_path_onto, "rebase-merge/onto")
@@ -157,7 +158,6 @@ static GIT_PATH_FUNC(rebase_path_autostash, "rebase-merge/autostash")
158 static GIT_PATH_FUNC(rebase_path_strategy, "rebase-merge/strategy")
159 static GIT_PATH_FUNC(rebase_path_strategy_opts, "rebase-merge/strategy_opts")
160 static GIT_PATH_FUNC(rebase_path_allow_rerere_autoupdate, "rebase-merge/allow_rerere_autoupdate")
160 -static GIT_PATH_FUNC(rebase_path_quiet, "rebase-merge/quiet")
161
162 static int git_sequencer_config(const char *k, const char *v, void *cb)
163 {
@@ -2357,6 +2357,9 @@ static int read_populate_opts(struct replay_opts *opts)
2357 if (file_exists(rebase_path_verbose()))
2358 opts->verbose = 1;
2359
2360 + if (file_exists(rebase_path_quiet()))
2361 + opts->quiet = 1;
2362 +
2363 if (file_exists(rebase_path_signoff())) {
2364 opts->allow_ff = 0;
2365 opts->signoff = 1;
@@ -2424,9 +2427,6 @@ int write_basic_state(struct replay_opts *opts, const char *head_name,
2427
2428 if (quiet)
2429 write_file(rebase_path_quiet(), "%s\n", quiet);
2427 - else
2428 - write_file(rebase_path_quiet(), "\n");
2429 -
2430 if (opts->verbose)
2431 write_file(rebase_path_verbose(), "%s", "");
2432 if (opts->strategy)
@@ -3503,10 +3503,11 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
3503 fprintf(f, "%d\n", todo_list->done_nr);
3504 fclose(f);
3505 }
3506 - fprintf(stderr, "Rebasing (%d/%d)%s",
3507 - todo_list->done_nr,
3508 - todo_list->total_nr,
3509 - opts->verbose ? "\n" : "\r");
3506 + if (!opts->quiet)
3507 + fprintf(stderr, "Rebasing (%d/%d)%s",
3508 + todo_list->done_nr,
3509 + todo_list->total_nr,
3510 + opts->verbose ? "\n" : "\r");
3511 }
3512 unlink(rebase_path_message());
3513 unlink(rebase_path_author_script());
@@ -3738,8 +3739,10 @@ cleanup_head_ref:
3739 }
3740 apply_autostash(opts);
3741
3741 - fprintf(stderr, "Successfully rebased and updated %s.\n",
3742 - head_ref.buf);
3742 + if (!opts->quiet)
3743 + fprintf(stderr,
3744 + "Successfully rebased and updated %s.\n",
3745 + head_ref.buf);
3746
3747 strbuf_release(&buf);
3748 strbuf_release(&head_ref);
sequencer.h
+1
@@ -39,6 +39,7 @@ struct replay_opts {
39 int allow_empty_message;
40 int keep_redundant_commits;
41 int verbose;
42 + int quiet;
43
44 int mainline;
45