Skip to content

Commit 0a79807

Browse files
author
Junio C Hamano
committed
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 <[email protected]>
1 parent 5b23683 commit 0a79807

File tree

4 files changed

+64
-32
lines changed

4 files changed

+64
-32
lines changed

combine-diff.c

Lines changed: 58 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -618,8 +618,8 @@ static void reuse_combine_diff(struct sline *sline, unsigned long cnt,
618618
sline->p_lno[i] = sline->p_lno[j];
619619
}
620620

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)
623623
{
624624
unsigned long size, cnt, lno;
625625
char *result, *cp, *ep;
@@ -791,32 +791,69 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, const cha
791791

792792
if (header)
793793
puts(header);
794-
offset = strlen(COLONS) - num_parent;
795-
if (offset < 0)
796-
offset = 0;
797-
prefix = COLONS + offset;
798794

799-
/* Show the modes */
800795
for (i = 0; i < num_parent; i++) {
801-
int mode = p->parent[i].mode;
802-
if (mode)
796+
if (p->parent[i].mode)
803797
mod_type = 'M';
804-
printf("%s%06o", prefix, mode);
805-
prefix = " ";
806798
}
807-
printf("%s%06o", prefix, p->mode);
808799
if (!p->mode)
809800
mod_type = 'D';
810801

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);
815835
}
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;
817852

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+
}
820857
}
821858

822859
const char *diff_tree_combined_merge(const unsigned char *sha1,
@@ -858,14 +895,8 @@ const char *diff_tree_combined_merge(const unsigned char *sha1,
858895
}
859896
if (num_paths) {
860897
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))
869900
header = NULL;
870901
}
871902
}

diff-files.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,8 @@ int main(int argc, const char **argv)
8888
}
8989
argv++; argc--;
9090
}
91-
if (combine_merges) {
91+
if (dense_combined_merges)
9292
diff_options.output_format = DIFF_FORMAT_PATCH;
93-
}
9493

9594
/* Find the directory, and set up the pathspec */
9695
pathspec = get_pathspec(prefix, argv + 1);
@@ -166,7 +165,8 @@ int main(int argc, const char **argv)
166165
if (combine_merges && num_compare_stages == 2) {
167166
show_combined_diff(&combine.p, 2,
168167
dense_combined_merges,
169-
NULL);
168+
NULL,
169+
&diff_options);
170170
free(combine.p.path);
171171
continue;
172172
}

diff-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ int main(int argc, const char **argv)
248248
continue;
249249
}
250250
if (!strcmp(arg, "-m")) {
251-
ignore_merges = 0;
251+
combine_merges = ignore_merges = 0;
252252
continue;
253253
}
254254
if (!strcmp(arg, "-c")) {

diff.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ struct combine_diff_path {
7575
sizeof(struct combine_diff_parent) * (n) + (l) + 1)
7676

7777
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 *);
7980

8081
extern const char *diff_tree_combined_merge(const unsigned char *sha1, const char *, int, struct diff_options *opt);
8182

0 commit comments

Comments
 (0)