mirror of
https://codeberg.org/forgejo/forgejo
synced 2024-12-01 14:26:10 +01:00
Compare commits
No commits in common. "2524c64853f7c2671345deb7b2eba429341f9625" and "aca2ae23907ded7b959362d033e039c4caa71478" have entirely different histories.
2524c64853
...
aca2ae2390
|
@ -8,6 +8,7 @@ import (
|
||||||
gotemplate "html/template"
|
gotemplate "html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
|
@ -38,15 +39,32 @@ type blameRow struct {
|
||||||
|
|
||||||
// RefBlame render blame page
|
// RefBlame render blame page
|
||||||
func RefBlame(ctx *context.Context) {
|
func RefBlame(ctx *context.Context) {
|
||||||
if ctx.Repo.TreePath == "" {
|
fileName := ctx.Repo.TreePath
|
||||||
ctx.NotFound("No file specified", nil)
|
if len(fileName) == 0 {
|
||||||
|
ctx.NotFound("Blame FileName", nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
branchLink := ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL()
|
||||||
|
treeLink := branchLink
|
||||||
|
rawLink := ctx.Repo.RepoLink + "/raw/" + ctx.Repo.BranchNameSubURL()
|
||||||
|
|
||||||
|
if len(ctx.Repo.TreePath) > 0 {
|
||||||
|
treeLink += "/" + util.PathEscapeSegments(ctx.Repo.TreePath)
|
||||||
|
}
|
||||||
|
|
||||||
|
var treeNames []string
|
||||||
paths := make([]string, 0, 5)
|
paths := make([]string, 0, 5)
|
||||||
treeNames := strings.Split(ctx.Repo.TreePath, "/")
|
if len(ctx.Repo.TreePath) > 0 {
|
||||||
for i := range treeNames {
|
treeNames = strings.Split(ctx.Repo.TreePath, "/")
|
||||||
paths = append(paths, strings.Join(treeNames[:i+1], "/"))
|
for i := range treeNames {
|
||||||
|
paths = append(paths, strings.Join(treeNames[:i+1], "/"))
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.Data["HasParentPath"] = true
|
||||||
|
if len(paths)-2 >= 0 {
|
||||||
|
ctx.Data["ParentPath"] = "/" + paths[len(paths)-1]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get current entry user currently looking at.
|
// Get current entry user currently looking at.
|
||||||
|
@ -55,35 +73,47 @@ func RefBlame(ctx *context.Context) {
|
||||||
HandleGitError(ctx, "Repo.Commit.GetTreeEntryByPath", err)
|
HandleGitError(ctx, "Repo.Commit.GetTreeEntryByPath", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
blob := entry.Blob()
|
blob := entry.Blob()
|
||||||
|
|
||||||
ctx.Data["PageIsViewCode"] = true
|
|
||||||
ctx.Data["IsBlame"] = true
|
|
||||||
|
|
||||||
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL()
|
|
||||||
ctx.Data["RawFileLink"] = ctx.Repo.RepoLink + "/raw/" + ctx.Repo.BranchNameSubURL() + "/" + util.PathEscapeSegments(ctx.Repo.TreePath)
|
|
||||||
ctx.Data["Paths"] = paths
|
ctx.Data["Paths"] = paths
|
||||||
|
ctx.Data["TreeLink"] = treeLink
|
||||||
ctx.Data["TreeNames"] = treeNames
|
ctx.Data["TreeNames"] = treeNames
|
||||||
|
ctx.Data["BranchLink"] = branchLink
|
||||||
|
|
||||||
|
ctx.Data["RawFileLink"] = rawLink + "/" + util.PathEscapeSegments(ctx.Repo.TreePath)
|
||||||
|
ctx.Data["PageIsViewCode"] = true
|
||||||
|
|
||||||
|
ctx.Data["IsBlame"] = true
|
||||||
|
|
||||||
ctx.Data["FileSize"] = blob.Size()
|
ctx.Data["FileSize"] = blob.Size()
|
||||||
ctx.Data["FileName"] = blob.Name()
|
ctx.Data["FileName"] = blob.Name()
|
||||||
|
|
||||||
ctx.Data["NumLinesSet"] = true
|
|
||||||
ctx.Data["NumLines"], err = blob.GetBlobLineCount()
|
ctx.Data["NumLines"], err = blob.GetBlobLineCount()
|
||||||
|
ctx.Data["NumLinesSet"] = true
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetBlobLineCount", err)
|
ctx.NotFound("GetBlobLineCount", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := performBlame(ctx, ctx.Repo.Commit, ctx.Repo.TreePath, ctx.FormBool("bypass-blame-ignore"))
|
bypassBlameIgnore, _ := strconv.ParseBool(ctx.FormString("bypass-blame-ignore"))
|
||||||
|
|
||||||
|
result, err := performBlame(ctx, ctx.Repo.Repository.RepoPath(), ctx.Repo.Commit, fileName, bypassBlameIgnore)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("performBlame", err)
|
ctx.NotFound("CreateBlameReader", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Data["UsesIgnoreRevs"] = result.UsesIgnoreRevs
|
ctx.Data["UsesIgnoreRevs"] = result.UsesIgnoreRevs
|
||||||
ctx.Data["FaultyIgnoreRevsFile"] = result.FaultyIgnoreRevsFile
|
ctx.Data["FaultyIgnoreRevsFile"] = result.FaultyIgnoreRevsFile
|
||||||
|
|
||||||
|
// Get Topics of this repo
|
||||||
|
renderRepoTopics(ctx)
|
||||||
|
if ctx.Written() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
commitNames := processBlameParts(ctx, result.Parts)
|
commitNames := processBlameParts(ctx, result.Parts)
|
||||||
if ctx.Written() {
|
if ctx.Written() {
|
||||||
return
|
return
|
||||||
|
@ -100,13 +130,12 @@ type blameResult struct {
|
||||||
FaultyIgnoreRevsFile bool
|
FaultyIgnoreRevsFile bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func performBlame(ctx *context.Context, commit *git.Commit, file string, bypassBlameIgnore bool) (*blameResult, error) {
|
func performBlame(ctx *context.Context, repoPath string, commit *git.Commit, file string, bypassBlameIgnore bool) (*blameResult, error) {
|
||||||
repoPath := ctx.Repo.Repository.RepoPath()
|
|
||||||
objectFormat, err := ctx.Repo.GitRepo.GetObjectFormat()
|
objectFormat, err := ctx.Repo.GitRepo.GetObjectFormat()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
ctx.NotFound("CreateBlameReader", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
blameReader, err := git.CreateBlameReader(ctx, objectFormat, repoPath, commit, file, bypassBlameIgnore)
|
blameReader, err := git.CreateBlameReader(ctx, objectFormat, repoPath, commit, file, bypassBlameIgnore)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -368,7 +368,7 @@ func DeleteBranch(ctx context.Context, doer *user_model.User, repo *repo_model.R
|
||||||
|
|
||||||
rawBranch, err := git_model.GetBranch(ctx, repo.ID, branchName)
|
rawBranch, err := git_model.GetBranch(ctx, repo.ID, branchName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("GetBranch: %v", err)
|
return fmt.Errorf("GetBranch: %vc", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
objectFormat, err := gitRepo.GetObjectFormat()
|
objectFormat, err := gitRepo.GetObjectFormat()
|
||||||
|
|
Loading…
Reference in a new issue