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>
This commit is contained in:
parent
5b23683251
commit
0a798076b8
@ -618,8 +618,8 @@ static void reuse_combine_diff(struct sline *sline, unsigned long cnt,
|
|||||||
sline->p_lno[i] = sline->p_lno[j];
|
sline->p_lno[i] = sline->p_lno[j];
|
||||||
}
|
}
|
||||||
|
|
||||||
int show_combined_diff(struct combine_diff_path *elem, int num_parent,
|
static int show_patch_diff(struct combine_diff_path *elem, int num_parent,
|
||||||
int dense, const char *header)
|
int dense, const char *header)
|
||||||
{
|
{
|
||||||
unsigned long size, cnt, lno;
|
unsigned long size, cnt, lno;
|
||||||
char *result, *cp, *ep;
|
char *result, *cp, *ep;
|
||||||
@ -791,32 +791,69 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, const cha
|
|||||||
|
|
||||||
if (header)
|
if (header)
|
||||||
puts(header);
|
puts(header);
|
||||||
offset = strlen(COLONS) - num_parent;
|
|
||||||
if (offset < 0)
|
|
||||||
offset = 0;
|
|
||||||
prefix = COLONS + offset;
|
|
||||||
|
|
||||||
/* Show the modes */
|
|
||||||
for (i = 0; i < num_parent; i++) {
|
for (i = 0; i < num_parent; i++) {
|
||||||
int mode = p->parent[i].mode;
|
if (p->parent[i].mode)
|
||||||
if (mode)
|
|
||||||
mod_type = 'M';
|
mod_type = 'M';
|
||||||
printf("%s%06o", prefix, mode);
|
|
||||||
prefix = " ";
|
|
||||||
}
|
}
|
||||||
printf("%s%06o", prefix, p->mode);
|
|
||||||
if (!p->mode)
|
if (!p->mode)
|
||||||
mod_type = 'D';
|
mod_type = 'D';
|
||||||
|
|
||||||
/* Show sha1's */
|
if (opt->output_format == DIFF_FORMAT_RAW) {
|
||||||
for (i = 0; i < num_parent; i++) {
|
offset = strlen(COLONS) - num_parent;
|
||||||
printf("%s%s", prefix, diff_unique_abbrev(p->parent[i].sha1, opt->abbrev));
|
if (offset < 0)
|
||||||
prefix = " ";
|
offset = 0;
|
||||||
}
|
prefix = COLONS + offset;
|
||||||
printf("%s%s", prefix, diff_unique_abbrev(p->sha1, opt->abbrev));
|
|
||||||
|
|
||||||
/* Modification type, terminations, filename */
|
/* Show the modes */
|
||||||
printf(" %c%c%s%c", mod_type, inter_name_termination, p->path, line_termination);
|
for (i = 0; i < num_parent; i++) {
|
||||||
|
printf("%s%06o", prefix, p->parent[i].mode);
|
||||||
|
prefix = " ";
|
||||||
|
}
|
||||||
|
printf("%s%06o", prefix, p->mode);
|
||||||
|
|
||||||
|
/* Show sha1's */
|
||||||
|
for (i = 0; i < num_parent; i++)
|
||||||
|
printf(" %s", diff_unique_abbrev(p->parent[i].sha1,
|
||||||
|
opt->abbrev));
|
||||||
|
printf(" %s ", diff_unique_abbrev(p->sha1, opt->abbrev));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (opt->output_format == DIFF_FORMAT_RAW ||
|
||||||
|
opt->output_format == DIFF_FORMAT_NAME_STATUS)
|
||||||
|
printf("%c%c", mod_type, inter_name_termination);
|
||||||
|
|
||||||
|
if (line_termination) {
|
||||||
|
if (quote_c_style(p->path, NULL, NULL, 0))
|
||||||
|
quote_c_style(p->path, NULL, stdout, 0);
|
||||||
|
else
|
||||||
|
printf("%s", p->path);
|
||||||
|
putchar(line_termination);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("%s%c", p->path, line_termination);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int show_combined_diff(struct combine_diff_path *p,
|
||||||
|
int num_parent,
|
||||||
|
int dense,
|
||||||
|
const char *header,
|
||||||
|
struct diff_options *opt)
|
||||||
|
{
|
||||||
|
if (!p->len)
|
||||||
|
return 0;
|
||||||
|
switch (opt->output_format) {
|
||||||
|
case DIFF_FORMAT_RAW:
|
||||||
|
case DIFF_FORMAT_NAME_STATUS:
|
||||||
|
case DIFF_FORMAT_NAME:
|
||||||
|
show_raw_diff(p, num_parent, header, opt);
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
default:
|
||||||
|
case DIFF_FORMAT_PATCH:
|
||||||
|
return show_patch_diff(p, num_parent, dense, header);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *diff_tree_combined_merge(const unsigned char *sha1,
|
const char *diff_tree_combined_merge(const unsigned char *sha1,
|
||||||
@ -858,14 +895,8 @@ const char *diff_tree_combined_merge(const unsigned char *sha1,
|
|||||||
}
|
}
|
||||||
if (num_paths) {
|
if (num_paths) {
|
||||||
for (p = paths; p; p = p->next) {
|
for (p = paths; p; p = p->next) {
|
||||||
if (!p->len)
|
if (show_combined_diff(p, num_parent, dense,
|
||||||
continue;
|
header, opt))
|
||||||
if (opt->output_format == DIFF_FORMAT_RAW) {
|
|
||||||
show_raw_diff(p, num_parent, header, opt);
|
|
||||||
header = NULL;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (show_combined_diff(p, num_parent, dense, header))
|
|
||||||
header = NULL;
|
header = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,9 +88,8 @@ int main(int argc, const char **argv)
|
|||||||
}
|
}
|
||||||
argv++; argc--;
|
argv++; argc--;
|
||||||
}
|
}
|
||||||
if (combine_merges) {
|
if (dense_combined_merges)
|
||||||
diff_options.output_format = DIFF_FORMAT_PATCH;
|
diff_options.output_format = DIFF_FORMAT_PATCH;
|
||||||
}
|
|
||||||
|
|
||||||
/* Find the directory, and set up the pathspec */
|
/* Find the directory, and set up the pathspec */
|
||||||
pathspec = get_pathspec(prefix, argv + 1);
|
pathspec = get_pathspec(prefix, argv + 1);
|
||||||
@ -166,7 +165,8 @@ int main(int argc, const char **argv)
|
|||||||
if (combine_merges && num_compare_stages == 2) {
|
if (combine_merges && num_compare_stages == 2) {
|
||||||
show_combined_diff(&combine.p, 2,
|
show_combined_diff(&combine.p, 2,
|
||||||
dense_combined_merges,
|
dense_combined_merges,
|
||||||
NULL);
|
NULL,
|
||||||
|
&diff_options);
|
||||||
free(combine.p.path);
|
free(combine.p.path);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -248,7 +248,7 @@ int main(int argc, const char **argv)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!strcmp(arg, "-m")) {
|
if (!strcmp(arg, "-m")) {
|
||||||
ignore_merges = 0;
|
combine_merges = ignore_merges = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!strcmp(arg, "-c")) {
|
if (!strcmp(arg, "-c")) {
|
||||||
|
3
diff.h
3
diff.h
@ -75,7 +75,8 @@ struct combine_diff_path {
|
|||||||
sizeof(struct combine_diff_parent) * (n) + (l) + 1)
|
sizeof(struct combine_diff_parent) * (n) + (l) + 1)
|
||||||
|
|
||||||
extern int show_combined_diff(struct combine_diff_path *elem, int num_parent,
|
extern int show_combined_diff(struct combine_diff_path *elem, int num_parent,
|
||||||
int dense, const char *header);
|
int dense, const char *header,
|
||||||
|
struct diff_options *);
|
||||||
|
|
||||||
extern const char *diff_tree_combined_merge(const unsigned char *sha1, const char *, int, struct diff_options *opt);
|
extern const char *diff_tree_combined_merge(const unsigned char *sha1, const char *, int, struct diff_options *opt);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user