add IsSubmodule field to DiffFile and hide view file button on diff page for submodules (#3097)

This commit is contained in:
Siarhei Navatski
2016-07-22 21:18:56 +03:00
repo.diff.committed_by 无闻
repo.diff.parent 599716bb1b
repo.diff.commit cf85e9eb7b
repo.diff.stats_desc%!(EXTRA int=2, int=14, int=8)

repo.diff.view_file

@@ -160,6 +160,7 @@ type DiffFile struct {
IsDeleted bool
IsBin bool
IsRenamed bool
IsSubmodule bool
Sections []*DiffSection
IsIncomplete bool
}
@@ -306,7 +307,7 @@ func ParsePatch(maxLines, maxLineCharacteres, maxFiles int, reader io.Reader) (*
}
curFileLinesCount = 0
// Check file diff type.
// Check file diff type and is submodule.
for {
line, err := input.ReadString('\n')
if err != nil {
@@ -333,6 +334,9 @@ func ParsePatch(maxLines, maxLineCharacteres, maxFiles int, reader io.Reader) (*
curFile.Name = b
}
if curFile.Type > 0 {
if strings.HasSuffix(line, " 160000\n") {
curFile.IsSubmodule = true
}
break
}
}

repo.diff.view_file

@@ -68,13 +68,15 @@
{{end}}
</div>
<span class="file">{{if $file.IsRenamed}}{{$file.OldName}} &rarr; {{end}}{{$file.Name}}</span>
<div class="ui right">
{{if $file.IsDeleted}}
<a class="ui basic tiny button" rel="nofollow" href="{{EscapePound $.BeforeSourcePath}}/{{EscapePound .Name}}">{{$.i18n.Tr "repo.diff.view_file"}}</a>
{{else}}
<a class="ui basic tiny button" rel="nofollow" href="{{EscapePound $.SourcePath}}/{{EscapePound .Name}}">{{$.i18n.Tr "repo.diff.view_file"}}</a>
{{end}}
</div>
{{if not $file.IsSubmodule}}
<div class="ui right">
{{if $file.IsDeleted}}
<a class="ui basic tiny button" rel="nofollow" href="{{EscapePound $.BeforeSourcePath}}/{{EscapePound .Name}}">{{$.i18n.Tr "repo.diff.view_file"}}</a>
{{else}}
<a class="ui basic tiny button" rel="nofollow" href="{{EscapePound $.SourcePath}}/{{EscapePound .Name}}">{{$.i18n.Tr "repo.diff.view_file"}}</a>
{{end}}
</div>
{{end}}
</h4>
<div class="ui attached table segment">
{{if not $file.IsRenamed}}