@matheusbsbs / matheus-bagliano / commits / 8828cdcb44
Fork 0

diff-tree --cc: squelch header generation on empty patch.

Earlier round showed the commit log header and "diff --combined" header even for paths that had no interesting hunk under --cc flag. Move the header display logic around to squelch them. With this, a merge that does not have any interesting merges will not be shown with --cc option, unless -m is used at the same time. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Jan 25, 2006 at 14:26 UTC 8828cdcb445fc420de9e869d359596ceefce76be
1 file changed +30 -16
combine-diff.c
+30 -16
@@ -323,12 +323,13 @@ static unsigned long line_all_diff(struct sline *sline, unsigned long all_mask)
323 return different;
324 }
325
326 -static void make_hunks(struct sline *sline, unsigned long cnt,
326 +static int make_hunks(struct sline *sline, unsigned long cnt,
327 int num_parent, int dense)
328 {
329 unsigned long all_mask = (1UL<<num_parent) - 1;
330 unsigned long mark = (1UL<<num_parent);
331 unsigned long i;
332 + int has_interesting = 0;
333
334 i = 0;
335 while (i < cnt) {
@@ -344,21 +345,23 @@ static void make_hunks(struct sline *sline, unsigned long cnt,
345 j = (i + context < cnt) ? i + context : cnt;
346 while (i < j)
347 sline[i++].flag |= mark;
348 + has_interesting = 1;
349 continue;
350 }
351 i++;
352 }
353 if (!dense)
352 - return;
354 + return has_interesting;
355
356 /* Look at each hunk, and if we have changes from only one
357 * parent, or the changes are the same from all but one
358 * parent, mark that uninteresting.
359 */
360 + has_interesting = 0;
361 i = 0;
362 while (i < cnt) {
363 int j, hunk_end, same, diff;
361 - unsigned long same_diff, all_diff, this_diff;
364 + unsigned long same_diff, all_diff;
365 while (i < cnt && !(sline[i].flag & mark))
366 i++;
367 if (cnt <= i)
@@ -387,8 +390,11 @@ static void make_hunks(struct sline *sline, unsigned long cnt,
390 for (j = i; j < hunk_end; j++)
391 sline[j].flag &= ~mark;
392 }
393 + else
394 + has_interesting = 1;
395 i = hunk_end;
396 }
397 + return has_interesting;
398 }
399
400 static void dump_sline(struct sline *sline, int cnt, int num_parent)
@@ -437,13 +443,13 @@ static void dump_sline(struct sline *sline, int cnt, int num_parent)
443 }
444 }
445
440 -static void show_combined_diff(struct path_list *elem, int num_parent,
441 - int dense)
446 +static int show_combined_diff(struct path_list *elem, int num_parent,
447 + int dense, const char *header, int show_empty)
448 {
449 unsigned long size, cnt, lno;
450 char *result, *cp, *ep;
451 struct sline *sline; /* survived lines */
446 - int i;
452 + int i, show_hunks, shown_header = 0;
453 char ourtmp[TMPPATHLEN];
454
455 /* Read the result of merge first */
@@ -479,9 +485,21 @@ static void show_combined_diff(struct path_list *elem, int num_parent,
485 for (i = 0; i < num_parent; i++)
486 combine_diff(elem->parent_sha1[i], ourtmp, sline, cnt, i);
487
482 - make_hunks(sline, cnt, num_parent, dense);
488 + show_hunks = make_hunks(sline, cnt, num_parent, dense);
489
484 - dump_sline(sline, cnt, num_parent);
490 + if (header && (show_hunks || show_empty)) {
491 + shown_header++;
492 + puts(header);
493 + }
494 + if (show_hunks) {
495 + printf("diff --%s ", dense ? "cc" : "combined");
496 + if (quote_c_style(elem->path, NULL, NULL, 0))
497 + quote_c_style(elem->path, NULL, stdout, 0);
498 + else
499 + printf("%s", elem->path);
500 + putchar('\n');
501 + dump_sline(sline, cnt, num_parent);
502 + }
503 unlink(ourtmp);
504 free(result);
505
@@ -496,6 +514,7 @@ static void show_combined_diff(struct path_list *elem, int num_parent,
514 }
515 }
516 free(sline);
517 + return shown_header;
518 }
519
520 int diff_tree_combined_merge(const unsigned char *sha1,
@@ -535,17 +554,12 @@ int diff_tree_combined_merge(const unsigned char *sha1,
554 num_paths++;
555 }
556 if (num_paths || show_empty_merge) {
538 - puts(header);
557 for (p = paths; p; p = p->next) {
558 if (!p->len)
559 continue;
542 - printf("diff --%s ", dense ? "cc" : "combined");
543 - if (quote_c_style(p->path, NULL, NULL, 0))
544 - quote_c_style(p->path, NULL, stdout, 0);
545 - else
546 - printf("%s", p->path);
547 - putchar('\n');
548 - show_combined_diff(p, num_parent, dense);
560 + if (show_combined_diff(p, num_parent, dense, header,
561 + show_empty_merge))
562 + header = NULL;
563 }
564 }
565