Skip to content

Commit 970fac5

Browse files
jnarebgitster
authored andcommitted
gitweb: Give side-by-side diff extra CSS styling
Use separate background colors for pure removal, pure addition and change for side-by-side diff. This makes reading such diff easier, allowing to easily distinguish empty lines in diff from vertical whitespace used to align chunk blocks. Note that if lines in diff were numbered, the absence of line numbers [for one side] would help in distinguishing empty lines from vertical align. Signed-off-by: Jakub Narebski <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6ba1eb5 commit 970fac5

File tree

2 files changed

+42
-10
lines changed

2 files changed

+42
-10
lines changed

gitweb/gitweb.perl

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4890,7 +4890,7 @@ sub print_sidebyside_diff_chunk {
48904890
# empty contents block on start rem/add block, or end of chunk
48914891
if (@ctx && (!$class || $class eq 'rem' || $class eq 'add')) {
48924892
print join '',
4893-
'<div class="chunk_block">',
4893+
'<div class="chunk_block ctx">',
48944894
'<div class="old">',
48954895
@ctx,
48964896
'</div>',
@@ -4902,15 +4902,34 @@ sub print_sidebyside_diff_chunk {
49024902
}
49034903
# empty add/rem block on start context block, or end of chunk
49044904
if ((@rem || @add) && (!$class || $class eq 'ctx')) {
4905-
print join '',
4906-
'<div class="chunk_block">',
4907-
'<div class="old">',
4908-
@rem,
4909-
'</div>',
4910-
'<div class="new">',
4911-
@add,
4912-
'</div>',
4913-
'</div>';
4905+
if (!@add) {
4906+
# pure removal
4907+
print join '',
4908+
'<div class="chunk_block rem">',
4909+
'<div class="old">',
4910+
@rem,
4911+
'</div>',
4912+
'</div>';
4913+
} elsif (!@rem) {
4914+
# pure addition
4915+
print join '',
4916+
'<div class="chunk_block add">',
4917+
'<div class="new">',
4918+
@add,
4919+
'</div>',
4920+
'</div>';
4921+
} else {
4922+
# assume that it is change
4923+
print join '',
4924+
'<div class="chunk_block chg">',
4925+
'<div class="old">',
4926+
@rem,
4927+
'</div>',
4928+
'<div class="new">',
4929+
@add,
4930+
'</div>',
4931+
'</div>';
4932+
}
49144933
@rem = @add = ();
49154934
}
49164935

gitweb/static/gitweb.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,19 @@ div.chunk_block div.new {
491491
width: 50%;
492492
}
493493

494+
div.chunk_block.rem div.old div.diff.rem {
495+
background-color: #fff5f5;
496+
}
497+
div.chunk_block.add div.new div.diff.add {
498+
background-color: #f8fff8;
499+
}
500+
div.chunk_block.chg div div.diff {
501+
background-color: #fffff0;
502+
}
503+
div.chunk_block.ctx div div.diff.ctx {
504+
color: #404040;
505+
}
506+
494507

495508
div.index_include {
496509
border: solid #d9d8d1;

0 commit comments

Comments
 (0)