Skip to content

Commit ee63802

Browse files
Linus TorvaldsJunio C Hamano
authored andcommitted
diff-tree -c raw output
NOTE! This makes "-c" be the default, which effectively means that merges are never ignored any more, and "-m" is a no-op. So it changes semantics. I would also like to make "--cc" the default if you do patches, but didn't actually do that. The raw output format is not wonderfully pretty, but it's distinguishable from a "normal patch" in that a normal patch with just one parent has just one colon at the beginning, while a multi-parent raw diff has <n> colons for <n> parents. So now, in the kernel, when you do git-diff-tree cce0cac (to see the manual ARM merge that had a conflict in arch/arm/Kconfig), you get cce0cac ::100644 100644 100644 4a63a8e 77eee38 2f61726d2f4b636f6e66696700dbf71a59dad287 arch/arm/Kconfig ie you see two colons (two parents), then three modes (parent modes followed by result mode), then three sha1s (parent sha1s followed by result sha1). Which is pretty close to the normal raw diff output. Cool/stupid exercise: $ git-whatchanged | grep '^::' | cut -f2- | sort | uniq -c | sort -n | less -S will show which files have needed the most file-level merge conflict resolution. Useful? Probably not. But kind of interesting. For the kernel, it's .... 10 arch/ia64/Kconfig 11 drivers/scsi/Kconfig 12 drivers/net/Makefile 17 include/linux/libata.h 18 include/linux/pci_ids.h 23 drivers/net/Kconfig 24 drivers/scsi/libata-scsi.c 28 drivers/scsi/libata-core.c 43 MAINTAINERS Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent d19e06f commit ee63802

File tree

3 files changed

+67
-12
lines changed

3 files changed

+67
-12
lines changed

combine-diff.c

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -776,8 +776,52 @@ int show_combined_diff(struct combine_diff_path *elem, int num_parent,
776776
return shown_header;
777777
}
778778

779-
int diff_tree_combined_merge(const unsigned char *sha1,
780-
const char *header, int dense)
779+
#define COLONS "::::::::::::::::::::::::::::::::"
780+
781+
static void show_raw_diff(struct combine_diff_path *p, int num_parent, const char *header, struct diff_options *opt)
782+
{
783+
int i, offset, mod_type = 'A';
784+
const char *prefix;
785+
int line_termination, inter_name_termination;
786+
787+
line_termination = opt->line_termination;
788+
inter_name_termination = '\t';
789+
if (!line_termination)
790+
inter_name_termination = 0;
791+
792+
if (header)
793+
puts(header);
794+
offset = strlen(COLONS) - num_parent;
795+
if (offset < 0)
796+
offset = 0;
797+
prefix = COLONS + offset;
798+
799+
/* Show the modes */
800+
for (i = 0; i < num_parent; i++) {
801+
int mode = p->parent[i].mode;
802+
if (mode)
803+
mod_type = 'M';
804+
printf("%s%06o", prefix, mode);
805+
prefix = " ";
806+
}
807+
printf("%s%06o", prefix, p->mode);
808+
if (!p->mode)
809+
mod_type = 'D';
810+
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 = " ";
815+
}
816+
printf("%s%s", prefix, diff_unique_abbrev(p->sha1, opt->abbrev));
817+
818+
/* Modification type, terminations, filename */
819+
printf(" %c%c%s%c", mod_type, inter_name_termination, p->path, line_termination);
820+
}
821+
822+
const char *diff_tree_combined_merge(const unsigned char *sha1,
823+
const char *header, int dense,
824+
struct diff_options *opt)
781825
{
782826
struct commit *commit = lookup_commit(sha1);
783827
struct diff_options diffopts;
@@ -815,6 +859,11 @@ int diff_tree_combined_merge(const unsigned char *sha1,
815859
for (p = paths; p; p = p->next) {
816860
if (!p->len)
817861
continue;
862+
if (opt->output_format == DIFF_FORMAT_RAW) {
863+
show_raw_diff(p, num_parent, header, opt);
864+
header = NULL;
865+
continue;
866+
}
818867
if (show_combined_diff(p, num_parent, dense, header))
819868
header = NULL;
820869
}
@@ -826,5 +875,5 @@ int diff_tree_combined_merge(const unsigned char *sha1,
826875
paths = paths->next;
827876
free(tmp);
828877
}
829-
return 0;
878+
return header;
830879
}

diff-tree.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ static int show_root_diff = 0;
66
static int no_commit_id = 0;
77
static int verbose_header = 0;
88
static int ignore_merges = 1;
9-
static int combine_merges = 0;
9+
static int combine_merges = 1;
1010
static int dense_combined_merges = 0;
1111
static int read_stdin = 0;
1212
static int always_show_header = 0;
@@ -117,8 +117,12 @@ static int diff_tree_commit(struct commit *commit)
117117
return 0;
118118
else if (combine_merges) {
119119
header = generate_header(sha1, sha1, commit);
120-
return diff_tree_combined_merge(sha1, header,
121-
dense_combined_merges);
120+
header = diff_tree_combined_merge(sha1, header,
121+
dense_combined_merges,
122+
&diff_options);
123+
if (!header && verbose_header)
124+
header_prefix = "\ndiff-tree ";
125+
return 0;
122126
}
123127
}
124128

@@ -285,10 +289,12 @@ int main(int argc, const char **argv)
285289
usage(diff_tree_usage);
286290
}
287291

288-
if (combine_merges) {
289-
diff_options.output_format = DIFF_FORMAT_PATCH;
292+
if (combine_merges)
290293
ignore_merges = 0;
291-
}
294+
295+
/* We can only do dense combined merges with diff output */
296+
if (dense_combined_merges)
297+
diff_options.output_format = DIFF_FORMAT_PATCH;
292298

293299
if (diff_options.output_format == DIFF_FORMAT_PATCH)
294300
diff_options.recursive = 1;

diff.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ struct combine_diff_path {
7474
(sizeof(struct combine_diff_path) + \
7575
sizeof(struct combine_diff_parent) * (n) + (l) + 1)
7676

77-
int show_combined_diff(struct combine_diff_path *elem, int num_parent,
78-
int dense, const char *header);
77+
extern int show_combined_diff(struct combine_diff_path *elem, int num_parent,
78+
int dense, const char *header);
7979

80-
extern int diff_tree_combined_merge(const unsigned char *sha1, const char *, int);
80+
extern const char *diff_tree_combined_merge(const unsigned char *sha1, const char *, int, struct diff_options *opt);
8181

8282
extern void diff_addremove(struct diff_options *,
8383
int addremove,

0 commit comments

Comments
 (0)