combine-diff.c: teach combined diffs about line prefix
When running "git log --graph --cc -p" the diff output for merges is not
indented by the graph structure, unlike the diffs of non-merge commits
(added in commit 7be5761
- diff.c: Output the text graph padding before
each diff line).
Fix this by teaching the combined diff code to output diff_line_prefix()
before each line.
Signed-off-by: John Keeping <john@keeping.me.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
30997bb8f1
commit
41ee2ad6cb
@ -526,7 +526,8 @@ static void show_line_to_eol(const char *line, int len, const char *reset)
|
|||||||
saw_cr_at_eol ? "\r" : "");
|
saw_cr_at_eol ? "\r" : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent,
|
static void dump_sline(struct sline *sline, const char *line_prefix,
|
||||||
|
unsigned long cnt, int num_parent,
|
||||||
int use_color, int result_deleted)
|
int use_color, int result_deleted)
|
||||||
{
|
{
|
||||||
unsigned long mark = (1UL<<num_parent);
|
unsigned long mark = (1UL<<num_parent);
|
||||||
@ -582,7 +583,7 @@ static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent,
|
|||||||
rlines -= null_context;
|
rlines -= null_context;
|
||||||
}
|
}
|
||||||
|
|
||||||
fputs(c_frag, stdout);
|
printf("%s%s", line_prefix, c_frag);
|
||||||
for (i = 0; i <= num_parent; i++) putchar(combine_marker);
|
for (i = 0; i <= num_parent; i++) putchar(combine_marker);
|
||||||
for (i = 0; i < num_parent; i++)
|
for (i = 0; i < num_parent; i++)
|
||||||
show_parent_lno(sline, lno, hunk_end, i, null_context);
|
show_parent_lno(sline, lno, hunk_end, i, null_context);
|
||||||
@ -614,7 +615,7 @@ static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent,
|
|||||||
struct sline *sl = &sline[lno++];
|
struct sline *sl = &sline[lno++];
|
||||||
ll = (sl->flag & no_pre_delete) ? NULL : sl->lost_head;
|
ll = (sl->flag & no_pre_delete) ? NULL : sl->lost_head;
|
||||||
while (ll) {
|
while (ll) {
|
||||||
fputs(c_old, stdout);
|
printf("%s%s", line_prefix, c_old);
|
||||||
for (j = 0; j < num_parent; j++) {
|
for (j = 0; j < num_parent; j++) {
|
||||||
if (ll->parent_map & (1UL<<j))
|
if (ll->parent_map & (1UL<<j))
|
||||||
putchar('-');
|
putchar('-');
|
||||||
@ -627,6 +628,7 @@ static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent,
|
|||||||
if (cnt < lno)
|
if (cnt < lno)
|
||||||
break;
|
break;
|
||||||
p_mask = 1;
|
p_mask = 1;
|
||||||
|
fputs(line_prefix, stdout);
|
||||||
if (!(sl->flag & (mark-1))) {
|
if (!(sl->flag & (mark-1))) {
|
||||||
/*
|
/*
|
||||||
* This sline was here to hang the
|
* This sline was here to hang the
|
||||||
@ -680,11 +682,13 @@ static void reuse_combine_diff(struct sline *sline, unsigned long cnt,
|
|||||||
static void dump_quoted_path(const char *head,
|
static void dump_quoted_path(const char *head,
|
||||||
const char *prefix,
|
const char *prefix,
|
||||||
const char *path,
|
const char *path,
|
||||||
|
const char *line_prefix,
|
||||||
const char *c_meta, const char *c_reset)
|
const char *c_meta, const char *c_reset)
|
||||||
{
|
{
|
||||||
static struct strbuf buf = STRBUF_INIT;
|
static struct strbuf buf = STRBUF_INIT;
|
||||||
|
|
||||||
strbuf_reset(&buf);
|
strbuf_reset(&buf);
|
||||||
|
strbuf_addstr(&buf, line_prefix);
|
||||||
strbuf_addstr(&buf, c_meta);
|
strbuf_addstr(&buf, c_meta);
|
||||||
strbuf_addstr(&buf, head);
|
strbuf_addstr(&buf, head);
|
||||||
quote_two_c_style(&buf, prefix, path, 0);
|
quote_two_c_style(&buf, prefix, path, 0);
|
||||||
@ -696,6 +700,7 @@ static void show_combined_header(struct combine_diff_path *elem,
|
|||||||
int num_parent,
|
int num_parent,
|
||||||
int dense,
|
int dense,
|
||||||
struct rev_info *rev,
|
struct rev_info *rev,
|
||||||
|
const char *line_prefix,
|
||||||
int mode_differs,
|
int mode_differs,
|
||||||
int show_file_header)
|
int show_file_header)
|
||||||
{
|
{
|
||||||
@ -714,8 +719,8 @@ static void show_combined_header(struct combine_diff_path *elem,
|
|||||||
show_log(rev);
|
show_log(rev);
|
||||||
|
|
||||||
dump_quoted_path(dense ? "diff --cc " : "diff --combined ",
|
dump_quoted_path(dense ? "diff --cc " : "diff --combined ",
|
||||||
"", elem->path, c_meta, c_reset);
|
"", elem->path, line_prefix, c_meta, c_reset);
|
||||||
printf("%sindex ", c_meta);
|
printf("%s%sindex ", line_prefix, c_meta);
|
||||||
for (i = 0; i < num_parent; i++) {
|
for (i = 0; i < num_parent; i++) {
|
||||||
abb = find_unique_abbrev(elem->parent[i].sha1,
|
abb = find_unique_abbrev(elem->parent[i].sha1,
|
||||||
abbrev);
|
abbrev);
|
||||||
@ -734,11 +739,12 @@ static void show_combined_header(struct combine_diff_path *elem,
|
|||||||
DIFF_STATUS_ADDED)
|
DIFF_STATUS_ADDED)
|
||||||
added = 0;
|
added = 0;
|
||||||
if (added)
|
if (added)
|
||||||
printf("%snew file mode %06o",
|
printf("%s%snew file mode %06o",
|
||||||
c_meta, elem->mode);
|
line_prefix, c_meta, elem->mode);
|
||||||
else {
|
else {
|
||||||
if (deleted)
|
if (deleted)
|
||||||
printf("%sdeleted file ", c_meta);
|
printf("%s%sdeleted file ",
|
||||||
|
line_prefix, c_meta);
|
||||||
printf("mode ");
|
printf("mode ");
|
||||||
for (i = 0; i < num_parent; i++) {
|
for (i = 0; i < num_parent; i++) {
|
||||||
printf("%s%06o", i ? "," : "",
|
printf("%s%06o", i ? "," : "",
|
||||||
@ -755,16 +761,16 @@ static void show_combined_header(struct combine_diff_path *elem,
|
|||||||
|
|
||||||
if (added)
|
if (added)
|
||||||
dump_quoted_path("--- ", "", "/dev/null",
|
dump_quoted_path("--- ", "", "/dev/null",
|
||||||
c_meta, c_reset);
|
line_prefix, c_meta, c_reset);
|
||||||
else
|
else
|
||||||
dump_quoted_path("--- ", a_prefix, elem->path,
|
dump_quoted_path("--- ", a_prefix, elem->path,
|
||||||
c_meta, c_reset);
|
line_prefix, c_meta, c_reset);
|
||||||
if (deleted)
|
if (deleted)
|
||||||
dump_quoted_path("+++ ", "", "/dev/null",
|
dump_quoted_path("+++ ", "", "/dev/null",
|
||||||
c_meta, c_reset);
|
line_prefix, c_meta, c_reset);
|
||||||
else
|
else
|
||||||
dump_quoted_path("+++ ", b_prefix, elem->path,
|
dump_quoted_path("+++ ", b_prefix, elem->path,
|
||||||
c_meta, c_reset);
|
line_prefix, c_meta, c_reset);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
|
static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
|
||||||
@ -782,6 +788,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
|
|||||||
struct userdiff_driver *userdiff;
|
struct userdiff_driver *userdiff;
|
||||||
struct userdiff_driver *textconv = NULL;
|
struct userdiff_driver *textconv = NULL;
|
||||||
int is_binary;
|
int is_binary;
|
||||||
|
const char *line_prefix = diff_line_prefix(opt);
|
||||||
|
|
||||||
context = opt->context;
|
context = opt->context;
|
||||||
userdiff = userdiff_find_by_path(elem->path);
|
userdiff = userdiff_find_by_path(elem->path);
|
||||||
@ -901,7 +908,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
|
|||||||
}
|
}
|
||||||
if (is_binary) {
|
if (is_binary) {
|
||||||
show_combined_header(elem, num_parent, dense, rev,
|
show_combined_header(elem, num_parent, dense, rev,
|
||||||
mode_differs, 0);
|
line_prefix, mode_differs, 0);
|
||||||
printf("Binary files differ\n");
|
printf("Binary files differ\n");
|
||||||
free(result);
|
free(result);
|
||||||
return;
|
return;
|
||||||
@ -962,8 +969,8 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
|
|||||||
|
|
||||||
if (show_hunks || mode_differs || working_tree_file) {
|
if (show_hunks || mode_differs || working_tree_file) {
|
||||||
show_combined_header(elem, num_parent, dense, rev,
|
show_combined_header(elem, num_parent, dense, rev,
|
||||||
mode_differs, 1);
|
line_prefix, mode_differs, 1);
|
||||||
dump_sline(sline, cnt, num_parent,
|
dump_sline(sline, line_prefix, cnt, num_parent,
|
||||||
opt->use_color, result_deleted);
|
opt->use_color, result_deleted);
|
||||||
}
|
}
|
||||||
free(result);
|
free(result);
|
||||||
@ -990,6 +997,7 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, struct re
|
|||||||
int i, offset;
|
int i, offset;
|
||||||
const char *prefix;
|
const char *prefix;
|
||||||
int line_termination, inter_name_termination;
|
int line_termination, inter_name_termination;
|
||||||
|
const char *line_prefix = diff_line_prefix(opt);
|
||||||
|
|
||||||
line_termination = opt->line_termination;
|
line_termination = opt->line_termination;
|
||||||
inter_name_termination = '\t';
|
inter_name_termination = '\t';
|
||||||
@ -1000,6 +1008,7 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, struct re
|
|||||||
show_log(rev);
|
show_log(rev);
|
||||||
|
|
||||||
if (opt->output_format & DIFF_FORMAT_RAW) {
|
if (opt->output_format & DIFF_FORMAT_RAW) {
|
||||||
|
printf("%s", line_prefix);
|
||||||
offset = strlen(COLONS) - num_parent;
|
offset = strlen(COLONS) - num_parent;
|
||||||
if (offset < 0)
|
if (offset < 0)
|
||||||
offset = 0;
|
offset = 0;
|
||||||
@ -1040,6 +1049,7 @@ void show_combined_diff(struct combine_diff_path *p,
|
|||||||
struct rev_info *rev)
|
struct rev_info *rev)
|
||||||
{
|
{
|
||||||
struct diff_options *opt = &rev->diffopt;
|
struct diff_options *opt = &rev->diffopt;
|
||||||
|
|
||||||
if (!p->len)
|
if (!p->len)
|
||||||
return;
|
return;
|
||||||
if (opt->output_format & (DIFF_FORMAT_RAW |
|
if (opt->output_format & (DIFF_FORMAT_RAW |
|
||||||
@ -1150,8 +1160,10 @@ void diff_tree_combined(const unsigned char *sha1,
|
|||||||
|
|
||||||
if (show_log_first && i == 0) {
|
if (show_log_first && i == 0) {
|
||||||
show_log(rev);
|
show_log(rev);
|
||||||
|
|
||||||
if (rev->verbose_header && opt->output_format)
|
if (rev->verbose_header && opt->output_format)
|
||||||
putchar(opt->line_termination);
|
printf("%s%c", diff_line_prefix(opt),
|
||||||
|
opt->line_termination);
|
||||||
}
|
}
|
||||||
diff_flush(&diffopts);
|
diff_flush(&diffopts);
|
||||||
}
|
}
|
||||||
@ -1179,7 +1191,8 @@ void diff_tree_combined(const unsigned char *sha1,
|
|||||||
|
|
||||||
if (opt->output_format & DIFF_FORMAT_PATCH) {
|
if (opt->output_format & DIFF_FORMAT_PATCH) {
|
||||||
if (needsep)
|
if (needsep)
|
||||||
putchar(opt->line_termination);
|
printf("%s%c", diff_line_prefix(opt),
|
||||||
|
opt->line_termination);
|
||||||
for (p = paths; p; p = p->next) {
|
for (p = paths; p; p = p->next) {
|
||||||
if (p->len)
|
if (p->len)
|
||||||
show_patch_diff(p, num_parent, dense,
|
show_patch_diff(p, num_parent, dense,
|
||||||
|
Loading…
Reference in New Issue
Block a user