blame: move progress updates to a scoreboard callback

Allow the interface user to decide how to handle a progress update. Signed-off-by: Jeff Smith <whydoubt@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff Smith committed May 24, 2017 at 00:15 UTC 8c59921dbf99cd19f1311a4eb1213312fdb41905
1 file changed +17 -10
builtin/blame.c
+17 -10
@@ -391,6 +391,9 @@ struct blame_scoreboard {
391
392 /* callbacks */
393 void(*on_sanity_fail)(struct blame_scoreboard *, int);
394 + void(*found_guilty_entry)(struct blame_entry *, void *);
395 +
396 + void *found_guilty_entry_data;
397 };
398
399 static void sanity_check_refcnt(struct blame_scoreboard *);
@@ -1729,9 +1732,10 @@ static int emit_one_suspect_detail(struct blame_origin *suspect, int repeat)
1732 * The blame_entry is found to be guilty for the range.
1733 * Show it in incremental output.
1734 */
1732 -static void found_guilty_entry(struct blame_entry *ent,
1733 - struct progress_info *pi)
1735 +static void found_guilty_entry(struct blame_entry *ent, void *data)
1736 {
1737 + struct progress_info *pi = (struct progress_info *)data;
1738 +
1739 if (incremental) {
1740 struct blame_origin *suspect = ent->suspect;
1741
@@ -1754,11 +1758,6 @@ static void assign_blame(struct blame_scoreboard *sb, int opt)
1758 {
1759 struct rev_info *revs = sb->revs;
1760 struct commit *commit = prio_queue_get(&sb->commits);
1757 - struct progress_info pi = { NULL, 0 };
1758 -
1759 - if (show_progress)
1760 - pi.progress = start_progress_delay(_("Blaming lines"),
1761 - sb->num_lines, 50, 1);
1761
1762 while (commit) {
1763 struct blame_entry *ent;
@@ -1800,7 +1799,8 @@ static void assign_blame(struct blame_scoreboard *sb, int opt)
1799 suspect->guilty = 1;
1800 for (;;) {
1801 struct blame_entry *next = ent->next;
1803 - found_guilty_entry(ent, &pi);
1802 + if (sb->found_guilty_entry)
1803 + sb->found_guilty_entry(ent, sb->found_guilty_entry_data);
1804 if (next) {
1805 ent = next;
1806 continue;
@@ -1816,8 +1816,6 @@ static void assign_blame(struct blame_scoreboard *sb, int opt)
1816 if (sb->debug) /* sanity */
1817 sanity_check_refcnt(sb);
1818 }
1819 -
1820 - stop_progress(&pi.progress);
1819 }
1820
1821 static const char *format_time(timestamp_t time, const char *tz_str,
@@ -2550,6 +2548,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
2548 char *final_commit_name = NULL;
2549 enum object_type type;
2550 struct commit *final_commit = NULL;
2551 + struct progress_info pi = { NULL, 0 };
2552
2553 struct string_list range_list = STRING_LIST_INIT_NODUP;
2554 int output_option = 0, opt = 0;
@@ -2905,8 +2904,16 @@ parse_done:
2904
2905 read_mailmap(&mailmap, NULL);
2906
2907 + sb.found_guilty_entry = &found_guilty_entry;
2908 + sb.found_guilty_entry_data = &pi;
2909 + if (show_progress)
2910 + pi.progress = start_progress_delay(_("Blaming lines"),
2911 + sb.num_lines, 50, 1);
2912 +
2913 assign_blame(&sb, opt);
2914
2915 + stop_progress(&pi.progress);
2916 +
2917 if (!incremental)
2918 setup_pager();
2919