blame: move stat counters to scoreboard

Statistic counters are used in parts of blame that are being moved to libgit, and should be accessible via the scoreboard structure. 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 8449528deb6826fac5e6a9a312b45b4522ef7ebb
1 file changed +17 -17
builtin/blame.c
+17 -17
@@ -61,11 +61,6 @@ static struct string_list mailmap = STRING_LIST_INIT_NODUP;
61 #define DEBUG 0
62 #endif
63
64 -/* stats */
65 -static int num_read_blob;
66 -static int num_get_patch;
67 -static int num_commits;
68 -
64 #define PICKAXE_BLAME_MOVE 01
65 #define PICKAXE_BLAME_COPY 02
66 #define PICKAXE_BLAME_COPY_HARDER 04
@@ -151,13 +146,13 @@ static int diff_hunks(mmfile_t *file_a, mmfile_t *file_b,
146 * diff machinery
147 */
148 static void fill_origin_blob(struct diff_options *opt,
154 - struct blame_origin *o, mmfile_t *file)
149 + struct blame_origin *o, mmfile_t *file, int *num_read_blob)
150 {
151 if (!o->file.ptr) {
152 enum object_type type;
153 unsigned long file_size;
154
160 - num_read_blob++;
155 + (*num_read_blob)++;
156 if (DIFF_OPT_TST(opt, ALLOW_TEXTCONV) &&
157 textconv_object(o->path, o->mode, &o->blob_oid, 1, &file->ptr, &file_size))
158 ;
@@ -375,6 +370,11 @@ struct blame_scoreboard {
370 /* look-up a line in the final buffer */
371 int num_lines;
372 int *lineno;
373 +
374 + /* stats */
375 + int num_read_blob;
376 + int num_get_patch;
377 + int num_commits;
378 };
379
380 static void sanity_check_refcnt(struct blame_scoreboard *);
@@ -934,9 +934,9 @@ static void pass_blame_to_parent(struct blame_scoreboard *sb,
934 d.offset = 0;
935 d.dstq = &newdest; d.srcq = &target->suspects;
936
937 - fill_origin_blob(&sb->revs->diffopt, parent, &file_p);
938 - fill_origin_blob(&sb->revs->diffopt, target, &file_o);
939 - num_get_patch++;
937 + fill_origin_blob(&sb->revs->diffopt, parent, &file_p, &sb->num_read_blob);
938 + fill_origin_blob(&sb->revs->diffopt, target, &file_o, &sb->num_read_blob);
939 + sb->num_get_patch++;
940
941 if (diff_hunks(&file_p, &file_o, blame_chunk_cb, &d))
942 die("unable to generate diff (%s -> %s)",
@@ -1140,7 +1140,7 @@ static void find_move_in_parent(struct blame_scoreboard *sb,
1140 if (!unblamed)
1141 return; /* nothing remains for this target */
1142
1143 - fill_origin_blob(&sb->revs->diffopt, parent, &file_p);
1143 + fill_origin_blob(&sb->revs->diffopt, parent, &file_p, &sb->num_read_blob);
1144 if (!file_p.ptr)
1145 return;
1146
@@ -1269,7 +1269,7 @@ static void find_copy_in_parent(struct blame_scoreboard *sb,
1269 norigin = get_origin(parent, p->one->path);
1270 oidcpy(&norigin->blob_oid, &p->one->oid);
1271 norigin->mode = p->one->mode;
1272 - fill_origin_blob(&sb->revs->diffopt, norigin, &file_p);
1272 + fill_origin_blob(&sb->revs->diffopt, norigin, &file_p, &sb->num_read_blob);
1273 if (!file_p.ptr)
1274 continue;
1275
@@ -1434,7 +1434,7 @@ static void pass_blame(struct blame_scoreboard *sb, struct blame_origin *origin,
1434 }
1435 }
1436
1437 - num_commits++;
1437 + sb->num_commits++;
1438 for (i = 0, sg = first_scapegoat(revs, commit);
1439 i < num_sg && sg;
1440 sg = sg->next, i++) {
@@ -2818,7 +2818,7 @@ parse_done:
2818 oid_to_hex(&o->blob_oid),
2819 path);
2820 }
2821 - num_read_blob++;
2821 + sb.num_read_blob++;
2822 lno = prepare_lines(&sb);
2823
2824 if (lno && !range_list.nr)
@@ -2899,9 +2899,9 @@ parse_done:
2899 }
2900
2901 if (show_stats) {
2902 - printf("num read blob: %d\n", num_read_blob);
2903 - printf("num get patch: %d\n", num_get_patch);
2904 - printf("num commits: %d\n", num_commits);
2902 + printf("num read blob: %d\n", sb.num_read_blob);
2903 + printf("num get patch: %d\n", sb.num_get_patch);
2904 + printf("num commits: %d\n", sb.num_commits);
2905 }
2906 return 0;
2907 }