format-patch: have progress option while generating patches

When generating patches for the rebase command, if the user does not realize the branch they are rebasing onto is thousands of commits different, there is no progress indication after initial rewinding message. The progress meter as presented in this patch assumes the thousands of patches to have a fine granularity as well as assuming to require all the same amount of work/time for each, such that a steady progress bar is achieved. We do not want to estimate the time for each patch based e.g. on their size or number of touched files (or parents) as that is too expensive for just a progress meter. This patch allows a progress option to be passed to format-patch so that the user can be informed the progress of generating the patch. This option is then used by the rebase command when calling format-patch. Signed-off-by: Kevin Willford <kewillf@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Kevin Willford committed Aug 10, 2017 at 14:32 UTC 738e88a20cd4c73930a18c759ed6f5704e85109f
2 files changed +14
Documentation/git-format-patch.txt
+4
@@ -23,6 +23,7 @@ SYNOPSIS
23 [(--reroll-count|-v) <n>]
24 [--to=<email>] [--cc=<email>]
25 [--[no-]cover-letter] [--quiet] [--notes[=<ref>]]
26 + [--progress]
27 [<common diff options>]
28 [ <since> | <revision range> ]
29
@@ -283,6 +284,9 @@ you can use `--suffix=-patch` to get `0001-description-of-my-change-patch`.
284 range are always formatted as creation patches, independently
285 of this flag.
286
287 +--progress::
288 + Show progress reports on stderr as patches are generated.
289 +
290 CONFIGURATION
291 -------------
292 You can specify extra mail header lines to be added to each message,
builtin/log.c
+10
@@ -27,6 +27,7 @@
27 #include "version.h"
28 #include "mailmap.h"
29 #include "gpg-interface.h"
30 +#include "progress.h"
31
32 /* Set a default date-time format for git log ("log.date" config variable) */
33 static const char *default_date_mode = NULL;
@@ -1419,6 +1420,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1420 char *branch_name = NULL;
1421 char *base_commit = NULL;
1422 struct base_tree_info bases;
1423 + int show_progress = 0;
1424 + struct progress *progress = NULL;
1425
1426 const struct option builtin_format_patch_options[] = {
1427 { OPTION_CALLBACK, 'n', "numbered", &numbered, NULL,
@@ -1490,6 +1493,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1493 OPT_FILENAME(0, "signature-file", &signature_file,
1494 N_("add a signature from a file")),
1495 OPT__QUIET(&quiet, N_("don't print the patch filenames")),
1496 + OPT_BOOL(0, "progress", &show_progress,
1497 + N_("show progress while generating patches")),
1498 OPT_END()
1499 };
1500
@@ -1749,8 +1754,12 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1754 start_number--;
1755 }
1756 rev.add_signoff = do_signoff;
1757 +
1758 + if (show_progress)
1759 + progress = start_progress_delay(_("Generating patches"), total, 0, 2);
1760 while (0 <= --nr) {
1761 int shown;
1762 + display_progress(progress, total - nr);
1763 commit = list[nr];
1764 rev.nr = total - nr + (start_number - 1);
1765 /* Make the second and subsequent mails replies to the first */
@@ -1815,6 +1824,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1824 if (!use_stdout)
1825 fclose(rev.diffopt.file);
1826 }
1827 + stop_progress(&progress);
1828 free(list);
1829 free(branch_name);
1830 string_list_clear(&extra_to, 0);