diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index ea9f6147ae292..1746bc69d6471 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -90,6 +90,7 @@ remove = Remove remove_all = Remove All remove_label_str = Remove item "%s" edit = Edit +empty_file = Empty File enabled = Enabled disabled = Disabled diff --git a/routers/web/repo/blame.go b/routers/web/repo/blame.go index b1cb42297c1a6..600bad70f0f85 100644 --- a/routers/web/repo/blame.go +++ b/routers/web/repo/blame.go @@ -94,7 +94,6 @@ func RefBlame(ctx *context.Context) { ctx.Data["FileName"] = blob.Name() ctx.Data["NumLines"], err = blob.GetBlobLineCount() - ctx.Data["NumLinesSet"] = true if err != nil { ctx.NotFound("GetBlobLineCount", err) diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index f0fe6140dfb8e..6a95e9901f7fa 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -463,6 +463,16 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st ctx.Data["HasSourceRenderedToggle"] = true } + buf, _ := io.ReadAll(rd) + + // empty: 0 lines; "a": one line; "a\n": two lines; "a\nb": two lines; + // the NumLines is only used for the display on the UI: "xxx lines" + if len(buf) == 0 { + ctx.Data["NumLines"] = 0 + } else { + ctx.Data["NumLines"] = bytes.Count(buf, []byte{'\n'}) + 1 + } + if markupType != "" && !shouldRenderSource { ctx.Data["IsMarkup"] = true ctx.Data["MarkupType"] = markupType @@ -486,17 +496,6 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st // to prevent iframe load third-party url ctx.Resp.Header().Add("Content-Security-Policy", "frame-src 'self'") } else { - buf, _ := io.ReadAll(rd) - - // empty: 0 lines; "a": one line; "a\n": two lines; "a\nb": two lines; - // the NumLines is only used for the display on the UI: "xxx lines" - if len(buf) == 0 { - ctx.Data["NumLines"] = 0 - } else { - ctx.Data["NumLines"] = bytes.Count(buf, []byte{'\n'}) + 1 - } - ctx.Data["NumLinesSet"] = true - language := "" indexFilename, worktree, deleteTemporaryFile, err := ctx.Repo.GitRepo.ReadTreeToTemporaryIndex(ctx.Repo.CommitID) diff --git a/templates/repo/blame.tmpl b/templates/repo/blame.tmpl index b253c4d90143b..1fcf790d094c4 100644 --- a/templates/repo/blame.tmpl +++ b/templates/repo/blame.tmpl @@ -20,46 +20,50 @@
-
-
-
- {{$row.Avatar}}
-
-
-
- {{$row.CommitSince}}
+ {{if .BlameRows}}
+ {{range $row := .BlameRows}}
+
+ |
-
+
-
-
+
+ {{$row.Avatar}}
+
+
+
+ {{$row.CommitSince}}
+
- {{if $row.PreviousSha}}
-
- {{svg "octicon-versions"}}
-
- {{end}}
- |
-
-
- |
- {{if $.EscapeStatus.Escaped}}
-
- {{if $row.EscapeStatus.Escaped}}
-
+ |
+
+ {{if $row.PreviousSha}}
+
+ {{svg "octicon-versions"}}
+
{{end}}
|
- {{end}}
-
- |
- {{$row.Code}}
-
+
+ |
+ {{if $.EscapeStatus.Escaped}}
+
+ {{if $row.EscapeStatus.Escaped}}
+
+ {{end}}
+ |
+ {{end}}
+
+ |
+ {{$row.Code}}
+ |
{{if .FileContent}}{{.FileContent | Safe}}{{end}}+ {{if .FileContent}} +
{{.FileContent | Safe}}+ {{else}} +
{{if .FileContent}}{{.FileContent | Safe}}{{end}}+ {{if .FileContent}} +
{{.FileContent | Safe}}+ {{else}} +