Skip to contentSkip to conversation

Syntax highlighting for combined diff

RFC Jakub Narebski 2 participants 6 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

Linus Torvalds wrote in "Re: VCS comparison table"

Quoted 3 lines

And "gitweb" does consider the first parent special, since it shows diffs against that one (although I've argued that it probably shouldn't, and that there should be some way to show branches against arbitrary parents)

So the question is how to color combined diff format (what should be syntax highlighting for combined diff format). If branches columns have only pluses we use the same color as for adding line in ordinary diff; if branches column consist only of minuses we use the same color as for removing line in ordinary diff. Can there be mixture of plusses and minuses? How git-diff --color solves this?

Should we in gitweb output change color slightly depending on number of plusses or minuses?

Signature · 3 lines
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git
#1 lore raw
Quoted 6 lines · Jakub Narebski

So the question is how to color combined diff format (what should be syntax highlighting for combined diff format). If branches columns have only pluses we use the same color as for adding line in ordinary diff; if branches column consist only of minuses we use the same color as for removing line in ordinary diff. Can there be mixture of plusses and minuses? How git-diff --color solves this?

UTSL ;-).

Otherwise (iow, if you refuse to use the source), you could cheat and let "git diff" do the coloring for you, and then regexp replace the output. You could even use the same coloring logic for normal diff if you did so.

#2 lore raw
Quoted 9 lines · Junio C Hamano
Quoted 6 lines · Jakub Narebski

So the question is how to color combined diff format (what should be syntax highlighting for combined diff format). If branches columns have only pluses we use the same color as for adding line in ordinary diff; if branches column consist only of minuses we use the same color as for removing line in ordinary diff. Can there be mixture of plusses and minuses? How git-diff --color solves this?

Quoted 6 lines

UTSL ;-).

Otherwise (iow, if you refuse to use the source), you could cheat and let "git diff" do the coloring for you, and then regexp replace the output. You could even use the same coloring logic for normal diff if you did so.

Do I understand code correctly, and the last '+' or '-' in the parents column means?

        for (i = 0; i < ecbdata->nparents && len; i++) {
                if (line[i] == '-')
                        color = DIFF_FILE_OLD;
                else if (line[i] == '+')
                        color = DIFF_FILE_NEW;
        }

Anyone who wrote this code, could you answer me, please?

Signature · 2 lines
Jakub Narebski
Poland
#3 lore raw
Quoted 11 lines · Jakub Narebski

Do I understand code correctly, and the last '+' or '-' in the parents column means?

        for (i = 0; i < ecbdata->nparents && len; i++) {
                if (line[i] == '-')
                        color = DIFF_FILE_OLD;
                else if (line[i] == '+')
                        color = DIFF_FILE_NEW;
        }

Anyone who wrote this code, could you answer me, please?

The "up to ecbdata->nparents" is Johannes in cd112ce. But you are looking at a wrong code, I am afraid, if your original question was about the combined format (there is a comment about the codepath dealing only with two-way diffs by Johannes, above the part you quoted). The output for combined diff is coming from combine-diff.c:dump_sline().

Combined diff output logic pretty much guarantees that you never will see plus and minus on the same line.

#4 lore raw
Quoted 12 lines · Junio C Hamano
Quoted 10 lines · Jakub Narebski

Do I understand code correctly, and the last '+' or '-' in the parents column means?

        for (i = 0; i < ecbdata->nparents && len; i++) {
                if (line[i] == '-')
                        color = DIFF_FILE_OLD;
                else if (line[i] == '+')
                        color = DIFF_FILE_NEW;
        }
Quoted 8 lines
Quoted 1 line

Anyone who wrote this code, could you answer me, please?

The "up to ecbdata->nparents" is Johannes in cd112ce. But you are looking at a wrong code, I am afraid, if your original question was about the combined format (there is a comment about the codepath dealing only with two-way diffs by Johannes, above the part you quoted). The output for combined diff is coming from combine-diff.c:dump_sline().

I was asking both about combined diff format, and how it is colored by git-diff --color, to add colored combined diff output to gitweb.

Quoted 2 lines

Combined diff output logic pretty much guarantees that you never will see plus and minus on the same line.

That's enough for me.

Any other ideas how combined commitdiff should look like in gitweb?

Signature · 2 lines
Jakub Narebski
Poland
#5 lore raw
Quoted 22 lines · Jakub Narebski
Quoted 12 lines · Junio C Hamano
Quoted 10 lines · Jakub Narebski

Do I understand code correctly, and the last '+' or '-' in the parents column means?

        for (i = 0; i < ecbdata->nparents && len; i++) {
                if (line[i] == '-')
                        color = DIFF_FILE_OLD;
                else if (line[i] == '+')
                        color = DIFF_FILE_NEW;
        }
Quoted 8 lines
Quoted 1 line

Anyone who wrote this code, could you answer me, please?

The "up to ecbdata->nparents" is Johannes in cd112ce. But you are looking at a wrong code, I am afraid, if your original question was about the combined format (there is a comment about the codepath dealing only with two-way diffs by Johannes, above the part you quoted). The output for combined diff is coming from combine-diff.c:dump_sline().

Quoted 2 lines

I was asking both about combined diff format, and how it is colored by git-diff --color, to add colored combined diff output to gitweb.

I was answering about both. dump_sline() implements both format and coloring.

Quoted 1 line

Any other ideas how combined commitdiff should look like in gitweb?

Combined or no combined, one thing that mildly irritates me sometimes is that there does not seem to be an easy and obvious way to do a rough equivalent of typing SPACE repeatedly while viewing "git log -p".

In other words, I think it would be a nice addition to have "go to commitdiff page of this parent" links near the top on the commitdiff page.