diff --git a/lib/GitList/Component/Git/Model/Diff.php b/lib/GitList/Component/Git/Model/Diff.php index aef747d..bb89315 100644 --- a/lib/GitList/Component/Git/Model/Diff.php +++ b/lib/GitList/Component/Git/Model/Diff.php @@ -12,9 +12,9 @@ class Diff protected $new; protected $file; - public function addLine($line) + public function addLine($line, $oldNo, $newNo) { - $this->lines[] = new Line($line); + $this->lines[] = new DiffLine($line, $oldNo, $newNo); } public function getLines() diff --git a/lib/GitList/Component/Git/Repository.php b/lib/GitList/Component/Git/Repository.php index 057a0e6..daa9e01 100644 --- a/lib/GitList/Component/Git/Repository.php +++ b/lib/GitList/Component/Git/Repository.php @@ -342,6 +342,8 @@ class Repository } // Read diff logs + $lineNumOld = 0; + $lineNumNew = 0; foreach ($logs as $log) { if ('diff' === substr($log, 0, 4)) { if (isset($diff)) { @@ -378,7 +380,30 @@ class Repository } } - $diff->addLine($log); + if (!empty($log)) { + switch ($log[0]) { + case "@": + // Set the line numbers + preg_match('/@@ -([0-9]+)/', $log, $matches); + $lineNumOld = $matches[1] - 1; + $lineNumNew = $matches[1] - 1; + break; + case "-": + $lineNumOld++; + break; + case "+": + $lineNumNew++; + break; + default: + $lineNumOld++; + $lineNumNew++; + } + } else { + $lineNumOld++; + $lineNumNew++; + } + + $diff->addLine($log, $lineNumOld, $lineNumNew); } if (isset($diff)) { diff --git a/views/commit.twig b/views/commit.twig index 8e7daf8..80a8d3a 100644 --- a/views/commit.twig +++ b/views/commit.twig @@ -35,9 +35,17 @@
- {% for line in diff.lines %} - {{ line.line }} + + {% for line in diff.getLines %} + + + + + {% endfor %} +
{{ line.getNumOld }}{{ line.getNumNew }} + {{ line.getLine }} +
{% endfor %} diff --git a/web/css/style.css b/web/css/style.css index 6dbc909..43bb5b0 100644 --- a/web/css/style.css +++ b/web/css/style.css @@ -254,10 +254,12 @@ table .span24{float:none;width:1884px;margin-left:0;} .source-view{width:100%;margin-bottom:18px;border:1px solid #cacaca;}.source-view .source-header{padding:8px;line-height:18px;text-align:left;vertical-align:bottom;background-color:#f4f4f4;background-image:-moz-linear-gradient(top, #fafafa, #eaeaea);background-image:-ms-linear-gradient(top, #fafafa, #eaeaea);background-image:-webkit-gradient(linear, 0 0, 0 100%, from(#fafafa), to(#eaeaea));background-image:-webkit-linear-gradient(top, #fafafa, #eaeaea);background-image:-o-linear-gradient(top, #fafafa, #eaeaea);background-image:linear-gradient(top, #fafafa, #eaeaea);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fafafa', endColorstr='#eaeaea', GradientType=0);border-bottom:1px solid #d7d7d7;font-weight:bold;color:#555555;text-shadow:1px 1px 1px #ffffff;height:28px;}.source-view .source-header .meta{float:left;padding:4px 0;font-size:14px;} .source-view pre{margin:0;padding:12px;border:none;} .source-view #sourcecode{margin:0;padding:0;border:none;width:100%;height:600px;} -.source-view .source-diff{background-color:#f5f5f5;padding:12px;}.source-view .source-diff pre{margin:0;padding:0;border:none;-webkit-border-radius:0;-moz-border-radius:0;border-radius:0;} +.source-view .source-diff{background-color:#f5f5f5;}.source-view .source-diff pre{margin:0;padding:0 0 0 6px;border:none;-webkit-border-radius:0;-moz-border-radius:0;border-radius:0;}.source-view .source-diff pre:hover{background-color:#ffc;} +.source-view .source-diff table td{padding:0px;} .source-view .source-diff .new{background-color:#DFD;} .source-view .source-diff .old{background-color:#FDD;} .source-view .source-diff .chunk{background-color:#e8e8e8;color:#999999;} +.source-view .source-diff .lineNo{color:#aaa;background-color:#e8e8e8;padding:0 6px;text-align:right;border-right:1px solid #ddd;font-family:monospace;} .source-view .image-blob{padding:10px;max-width:600px;} .blame-view{width:100%;background-color:#f5f5f5;}.blame-view td{vertical-align:top;padding:8px;} .blame-view tr{border-bottom:1px solid #cccccc;} diff --git a/web/less/files.less b/web/less/files.less index 6d57a14..0047a79 100644 --- a/web/less/files.less +++ b/web/less/files.less @@ -34,12 +34,18 @@ } .source-diff { background-color: #f5f5f5; - padding:12px; pre { margin: 0; - padding: 0; + padding: 0 0 0 6px; border: none; .border-radius(0); + + &:hover { + background-color: #ffc; + } + } + table td { + padding: 0px; } .new { background-color:#DFD; @@ -51,6 +57,14 @@ background-color:darken(#f5f5f5, 5%); color:@grayLight; } + .lineNo { + color: #aaa; + background-color: #e8e8e8; + padding: 0 6px; + text-align: right; + border-right: 1px solid #ddd; + font-family: monospace; + } } .image-blob { padding:10px; @@ -173,4 +187,4 @@ padding: 30px; color: @black; } -} \ No newline at end of file +}