mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-21 12:44:49 -05:00
minor fix to #2335
This commit is contained in:
parent
21d7b5acaf
commit
86bce4a2ae
7 changed files with 57 additions and 42 deletions
|
@ -31,6 +31,7 @@ github.com/microcosm-cc/bluemonday = commit:4ac6f27
|
|||
github.com/msteinert/pam = commit:02ccfbf
|
||||
github.com/nfnt/resize = commit:dc93e1b98c
|
||||
github.com/russross/blackfriday = commit:d18b67a
|
||||
github.com/sergi/go-diff =
|
||||
github.com/shurcooL/sanitized_anchor_name = commit:10ef21a
|
||||
github.com/Unknwon/cae = commit:7f5e046
|
||||
github.com/Unknwon/com = commit:28b053d
|
||||
|
|
|
@ -3,7 +3,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra
|
|||
|
||||
![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true)
|
||||
|
||||
##### Current version: 0.8.17
|
||||
##### Current version: 0.8.18
|
||||
|
||||
| Web | UI | Preview |
|
||||
|:-------------:|:-------:|:-------:|
|
||||
|
|
2
gogs.go
2
gogs.go
|
@ -17,7 +17,7 @@ import (
|
|||
"github.com/gogits/gogs/modules/setting"
|
||||
)
|
||||
|
||||
const APP_VER = "0.8.17.0109"
|
||||
const APP_VER = "0.8.18.0109"
|
||||
|
||||
func init() {
|
||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||
|
|
|
@ -8,18 +8,18 @@ import (
|
|||
"bufio"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"html"
|
||||
"html/template"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"html/template"
|
||||
"html"
|
||||
|
||||
"github.com/Unknwon/com"
|
||||
"github.com/sergi/go-diff/diffmatchpatch"
|
||||
"golang.org/x/net/html/charset"
|
||||
"golang.org/x/text/transform"
|
||||
"github.com/sergi/go-diff/diffmatchpatch"
|
||||
|
||||
"github.com/gogits/git-module"
|
||||
|
||||
|
@ -47,10 +47,10 @@ const (
|
|||
)
|
||||
|
||||
type DiffLine struct {
|
||||
LeftIdx int
|
||||
RightIdx int
|
||||
Type DiffLineType
|
||||
Content string
|
||||
LeftIdx int
|
||||
RightIdx int
|
||||
Type DiffLineType
|
||||
Content string
|
||||
ParsedContent template.HTML
|
||||
}
|
||||
|
||||
|
@ -63,18 +63,29 @@ type DiffSection struct {
|
|||
Lines []*DiffLine
|
||||
}
|
||||
|
||||
func diffToHtml(diffRecord []diffmatchpatch.Diff, lineType DiffLineType) template.HTML {
|
||||
result := ""
|
||||
for _, s := range diffRecord {
|
||||
if s.Type == diffmatchpatch.DiffInsert && lineType == DIFF_LINE_ADD {
|
||||
result = result + "<span class=\"added-code\">"+html.EscapeString(s.Text)+"</span>"
|
||||
} else if s.Type == diffmatchpatch.DiffDelete && lineType == DIFF_LINE_DEL {
|
||||
result = result + "<span class=\"removed-code\">"+html.EscapeString(s.Text)+"</span>"
|
||||
} else if s.Type == diffmatchpatch.DiffEqual {
|
||||
result = result + html.EscapeString(s.Text)
|
||||
var (
|
||||
addedCodePrefix = []byte("<span class=\"added-code\">")
|
||||
removedCodePrefix = []byte("<span class=\"removed-code\">")
|
||||
codeTagSuffix = []byte("</span>")
|
||||
)
|
||||
|
||||
func diffToHTML(diffs []diffmatchpatch.Diff, lineType DiffLineType) template.HTML {
|
||||
var buf bytes.Buffer
|
||||
for i := range diffs {
|
||||
if diffs[i].Type == diffmatchpatch.DiffInsert && lineType == DIFF_LINE_ADD {
|
||||
buf.Write(addedCodePrefix)
|
||||
buf.WriteString(html.EscapeString(diffs[i].Text))
|
||||
buf.Write(codeTagSuffix)
|
||||
} else if diffs[i].Type == diffmatchpatch.DiffDelete && lineType == DIFF_LINE_DEL {
|
||||
buf.Write(removedCodePrefix)
|
||||
buf.WriteString(html.EscapeString(diffs[i].Text))
|
||||
buf.Write(codeTagSuffix)
|
||||
} else if diffs[i].Type == diffmatchpatch.DiffEqual {
|
||||
buf.WriteString(html.EscapeString(diffs[i].Text))
|
||||
}
|
||||
}
|
||||
return template.HTML(result)
|
||||
|
||||
return template.HTML(buf.Bytes())
|
||||
}
|
||||
|
||||
// get an specific line by type (add or del) and file line number
|
||||
|
@ -89,11 +100,11 @@ func (diffSection *DiffSection) GetLine(lineType DiffLineType, idx int) *DiffLin
|
|||
}
|
||||
|
||||
if lineType == DIFF_LINE_DEL {
|
||||
if diffLine.RightIdx == 0 && diffLine.LeftIdx == idx - difference {
|
||||
if diffLine.RightIdx == 0 && diffLine.LeftIdx == idx-difference {
|
||||
return diffLine
|
||||
}
|
||||
} else if lineType == DIFF_LINE_ADD {
|
||||
if diffLine.LeftIdx == 0 && diffLine.RightIdx == idx + difference {
|
||||
if diffLine.LeftIdx == 0 && diffLine.RightIdx == idx+difference {
|
||||
return diffLine
|
||||
}
|
||||
}
|
||||
|
@ -107,11 +118,9 @@ func (diffSection *DiffSection) ComputeLinesDiff() {
|
|||
var compareDiffLine *DiffLine
|
||||
var diff1, diff2 string
|
||||
|
||||
// default content: as is
|
||||
diffLine.ParsedContent = template.HTML(html.EscapeString(diffLine.Content[1:]))
|
||||
|
||||
// just compute diff for adds and removes
|
||||
if diffLine.Type != DIFF_LINE_ADD && diffLine.Type != DIFF_LINE_DEL {
|
||||
diffLine.ParsedContent = template.HTML(html.EscapeString(diffLine.Content[1:]))
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -136,7 +145,7 @@ func (diffSection *DiffSection) ComputeLinesDiff() {
|
|||
diffRecord := dmp.DiffMain(diff1[1:], diff2[1:], true)
|
||||
diffRecord = dmp.DiffCleanupSemantic(diffRecord)
|
||||
|
||||
diffLine.ParsedContent = diffToHtml(diffRecord, diffLine.Type)
|
||||
diffLine.ParsedContent = diffToHTML(diffRecord, diffLine.Type)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2306,9 +2306,10 @@ footer .container .links > *:first-child {
|
|||
}
|
||||
.repository .diff-box .count {
|
||||
margin-right: 12px;
|
||||
font-size: 13px;
|
||||
}
|
||||
.repository .diff-box .count .bar {
|
||||
background-color: #e75316;
|
||||
background-color: #bd2c00 ;
|
||||
height: 12px;
|
||||
width: 40px;
|
||||
display: inline-block;
|
||||
|
@ -2316,7 +2317,7 @@ footer .container .links > *:first-child {
|
|||
vertical-align: text-top;
|
||||
}
|
||||
.repository .diff-box .count .bar .add {
|
||||
background-color: #77c64a;
|
||||
background-color: #55a532;
|
||||
height: 12px;
|
||||
}
|
||||
.repository .diff-box .file {
|
||||
|
@ -2387,6 +2388,12 @@ footer .container .links > *:first-child {
|
|||
.repository .diff-file-box .code-diff tbody tr.add-code td.halfwidth {
|
||||
width: 50%;
|
||||
}
|
||||
.repository .diff-file-box .code-diff tbody tr .removed-code {
|
||||
background-color: #ff9999;
|
||||
}
|
||||
.repository .diff-file-box .code-diff tbody tr .added-code {
|
||||
background-color: #99ff99;
|
||||
}
|
||||
.repository .diff-file-box.file-content img {
|
||||
max-width: 100%;
|
||||
padding: 5px 5px 0 5px;
|
||||
|
@ -2764,12 +2771,6 @@ footer .container .links > *:first-child {
|
|||
#delete-repo-modal .ui.message {
|
||||
width: 100%!important;
|
||||
}
|
||||
.removed-code {
|
||||
background-color: #ff9999;
|
||||
}
|
||||
.added-code {
|
||||
background-color: #99ff99;
|
||||
}
|
||||
.organization {
|
||||
padding-top: 15px;
|
||||
padding-bottom: 80px;
|
||||
|
|
|
@ -641,15 +641,17 @@
|
|||
.diff-box {
|
||||
.count {
|
||||
margin-right: 12px;
|
||||
font-size: 13px;
|
||||
|
||||
.bar {
|
||||
background-color: #e75316;
|
||||
background-color: #bd2c00 ;
|
||||
height: 12px;
|
||||
width: 40px;
|
||||
display: inline-block;
|
||||
margin: 2px 4px 0 4px;
|
||||
vertical-align: text-top;
|
||||
.add {
|
||||
background-color: #77c64a;
|
||||
background-color: #55a532;
|
||||
height: 12px;
|
||||
}
|
||||
}
|
||||
|
@ -716,6 +718,7 @@
|
|||
// }
|
||||
// }
|
||||
&.del-code {
|
||||
// Duplicate here to enforce add code color.
|
||||
td.add-code {
|
||||
background-color: #eaffea !important;
|
||||
border-color: #c1e9c1 !important;
|
||||
|
@ -749,6 +752,13 @@
|
|||
// background-color: #ffffdd !important;
|
||||
// }
|
||||
}
|
||||
|
||||
.removed-code {
|
||||
background-color: #ff9999;
|
||||
}
|
||||
.added-code {
|
||||
background-color: #99ff99;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1218,10 +1228,4 @@
|
|||
}
|
||||
}
|
||||
|
||||
.removed-code {
|
||||
background-color: #ff9999;
|
||||
}
|
||||
|
||||
.added-code {
|
||||
background-color: #99ff99;
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
0.8.17.0109
|
||||
0.8.18.0109
|
Loading…
Reference in a new issue