combine-diff: move show_log_first logic/action out of paths scanning

Judging from sample outputs and tests nothing changes in diff -c output, and this change will help later patches, when we'll be refactoring paths scanning into its own function with several variants - the show_log_first logic / code will stay common to all of them. NOTE: only now we have to take care to explicitly not show anything if parents array is empty, as in fact there are some clients in Git code, which calls diff_tree_combined() in such a way. Signed-off-by: Kirill Smelkov <kirr@mns.spb.ru> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Kirill Smelkov committed Feb 3, 2014 at 16:47 UTC 51af1886c73f12b1e020db1aa03525e2d74bed93
1 file changed +14 -10
combine-diff.c
+14 -10
@@ -1311,6 +1311,20 @@ void diff_tree_combined(const unsigned char *sha1,
1311 struct combine_diff_path *p, *paths = NULL;
1312 int i, num_paths, needsep, show_log_first, num_parent = parents->nr;
1313
1314 + /* nothing to do, if no parents */
1315 + if (!num_parent)
1316 + return;
1317 +
1318 + show_log_first = !!rev->loginfo && !rev->no_commit_id;
1319 + needsep = 0;
1320 + if (show_log_first) {
1321 + show_log(rev);
1322 +
1323 + if (rev->verbose_header && opt->output_format)
1324 + printf("%s%c", diff_line_prefix(opt),
1325 + opt->line_termination);
1326 + }
1327 +
1328 diffopts = *opt;
1329 copy_pathspec(&diffopts.pathspec, &opt->pathspec);
1330 diffopts.output_format = DIFF_FORMAT_NO_OUTPUT;
@@ -1319,8 +1333,6 @@ void diff_tree_combined(const unsigned char *sha1,
1333 /* tell diff_tree to emit paths in sorted (=tree) order */
1334 diffopts.orderfile = NULL;
1335
1322 - show_log_first = !!rev->loginfo && !rev->no_commit_id;
1323 - needsep = 0;
1336 /* find set of paths that everybody touches */
1337 for (i = 0; i < num_parent; i++) {
1338 /* show stat against the first parent even
@@ -1336,14 +1348,6 @@ void diff_tree_combined(const unsigned char *sha1,
1348 diffcore_std(&diffopts);
1349 paths = intersect_paths(paths, i, num_parent);
1350
1339 - if (show_log_first && i == 0) {
1340 - show_log(rev);
1341 -
1342 - if (rev->verbose_header && opt->output_format)
1343 - printf("%s%c", diff_line_prefix(opt),
1344 - opt->line_termination);
1345 - }
1346 -
1351 /* if showing diff, show it in requested order */
1352 if (diffopts.output_format != DIFF_FORMAT_NO_OUTPUT &&
1353 opt->orderfile) {