Merge branch 'kw/rebase-progress'
authorJunio C Hamano <gitster@pobox.com>
Wed, 23 Aug 2017 21:13:07 +0000 (14:13 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 23 Aug 2017 21:13:07 +0000 (14:13 -0700)
"git rebase", especially when it is run by mistake and ends up
trying to replay many changes, spent long time in silence. The
command has been taught to show progress report when it spends
long time preparing these many changes to replay (which would give
the user a chance to abort with ^C).

* kw/rebase-progress:
rebase: turn on progress option by default for format-patch
format-patch: have progress option while generating patches

1  2 
builtin/log.c
git-rebase--am.sh
git-rebase.sh
diff --combined builtin/log.c
index 25c82410923f7b7e33760b31362e0f665a66abda,54b94107e553fd7cb298f517848940efc3036f98..25c0808409abce661d89896ceef490f15bb0b57e
@@@ -27,6 -27,7 +27,7 @@@
  #include "version.h"
  #include "mailmap.h"
  #include "gpg-interface.h"
+ #include "progress.h"
  
  /* Set a default date-time format for git log ("log.date" config variable) */
  static const char *default_date_mode = NULL;
@@@ -58,9 -59,9 +59,9 @@@ static int auto_decoration_style(void
        return (isatty(1) || pager_in_use()) ? DECORATE_SHORT_REFS : 0;
  }
  
 -static int parse_decoration_style(const char *var, const char *value)
 +static int parse_decoration_style(const char *value)
  {
 -      switch (git_config_maybe_bool(var, value)) {
 +      switch (git_parse_maybe_bool(value)) {
        case 1:
                return DECORATE_SHORT_REFS;
        case 0:
@@@ -82,7 -83,7 +83,7 @@@ static int decorate_callback(const stru
        if (unset)
                decoration_style = 0;
        else if (arg)
 -              decoration_style = parse_decoration_style("command line", arg);
 +              decoration_style = parse_decoration_style(arg);
        else
                decoration_style = DECORATE_SHORT_REFS;
  
@@@ -372,14 -373,11 +373,14 @@@ static int cmd_log_walk(struct rev_inf
                         */
                        rev->max_count++;
                if (!rev->reflog_info) {
 -                      /* we allow cycles in reflog ancestry */
 +                      /*
 +                       * We may show a given commit multiple times when
 +                       * walking the reflogs.
 +                       */
                        free_commit_buffer(commit);
 +                      free_commit_list(commit->parents);
 +                      commit->parents = NULL;
                }
 -              free_commit_list(commit->parents);
 -              commit->parents = NULL;
                if (saved_nrl < rev->diffopt.needed_rename_limit)
                        saved_nrl = rev->diffopt.needed_rename_limit;
                if (rev->diffopt.degraded_cc_to_c)
@@@ -412,7 -410,7 +413,7 @@@ static int git_log_config(const char *v
        if (!strcmp(var, "log.date"))
                return git_config_string(&default_date_mode, var, value);
        if (!strcmp(var, "log.decorate")) {
 -              decoration_style = parse_decoration_style(var, value);
 +              decoration_style = parse_decoration_style(value);
                if (decoration_style < 0)
                        decoration_style = 0; /* maybe warn? */
                return 0;
@@@ -487,8 -485,8 +488,8 @@@ static int show_blob_object(const struc
            !DIFF_OPT_TST(&rev->diffopt, ALLOW_TEXTCONV))
                return stream_blob_to_fd(1, oid, NULL, 0);
  
 -      if (get_sha1_with_context(obj_name, GET_SHA1_RECORD_PATH,
 -                                oidc.hash, &obj_context))
 +      if (get_oid_with_context(obj_name, GET_OID_RECORD_PATH,
 +                               &oidc, &obj_context))
                die(_("Not a valid object name %s"), obj_name);
        if (!obj_context.path ||
            !textconv_object(obj_context.path, obj_context.mode, &oidc, 1, &buf, &size)) {
@@@ -824,7 -822,7 +825,7 @@@ static int git_format_config(const cha
                return 0;
        }
        if (!strcmp(var, "format.from")) {
 -              int b = git_config_maybe_bool(var, value);
 +              int b = git_parse_maybe_bool(value);
                free(from);
                if (b < 0)
                        from = xstrdup(value);
@@@ -1422,6 -1420,8 +1423,8 @@@ int cmd_format_patch(int argc, const ch
        char *branch_name = NULL;
        char *base_commit = NULL;
        struct base_tree_info bases;
+       int show_progress = 0;
+       struct progress *progress = NULL;
  
        const struct option builtin_format_patch_options[] = {
                { OPTION_CALLBACK, 'n', "numbered", &numbered, NULL,
                OPT_FILENAME(0, "signature-file", &signature_file,
                                N_("add a signature from a file")),
                OPT__QUIET(&quiet, N_("don't print the patch filenames")),
+               OPT_BOOL(0, "progress", &show_progress,
+                        N_("show progress while generating patches")),
                OPT_END()
        };
  
                start_number--;
        }
        rev.add_signoff = do_signoff;
+       if (show_progress)
+               progress = start_progress_delay(_("Generating patches"), total, 0, 2);
        while (0 <= --nr) {
                int shown;
+               display_progress(progress, total - nr);
                commit = list[nr];
                rev.nr = total - nr + (start_number - 1);
                /* Make the second and subsequent mails replies to the first */
                if (!use_stdout)
                        fclose(rev.diffopt.file);
        }
+       stop_progress(&progress);
        free(list);
        free(branch_name);
        string_list_clear(&extra_to, 0);
diff --combined git-rebase--am.sh
index 319933e70a34f9da4ec93d063eb102eff33b6787,ff98fe3a7328ea8443ebe9bbe0b8388021805d02..6e64d40d6fb8fe1566dd26c3df534afe2278390c
@@@ -45,7 -45,7 +45,7 @@@ the
        # itself well to recording empty patches.  fortunately, cherry-pick
        # makes this easy
        git cherry-pick ${gpg_sign_opt:+"$gpg_sign_opt"} --allow-empty \
 -              --right-only "$revisions" \
 +              $allow_rerere_autoupdate --right-only "$revisions" \
                ${restrict_revision+^$restrict_revision}
        ret=$?
  else
@@@ -53,6 -53,7 +53,7 @@@
  
        git format-patch -k --stdout --full-index --cherry-pick --right-only \
                --src-prefix=a/ --dst-prefix=b/ --no-renames --no-cover-letter \
+               $git_format_patch_opt \
                "$revisions" ${restrict_revision+^$restrict_revision} \
                >"$GIT_DIR/rebased-patches"
        ret=$?
@@@ -82,7 -83,6 +83,7 @@@
        fi
  
        git am $git_am_opt --rebasing --resolvemsg="$resolvemsg" \
 +              $allow_rerere_autoupdate \
                ${gpg_sign_opt:+"$gpg_sign_opt"} <"$GIT_DIR/rebased-patches"
        ret=$?
  
diff --combined git-rebase.sh
index f8b3d1fd9752a37c5424e06ba36da4648d0aba1b,06f5082dc3f57e5b8fe718a74b8061383e2492b8..ad8415e3cf6907044b0730b59fc2e6ff30ab7174
@@@ -55,10 -55,9 +55,10 @@@ LF=
  '
  ok_to_skip_pre_rebase=
  resolvemsg="
 -$(gettext 'When you have resolved this problem, run "git rebase --continue".
 -If you prefer to skip this patch, run "git rebase --skip" instead.
 -To check out the original branch and stop rebasing, run "git rebase --abort".')
 +$(gettext 'Resolve all conflicts manually, mark them as resolved with
 +"git add/rm <conflicted_files>", then run "git rebase --continue".
 +You can instead skip this commit: run "git rebase --skip".
 +To abort and get back to the state before "git rebase", run "git rebase --abort".')
  "
  unset onto
  unset restrict_revision
@@@ -74,6 -73,7 +74,7 @@@ test "$(git config --bool rebase.stat)
  autostash="$(git config --bool rebase.autostash || echo false)"
  fork_point=auto
  git_am_opt=
+ git_format_patch_opt=
  rebase_root=
  force_rebase=
  allow_rerere_autoupdate=
@@@ -445,6 -445,11 +446,11 @@@ els
        state_dir="$apply_dir"
  fi
  
+ if test -t 2 && test -z "$GIT_QUIET"
+ then
+       git_format_patch_opt="$git_format_patch_opt --progress"
+ fi
  if test -z "$rebase_root"
  then
        case "$#" in