mirror of
https://github.com/gogs/gogs.git
synced 2025-12-20 15:20:01 +01:00
diff: able to highlight line with hashtag URL
This commit is contained in:
2
gogs.go
2
gogs.go
@@ -16,7 +16,7 @@ import (
|
|||||||
"github.com/gogits/gogs/modules/setting"
|
"github.com/gogits/gogs/modules/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
const APP_VER = "0.9.160.0220"
|
const APP_VER = "0.9.161.0220"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
setting.AppVer = APP_VER
|
setting.AppVer = APP_VER
|
||||||
|
|||||||
@@ -188,7 +188,7 @@ func (diffSection *DiffSection) GetComputedInlineDiffFor(diffLine *DiffLine) tem
|
|||||||
type DiffFile struct {
|
type DiffFile struct {
|
||||||
Name string
|
Name string
|
||||||
OldName string
|
OldName string
|
||||||
Index int
|
Index string // 40-byte SHA, Changed/New: new SHA; Deleted: old SHA
|
||||||
Addition, Deletion int
|
Addition, Deletion int
|
||||||
Type DiffFileType
|
Type DiffFileType
|
||||||
IsCreated bool
|
IsCreated bool
|
||||||
@@ -331,7 +331,6 @@ func ParsePatch(maxLines, maxLineCharacteres, maxFiles int, reader io.Reader) (*
|
|||||||
|
|
||||||
curFile = &DiffFile{
|
curFile = &DiffFile{
|
||||||
Name: a,
|
Name: a,
|
||||||
Index: len(diff.Files) + 1,
|
|
||||||
Type: DIFF_FILE_CHANGE,
|
Type: DIFF_FILE_CHANGE,
|
||||||
Sections: make([]*DiffSection, 0, 10),
|
Sections: make([]*DiffSection, 0, 10),
|
||||||
}
|
}
|
||||||
@@ -343,7 +342,8 @@ func ParsePatch(maxLines, maxLineCharacteres, maxFiles int, reader io.Reader) (*
|
|||||||
}
|
}
|
||||||
curFileLinesCount = 0
|
curFileLinesCount = 0
|
||||||
|
|
||||||
// Check file diff type and is submodule.
|
// Check file diff type and submodule.
|
||||||
|
CHECK_TYPE:
|
||||||
for {
|
for {
|
||||||
line, err := input.ReadString('\n')
|
line, err := input.ReadString('\n')
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -358,22 +358,25 @@ func ParsePatch(maxLines, maxLineCharacteres, maxFiles int, reader io.Reader) (*
|
|||||||
case strings.HasPrefix(line, "new file"):
|
case strings.HasPrefix(line, "new file"):
|
||||||
curFile.Type = DIFF_FILE_ADD
|
curFile.Type = DIFF_FILE_ADD
|
||||||
curFile.IsCreated = true
|
curFile.IsCreated = true
|
||||||
|
curFile.IsSubmodule = strings.HasSuffix(line, " 160000\n")
|
||||||
case strings.HasPrefix(line, "deleted"):
|
case strings.HasPrefix(line, "deleted"):
|
||||||
curFile.Type = DIFF_FILE_DEL
|
curFile.Type = DIFF_FILE_DEL
|
||||||
curFile.IsDeleted = true
|
curFile.IsDeleted = true
|
||||||
|
curFile.IsSubmodule = strings.HasSuffix(line, " 160000\n")
|
||||||
case strings.HasPrefix(line, "index"):
|
case strings.HasPrefix(line, "index"):
|
||||||
curFile.Type = DIFF_FILE_CHANGE
|
if curFile.IsDeleted {
|
||||||
|
curFile.Index = line[6:46]
|
||||||
|
} else {
|
||||||
|
curFile.Index = line[49:88]
|
||||||
|
}
|
||||||
|
break CHECK_TYPE
|
||||||
case strings.HasPrefix(line, "similarity index 100%"):
|
case strings.HasPrefix(line, "similarity index 100%"):
|
||||||
curFile.Type = DIFF_FILE_RENAME
|
curFile.Type = DIFF_FILE_RENAME
|
||||||
curFile.IsRenamed = true
|
curFile.IsRenamed = true
|
||||||
curFile.OldName = curFile.Name
|
curFile.OldName = curFile.Name
|
||||||
curFile.Name = b
|
curFile.Name = b
|
||||||
}
|
curFile.Index = b
|
||||||
if curFile.Type > 0 {
|
break CHECK_TYPE
|
||||||
if strings.HasSuffix(line, " 160000\n") {
|
|
||||||
curFile.IsSubmodule = true
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -423,13 +426,13 @@ func GetDiffRange(repoPath, beforeCommitID, afterCommitID string, maxLines, maxL
|
|||||||
if len(beforeCommitID) == 0 {
|
if len(beforeCommitID) == 0 {
|
||||||
// First commit of repository.
|
// First commit of repository.
|
||||||
if commit.ParentCount() == 0 {
|
if commit.ParentCount() == 0 {
|
||||||
cmd = exec.Command("git", "show", afterCommitID)
|
cmd = exec.Command("git", "show", "--full-index", afterCommitID)
|
||||||
} else {
|
} else {
|
||||||
c, _ := commit.Parent(0)
|
c, _ := commit.Parent(0)
|
||||||
cmd = exec.Command("git", "diff", "-M", c.ID.String(), afterCommitID)
|
cmd = exec.Command("git", "diff", "--full-index", "-M", c.ID.String(), afterCommitID)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
cmd = exec.Command("git", "diff", "-M", beforeCommitID, afterCommitID)
|
cmd = exec.Command("git", "diff", "--full-index", "-M", beforeCommitID, afterCommitID)
|
||||||
}
|
}
|
||||||
cmd.Dir = repoPath
|
cmd.Dir = repoPath
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
|
|||||||
@@ -2065,8 +2065,15 @@ footer .ui.language .menu {
|
|||||||
border-right: 1px solid #d4d4d5;
|
border-right: 1px solid #d4d4d5;
|
||||||
padding: 0 5px;
|
padding: 0 5px;
|
||||||
}
|
}
|
||||||
.repository .diff-file-box .code-diff tbody tr.tag-code td,
|
.repository .diff-file-box .code-diff .lines-num.lines-num-old,
|
||||||
.repository .diff-file-box .code-diff tbody tr.tag-code pre {
|
.repository .diff-file-box .code-diff .lines-num.lines-num-new {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.repository .diff-file-box .code-diff .lines-num.lines-num-old:hover,
|
||||||
|
.repository .diff-file-box .code-diff .lines-num.lines-num-new:hover {
|
||||||
|
color: #383636;
|
||||||
|
}
|
||||||
|
.repository .diff-file-box .code-diff tbody tr.tag-code td {
|
||||||
background-color: #F0F0F0 !important;
|
background-color: #F0F0F0 !important;
|
||||||
border-color: #D2CECE!important;
|
border-color: #D2CECE!important;
|
||||||
padding-top: 4px;
|
padding-top: 4px;
|
||||||
@@ -2075,6 +2082,9 @@ footer .ui.language .menu {
|
|||||||
.repository .diff-file-box .code-diff tbody tr.tag-code td.halfwidth {
|
.repository .diff-file-box .code-diff tbody tr.tag-code td.halfwidth {
|
||||||
width: 50%;
|
width: 50%;
|
||||||
}
|
}
|
||||||
|
.repository .diff-file-box .code-diff tbody tr.same-code td.active {
|
||||||
|
background-color: #ffffdd !important;
|
||||||
|
}
|
||||||
.repository .diff-file-box .code-diff tbody tr.del-code td.add-code {
|
.repository .diff-file-box .code-diff tbody tr.del-code td.add-code {
|
||||||
background-color: #eaffea !important;
|
background-color: #eaffea !important;
|
||||||
border-color: #c1e9c1 !important;
|
border-color: #c1e9c1 !important;
|
||||||
@@ -2083,22 +2093,26 @@ footer .ui.language .menu {
|
|||||||
background-color: #eaffea !important;
|
background-color: #eaffea !important;
|
||||||
border-color: #c1e9c1 !important;
|
border-color: #c1e9c1 !important;
|
||||||
}
|
}
|
||||||
.repository .diff-file-box .code-diff tbody tr.del-code td,
|
.repository .diff-file-box .code-diff tbody tr.del-code td {
|
||||||
.repository .diff-file-box .code-diff tbody tr.del-code pre {
|
|
||||||
background-color: #ffecec !important;
|
background-color: #ffecec !important;
|
||||||
border-color: #f1c0c0 !important;
|
border-color: #f1c0c0 !important;
|
||||||
}
|
}
|
||||||
|
.repository .diff-file-box .code-diff tbody tr.del-code td.active {
|
||||||
|
background-color: #ffffdd !important;
|
||||||
|
}
|
||||||
.repository .diff-file-box .code-diff tbody tr.del-code td.halfwidth {
|
.repository .diff-file-box .code-diff tbody tr.del-code td.halfwidth {
|
||||||
width: 50%;
|
width: 50%;
|
||||||
}
|
}
|
||||||
.repository .diff-file-box .code-diff tbody tr.add-code td,
|
.repository .diff-file-box .code-diff tbody tr.add-code td {
|
||||||
.repository .diff-file-box .code-diff tbody tr.add-code pre {
|
|
||||||
background-color: #eaffea !important;
|
background-color: #eaffea !important;
|
||||||
border-color: #c1e9c1 !important;
|
border-color: #c1e9c1 !important;
|
||||||
}
|
}
|
||||||
.repository .diff-file-box .code-diff tbody tr.add-code td.halfwidth {
|
.repository .diff-file-box .code-diff tbody tr.add-code td.halfwidth {
|
||||||
width: 50%;
|
width: 50%;
|
||||||
}
|
}
|
||||||
|
.repository .diff-file-box .code-diff tbody tr.add-code td.active {
|
||||||
|
background-color: #ffffdd !important;
|
||||||
|
}
|
||||||
.repository .diff-file-box .code-diff tbody tr .removed-code {
|
.repository .diff-file-box .code-diff tbody tr .removed-code {
|
||||||
background-color: #ff9999;
|
background-color: #ff9999;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -542,6 +542,20 @@ function initRepository() {
|
|||||||
$item.find(".bar .add").css("width", addPercent + "%");
|
$item.find(".bar .add").css("width", addPercent + "%");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$('.diff-file-box .lines-num').click(function () {
|
||||||
|
if ($(this).attr('id')) {
|
||||||
|
window.location.href = '#' + $(this).attr('id');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$(window).on('hashchange', function (e) {
|
||||||
|
$('.diff-file-box .lines-code.active').removeClass('active');
|
||||||
|
var m = window.location.hash.match(/^#diff-.+$/);
|
||||||
|
if (m) {
|
||||||
|
$(m[0]).siblings('.lines-code').addClass('active');
|
||||||
|
}
|
||||||
|
}).trigger('hashchange');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Quick start and repository home
|
// Quick start and repository home
|
||||||
|
|||||||
@@ -1005,12 +1005,19 @@
|
|||||||
.lines-num {
|
.lines-num {
|
||||||
border-right: 1px solid #d4d4d5;
|
border-right: 1px solid #d4d4d5;
|
||||||
padding: 0 5px;
|
padding: 0 5px;
|
||||||
|
|
||||||
|
&.lines-num-old, &.lines-num-new {
|
||||||
|
cursor: pointer;
|
||||||
|
&:hover {
|
||||||
|
color: #383636;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
tbody {
|
tbody {
|
||||||
tr {
|
tr {
|
||||||
|
|
||||||
&.tag-code {
|
&.tag-code {
|
||||||
td, pre {
|
td {
|
||||||
background-color: #F0F0F0 !important;
|
background-color: #F0F0F0 !important;
|
||||||
border-color: #D2CECE!important;
|
border-color: #D2CECE!important;
|
||||||
padding-top: 4px;
|
padding-top: 4px;
|
||||||
@@ -1019,15 +1026,12 @@
|
|||||||
td.halfwidth {
|
td.halfwidth {
|
||||||
width: 50%;
|
width: 50%;
|
||||||
}
|
}
|
||||||
// td.selected-line, td.selected-line pre {
|
|
||||||
// background-color: #ffffdd !important;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
// &.same-code {
|
&.same-code {
|
||||||
// td.selected-line, td.selected-line pre {
|
td.active {
|
||||||
// background-color: #ffffdd !important;
|
background-color: #ffffdd !important;
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
&.del-code {
|
&.del-code {
|
||||||
// Duplicate here to enforce add code color.
|
// Duplicate here to enforce add code color.
|
||||||
td.add-code {
|
td.add-code {
|
||||||
@@ -1039,29 +1043,29 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
td, pre {
|
td {
|
||||||
background-color: #ffecec !important;
|
background-color: #ffecec !important;
|
||||||
border-color: #f1c0c0 !important;
|
border-color: #f1c0c0 !important;
|
||||||
}
|
}
|
||||||
|
td.active {
|
||||||
|
background-color: #ffffdd !important;
|
||||||
|
}
|
||||||
|
|
||||||
td.halfwidth {
|
td.halfwidth {
|
||||||
width: 50%;
|
width: 50%;
|
||||||
}
|
}
|
||||||
// td.selected-line, td.selected-line pre {
|
|
||||||
// background-color: #ffffdd !important;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
&.add-code {
|
&.add-code {
|
||||||
td, pre {
|
td {
|
||||||
background-color: #eaffea !important;
|
background-color: #eaffea !important;
|
||||||
border-color: #c1e9c1 !important;
|
border-color: #c1e9c1 !important;
|
||||||
}
|
}
|
||||||
td.halfwidth {
|
td.halfwidth {
|
||||||
width: 50%;
|
width: 50%;
|
||||||
}
|
}
|
||||||
// td.selected-line, td.selected-line pre {
|
td.active {
|
||||||
// background-color: #ffffdd !important;
|
background-color: #ffffdd !important;
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.removed-code {
|
.removed-code {
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
0.9.160.0220
|
0.9.161.0220
|
||||||
@@ -8,14 +8,18 @@
|
|||||||
{{/* {{if gt $j 0}}<span class="fold octicon octicon-fold"></span>{{end}} */}}
|
{{/* {{if gt $j 0}}<span class="fold octicon octicon-fold"></span>{{end}} */}}
|
||||||
</td>
|
</td>
|
||||||
{{else}}
|
{{else}}
|
||||||
<td class="lines-num lines-num-old">
|
<td class="lines-num lines-num-old" {{if $line.LeftIdx}}id="diff-{{$file.Index}}L{{$line.LeftIdx}}"{{end}}>
|
||||||
<span rel="{{if $line.LeftIdx}}diff-{{Sha1 $file.Name}}L{{$line.LeftIdx}}{{end}}">{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}</span>
|
{{if $line.LeftIdx}}
|
||||||
|
<span>{{$line.LeftIdx}}</span>
|
||||||
|
{{end}}
|
||||||
</td>
|
</td>
|
||||||
<td class="lines-num lines-num-new">
|
<td class="lines-num lines-num-new" {{if $line.RightIdx}}id="diff-{{$file.Index}}R{{$line.RightIdx}}"{{end}}>
|
||||||
<span rel="{{if $line.RightIdx}}diff-{{Sha1 $file.Name}}R{{$line.RightIdx}}{{end}}">{{if $line.RightIdx}}{{$line.RightIdx}}{{end}}</span>
|
{{if $line.RightIdx}}
|
||||||
|
<span>{{$line.RightIdx}}</span>
|
||||||
|
{{end}}
|
||||||
</td>
|
</td>
|
||||||
{{end}}
|
{{end}}
|
||||||
<td class="lines-code">
|
<td class="lines-code" rel="">
|
||||||
<pre><code class="{{if $highlightClass}}language-{{$highlightClass}}{{else}}nohighlight{{end}}">{{$section.GetComputedInlineDiffFor $line}}</code></pre>
|
<pre><code class="{{if $highlightClass}}language-{{$highlightClass}}{{else}}nohighlight{{end}}">{{$section.GetComputedInlineDiffFor $line}}</code></pre>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
Reference in New Issue
Block a user