@matheusbsbs / matheus-bagliano / commits / 0a798076b8
Fork 0

combine-diff: move formatting logic to show_combined_diff()

This way, diff-files can make use of it. Also implement the full suite of what diff_flush_raw() supports just for consistency. With this, 'diff-tree -c -r --name-status' would show what is expected. There is no way to get the historical output (useful for debugging and low-level Plumbing work) anymore, so tentatively it makes '-m' to mean "do not combine and show individual diffs with parents". diff-files matches diff-tree to produce raw output for -c. For textual combined diff, use -p -c. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Feb 9, 2006 at 15:23 UTC 0a798076b8d1a4a31bf2b24c564e2a99fd1c43a1
4 files changed +64 -32
combine-diff.c
+58 -27
@@ -618,8 +618,8 @@ static void reuse_combine_diff(struct sline *sline, unsigned long cnt,
618 sline->p_lno[i] = sline->p_lno[j];
619 }
620
621 -int show_combined_diff(struct combine_diff_path *elem, int num_parent,
622 - int dense, const char *header)
621 +static int show_patch_diff(struct combine_diff_path *elem, int num_parent,
622 + int dense, const char *header)
623 {
624 unsigned long size, cnt, lno;
625 char *result, *cp, *ep;
@@ -791,32 +791,69 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, const cha
791
792 if (header)
793 puts(header);
794 - offset = strlen(COLONS) - num_parent;
795 - if (offset < 0)
796 - offset = 0;
797 - prefix = COLONS + offset;
794
799 - /* Show the modes */
795 for (i = 0; i < num_parent; i++) {
801 - int mode = p->parent[i].mode;
802 - if (mode)
796 + if (p->parent[i].mode)
797 mod_type = 'M';
804 - printf("%s%06o", prefix, mode);
805 - prefix = " ";
798 }
807 - printf("%s%06o", prefix, p->mode);
799 if (!p->mode)
800 mod_type = 'D';
801
811 - /* Show sha1's */
812 - for (i = 0; i < num_parent; i++) {
813 - printf("%s%s", prefix, diff_unique_abbrev(p->parent[i].sha1, opt->abbrev));
814 - prefix = " ";
802 + if (opt->output_format == DIFF_FORMAT_RAW) {
803 + offset = strlen(COLONS) - num_parent;
804 + if (offset < 0)
805 + offset = 0;
806 + prefix = COLONS + offset;
807 +
808 + /* Show the modes */
809 + for (i = 0; i < num_parent; i++) {
810 + printf("%s%06o", prefix, p->parent[i].mode);
811 + prefix = " ";
812 + }
813 + printf("%s%06o", prefix, p->mode);
814 +
815 + /* Show sha1's */
816 + for (i = 0; i < num_parent; i++)
817 + printf(" %s", diff_unique_abbrev(p->parent[i].sha1,
818 + opt->abbrev));
819 + printf(" %s ", diff_unique_abbrev(p->sha1, opt->abbrev));
820 + }
821 +
822 + if (opt->output_format == DIFF_FORMAT_RAW ||
823 + opt->output_format == DIFF_FORMAT_NAME_STATUS)
824 + printf("%c%c", mod_type, inter_name_termination);
825 +
826 + if (line_termination) {
827 + if (quote_c_style(p->path, NULL, NULL, 0))
828 + quote_c_style(p->path, NULL, stdout, 0);
829 + else
830 + printf("%s", p->path);
831 + putchar(line_termination);
832 + }
833 + else {
834 + printf("%s%c", p->path, line_termination);
835 }
816 - printf("%s%s", prefix, diff_unique_abbrev(p->sha1, opt->abbrev));
836 +}
837 +
838 +int show_combined_diff(struct combine_diff_path *p,
839 + int num_parent,
840 + int dense,
841 + const char *header,
842 + struct diff_options *opt)
843 +{
844 + if (!p->len)
845 + return 0;
846 + switch (opt->output_format) {
847 + case DIFF_FORMAT_RAW:
848 + case DIFF_FORMAT_NAME_STATUS:
849 + case DIFF_FORMAT_NAME:
850 + show_raw_diff(p, num_parent, header, opt);
851 + return 1;
852
818 - /* Modification type, terminations, filename */
819 - printf(" %c%c%s%c", mod_type, inter_name_termination, p->path, line_termination);
853 + default:
854 + case DIFF_FORMAT_PATCH:
855 + return show_patch_diff(p, num_parent, dense, header);
856 + }
857 }
858
859 const char *diff_tree_combined_merge(const unsigned char *sha1,
@@ -858,14 +895,8 @@ const char *diff_tree_combined_merge(const unsigned char *sha1,
895 }
896 if (num_paths) {
897 for (p = paths; p; p = p->next) {
861 - if (!p->len)
862 - continue;
863 - if (opt->output_format == DIFF_FORMAT_RAW) {
864 - show_raw_diff(p, num_parent, header, opt);
865 - header = NULL;
866 - continue;
867 - }
868 - if (show_combined_diff(p, num_parent, dense, header))
898 + if (show_combined_diff(p, num_parent, dense,
899 + header, opt))
900 header = NULL;
901 }
902 }
diff-files.c
+3 -3
@@ -88,9 +88,8 @@ int main(int argc, const char **argv)
88 }
89 argv++; argc--;
90 }
91 - if (combine_merges) {
91 + if (dense_combined_merges)
92 diff_options.output_format = DIFF_FORMAT_PATCH;
93 - }
93
94 /* Find the directory, and set up the pathspec */
95 pathspec = get_pathspec(prefix, argv + 1);
@@ -166,7 +165,8 @@ int main(int argc, const char **argv)
165 if (combine_merges && num_compare_stages == 2) {
166 show_combined_diff(&combine.p, 2,
167 dense_combined_merges,
169 - NULL);
168 + NULL,
169 + &diff_options);
170 free(combine.p.path);
171 continue;
172 }
diff-tree.c
+1 -1
@@ -248,7 +248,7 @@ int main(int argc, const char **argv)
248 continue;
249 }
250 if (!strcmp(arg, "-m")) {
251 - ignore_merges = 0;
251 + combine_merges = ignore_merges = 0;
252 continue;
253 }
254 if (!strcmp(arg, "-c")) {
diff.h
+2 -1
@@ -75,7 +75,8 @@ struct combine_diff_path {
75 sizeof(struct combine_diff_parent) * (n) + (l) + 1)
76
77 extern int show_combined_diff(struct combine_diff_path *elem, int num_parent,
78 - int dense, const char *header);
78 + int dense, const char *header,
79 + struct diff_options *);
80
81 extern const char *diff_tree_combined_merge(const unsigned char *sha1, const char *, int, struct diff_options *opt);
82