@matheusbsbs / matheus-bagliano / commits / 9843a1f6fd
Fork 0

combine-diff: do not send NULL to printf

When we run combined diff from working tree (diff-files --cc), we sent NULL to printf that is returned by find_unique_abbrev(). Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Feb 6, 2006 at 12:30 UTC 9843a1f6fdb31eed5db774a6d6f99ab0758642a3
1 file changed +17 -6
combine-diff.c
+17 -6
@@ -623,6 +623,7 @@ int show_combined_diff(struct combine_diff_path *elem, int num_parent,
623 write_to_temp_file(ourtmp, result, size);
624 }
625 else {
626 + /* Used by diff-tree to read from the working tree */
627 struct stat st;
628 int fd;
629 ourtmp = elem->path;
@@ -701,6 +702,11 @@ int show_combined_diff(struct combine_diff_path *elem, int num_parent,
702 show_hunks = make_hunks(sline, cnt, num_parent, dense);
703
704 if (show_hunks) {
705 + const char *abb;
706 + char null_abb[DEFAULT_ABBREV + 1];
707 +
708 + memset(null_abb, '0', DEFAULT_ABBREV);
709 + null_abb[DEFAULT_ABBREV] = 0;
710 if (header) {
711 shown_header++;
712 puts(header);
@@ -713,13 +719,18 @@ int show_combined_diff(struct combine_diff_path *elem, int num_parent,
719 putchar('\n');
720 printf("index ");
721 for (i = 0; i < num_parent; i++) {
716 - printf("%s%s",
717 - i ? "," : "",
718 - find_unique_abbrev(elem->parent_sha1[i],
719 - DEFAULT_ABBREV));
722 + if (memcmp(elem->parent_sha1[i], null_sha1, 20))
723 + abb = find_unique_abbrev(elem->parent_sha1[i],
724 + DEFAULT_ABBREV);
725 + else
726 + abb = null_abb;
727 + printf("%s%s", i ? "," : "", abb);
728 }
721 - printf("..%s\n",
722 - find_unique_abbrev(elem->sha1, DEFAULT_ABBREV));
729 + if (memcmp(elem->sha1, null_sha1, 20))
730 + abb = find_unique_abbrev(elem->sha1, DEFAULT_ABBREV);
731 + else
732 + abb = null_abb;
733 + printf("..%s\n", abb);
734 dump_sline(sline, cnt, num_parent);
735 }
736 if (ourtmp == ourtmp_buf)