970
show_patch_diff(p, num_parent, dense, rev);
971
}
972
973
+static void free_combined_pair(struct diff_filepair *pair)
974
+{
975
+ free(pair->two);
976
+ free(pair);
977
+}
978
+
979
+/*
980
+ * A combine_diff_path expresses N parents on the LHS against 1 merge
981
+ * result. Synthesize a diff_filepair that has N entries on the "one"
982
+ * side and 1 entry on the "two" side.
983
+ *
984
+ * In the future, we might want to add more data to combine_diff_path
985
+ * so that we can fill fields we are ignoring (most notably, size) here,
986
+ * but currently nobody uses it, so this should suffice for now.
987
+ */
988
+static struct diff_filepair *combined_pair(struct combine_diff_path *p,
989
+ int num_parent)
990
+{
991
+ int i;
992
+ struct diff_filepair *pair;
993
+ struct diff_filespec *pool;
994
+
995
+ pair = xmalloc(sizeof(*pair));
996
+ pool = xcalloc(num_parent + 1, sizeof(struct diff_filespec));
997
+ pair->one = pool + 1;
998
+ pair->two = pool;
999
+
1000
+ for (i = 0; i < num_parent; i++) {
1001
+ pair->one[i].path = p->path;
1002
+ pair->one[i].mode = p->parent[i].mode;
1003
+ hashcpy(pair->one[i].sha1, p->parent[i].sha1);
1004
+ pair->one[i].sha1_valid = !is_null_sha1(p->parent[i].sha1);
1005
+ pair->one[i].has_more_entries = 1;
1006
+ }
1007
+ pair->one[num_parent - 1].has_more_entries = 0;
1008
+
1009
+ pair->two->path = p->path;
1010
+ pair->two->mode = p->mode;
1011
+ hashcpy(pair->two->sha1, p->sha1);
1012
+ pair->two->sha1_valid = !is_null_sha1(p->sha1);
1013
+ return pair;
1014
+}
1015
+
1016
+static void handle_combined_callback(struct diff_options *opt,
1017
+ struct combine_diff_path *paths,
1018
+ int num_parent,
1019
+ int num_paths)
1020
+{
1021
+ struct combine_diff_path *p;
1022
+ struct diff_queue_struct q;
1023
+ int i;
1024
+
1025
+ q.queue = xcalloc(num_paths, sizeof(struct diff_filepair *));
1026
+ q.alloc = num_paths;
1027
+ q.nr = num_paths;
1028
+ for (i = 0, p = paths; p; p = p->next) {
1029
+ if (!p->len)
1030
+ continue;
1031
+ q.queue[i++] = combined_pair(p, num_parent);
1032
+ }
1033
+ opt->format_callback(&q, opt, opt->format_callback_data);
1034
+ for (i = 0; i < num_paths; i++)
1035
+ free_combined_pair(q.queue[i]);
1036
+ free(q.queue);
1037
+}
1038
+
1039
void diff_tree_combined(const unsigned char *sha1,
1040
const unsigned char parent[][20],
1041
int num_parent,
1095
else if (opt->output_format &
1096
(DIFF_FORMAT_NUMSTAT|DIFF_FORMAT_DIFFSTAT))
1097
needsep = 1;
1098
+ else if (opt->output_format & DIFF_FORMAT_CALLBACK)
1099
+ handle_combined_callback(opt, paths, num_parent, num_paths);
1100
+
1101
if (opt->output_format & DIFF_FORMAT_PATCH) {
1102
if (needsep)
1103
putchar(opt->line_termination);