]> source.dussan.org Git - gitea.git/commitdiff
Fixed commit count. (#17698)
authorKN4CK3R <admin@oldschoolhack.me>
Wed, 17 Nov 2021 23:50:17 +0000 (00:50 +0100)
committerGitHub <noreply@github.com>
Wed, 17 Nov 2021 23:50:17 +0000 (23:50 +0000)
Added "Tag" label.
Unified branch, tag and commit name.

modules/context/repo.go
options/locale/locale_en-US.ini
routers/web/repo/branch.go
routers/web/repo/commit.go
routers/web/repo/view.go
templates/repo/branch_dropdown.tmpl
templates/repo/commits_table.tmpl
templates/repo/sub_menu.tmpl

index 3be33f2483808c7432ac2b1f58c7ce5ea516ab0f..e3d66fc3b98ac203802d41e5b6d16bb9d46d15f8 100644 (file)
@@ -59,6 +59,7 @@ type Repository struct {
        Commit       *git.Commit
        Tag          *git.Tag
        GitRepo      *git.Repository
+       RefName      string
        BranchName   string
        TagName      string
        TreePath     string
@@ -191,9 +192,9 @@ func (r *Repository) BranchNameSubURL() string {
        case r.IsViewBranch:
                return "branch/" + util.PathEscapeSegments(r.BranchName)
        case r.IsViewTag:
-               return "tag/" + util.PathEscapeSegments(r.BranchName)
+               return "tag/" + util.PathEscapeSegments(r.TagName)
        case r.IsViewCommit:
-               return "commit/" + util.PathEscapeSegments(r.BranchName)
+               return "commit/" + util.PathEscapeSegments(r.CommitID)
        }
        log.Error("Unknown view type for repo: %v", r)
        return ""
@@ -563,8 +564,6 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
        ctx.Data["Branches"] = brs
        ctx.Data["BranchesCount"] = len(brs)
 
-       ctx.Data["TagName"] = ctx.Repo.TagName
-
        // If not branch selected, try default one.
        // If default branch doesn't exists, fall back to some other branch.
        if len(ctx.Repo.BranchName) == 0 {
@@ -573,9 +572,9 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
                } else if len(brs) > 0 {
                        ctx.Repo.BranchName = brs[0]
                }
+               ctx.Repo.RefName = ctx.Repo.BranchName
        }
        ctx.Data["BranchName"] = ctx.Repo.BranchName
-       ctx.Data["CommitID"] = ctx.Repo.CommitID
 
        // People who have push access or have forked repository can propose a new pull request.
        canPush := ctx.Repo.CanWrite(unit_model.TypeCode) || (ctx.IsSigned && ctx.User.HasForkedRepo(ctx.Repo.Repository.ID))
@@ -781,7 +780,6 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
                // Get default branch.
                if len(ctx.Params("*")) == 0 {
                        refName = ctx.Repo.Repository.DefaultBranch
-                       ctx.Repo.BranchName = refName
                        if !ctx.Repo.GitRepo.IsBranchExist(refName) {
                                brs, _, err := ctx.Repo.GitRepo.GetBranches(0, 0)
                                if err != nil {
@@ -795,6 +793,8 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
                                }
                                refName = brs[0]
                        }
+                       ctx.Repo.RefName = refName
+                       ctx.Repo.BranchName = refName
                        ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(refName)
                        if err != nil {
                                ctx.ServerError("GetBranchCommit", err)
@@ -805,7 +805,7 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
 
                } else {
                        refName = getRefName(ctx, refType)
-                       ctx.Repo.BranchName = refName
+                       ctx.Repo.RefName = refName
                        isRenamedBranch, has := ctx.Data["IsRenamedBranch"].(bool)
                        if isRenamedBranch && has {
                                renamedBranchName := ctx.Data["RenamedBranchName"].(string)
@@ -817,6 +817,7 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
 
                        if refType.RefTypeIncludesBranches() && ctx.Repo.GitRepo.IsBranchExist(refName) {
                                ctx.Repo.IsViewBranch = true
+                               ctx.Repo.BranchName = refName
 
                                ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(refName)
                                if err != nil {
@@ -827,6 +828,8 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
 
                        } else if refType.RefTypeIncludesTags() && ctx.Repo.GitRepo.IsTagExist(refName) {
                                ctx.Repo.IsViewTag = true
+                               ctx.Repo.TagName = refName
+
                                ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetTagCommit(refName)
                                if err != nil {
                                        ctx.ServerError("GetTagCommit", err)
@@ -870,6 +873,7 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
 
                ctx.Data["BranchName"] = ctx.Repo.BranchName
                ctx.Data["BranchNameSubURL"] = ctx.Repo.BranchNameSubURL()
+               ctx.Data["TagName"] = ctx.Repo.TagName
                ctx.Data["CommitID"] = ctx.Repo.CommitID
                ctx.Data["TreePath"] = ctx.Repo.TreePath
                ctx.Data["IsViewBranch"] = ctx.Repo.IsViewBranch
index 062ce029323e93f1263116906e52b8d7f49f2457..66996b201456715f1812e0535eed93b56dc27db8 100644 (file)
@@ -971,6 +971,7 @@ release = Release
 releases = Releases
 tag = Tag
 released_this = released this
+file.title =  %s at %s
 file_raw = Raw
 file_history = History
 file_view_source = View Source
index 10557ff3db088057ff3241c48f259089083f1e18..27cd06023d49a903a6018fcd4f5eb90a92757009 100644 (file)
@@ -344,17 +344,15 @@ func CreateBranch(ctx *context.Context) {
        var err error
 
        if form.CreateTag {
-               if ctx.Repo.IsViewTag {
-                       err = release_service.CreateNewTag(ctx.User, ctx.Repo.Repository, ctx.Repo.CommitID, form.NewBranchName, "")
-               } else {
-                       err = release_service.CreateNewTag(ctx.User, ctx.Repo.Repository, ctx.Repo.BranchName, form.NewBranchName, "")
+               target := ctx.Repo.CommitID
+               if ctx.Repo.IsViewBranch {
+                       target = ctx.Repo.BranchName
                }
+               err = release_service.CreateNewTag(ctx.User, ctx.Repo.Repository, target, form.NewBranchName, "")
        } else if ctx.Repo.IsViewBranch {
                err = repo_service.CreateNewBranch(ctx.User, ctx.Repo.Repository, ctx.Repo.BranchName, form.NewBranchName)
-       } else if ctx.Repo.IsViewTag {
-               err = repo_service.CreateNewBranchFromCommit(ctx.User, ctx.Repo.Repository, ctx.Repo.CommitID, form.NewBranchName)
        } else {
-               err = repo_service.CreateNewBranchFromCommit(ctx.User, ctx.Repo.Repository, ctx.Repo.BranchName, form.NewBranchName)
+               err = repo_service.CreateNewBranchFromCommit(ctx.User, ctx.Repo.Repository, ctx.Repo.CommitID, form.NewBranchName)
        }
        if err != nil {
                if models.IsErrTagAlreadyExists(err) {
index 06cce92417a2080a27701d6b77eb3c616f5e351d..c9e2b94f239acdaa16b016a0cba00f2c8ee6df7e 100644 (file)
@@ -77,7 +77,7 @@ func Commits(ctx *context.Context) {
        ctx.Data["Username"] = ctx.Repo.Owner.Name
        ctx.Data["Reponame"] = ctx.Repo.Repository.Name
        ctx.Data["CommitCount"] = commitsCount
-       ctx.Data["Branch"] = ctx.Repo.BranchName
+       ctx.Data["RefName"] = ctx.Repo.RefName
 
        pager := context.NewPagination(int(commitsCount), setting.Git.CommitsRangeSize, page, 5)
        pager.SetDefaultParams(ctx)
@@ -153,7 +153,7 @@ func Graph(ctx *context.Context) {
        ctx.Data["Username"] = ctx.Repo.Owner.Name
        ctx.Data["Reponame"] = ctx.Repo.Repository.Name
        ctx.Data["CommitCount"] = commitsCount
-       ctx.Data["Branch"] = ctx.Repo.BranchName
+       ctx.Data["RefName"] = ctx.Repo.RefName
        paginator := context.NewPagination(int(graphCommitsCount), setting.UI.GraphMaxCommitNum, page, 5)
        paginator.AddParam(ctx, "mode", "Mode")
        paginator.AddParam(ctx, "hide-pr-refs", "HidePRRefs")
@@ -199,7 +199,7 @@ func SearchCommits(ctx *context.Context) {
        }
        ctx.Data["Username"] = ctx.Repo.Owner.Name
        ctx.Data["Reponame"] = ctx.Repo.Repository.Name
-       ctx.Data["Branch"] = ctx.Repo.BranchName
+       ctx.Data["RefName"] = ctx.Repo.RefName
        ctx.HTML(http.StatusOK, tplCommits)
 }
 
@@ -213,8 +213,7 @@ func FileHistory(ctx *context.Context) {
                return
        }
 
-       branchName := ctx.Repo.BranchName
-       commitsCount, err := ctx.Repo.GitRepo.FileCommitsCount(branchName, fileName)
+       commitsCount, err := ctx.Repo.GitRepo.FileCommitsCount(ctx.Repo.RefName, fileName)
        if err != nil {
                ctx.ServerError("FileCommitsCount", err)
                return
@@ -228,7 +227,7 @@ func FileHistory(ctx *context.Context) {
                page = 1
        }
 
-       commits, err := ctx.Repo.GitRepo.CommitsByFileAndRange(branchName, fileName, page)
+       commits, err := ctx.Repo.GitRepo.CommitsByFileAndRange(ctx.Repo.RefName, fileName, page)
        if err != nil {
                ctx.ServerError("CommitsByFileAndRange", err)
                return
@@ -239,7 +238,7 @@ func FileHistory(ctx *context.Context) {
        ctx.Data["Reponame"] = ctx.Repo.Repository.Name
        ctx.Data["FileName"] = fileName
        ctx.Data["CommitCount"] = commitsCount
-       ctx.Data["Branch"] = branchName
+       ctx.Data["RefName"] = ctx.Repo.RefName
 
        pager := context.NewPagination(int(commitsCount), setting.Git.CommitsRangeSize, page, 5)
        pager.SetDefaultParams(ctx)
index 938292a37a6b0cc6237341437b29410b779bdf47..d455dc1039a34a24dded5c42a3a25978c6ee2645 100644 (file)
@@ -371,7 +371,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
        }
        defer dataRc.Close()
 
-       ctx.Data["Title"] = ctx.Data["Title"].(string) + " - " + ctx.Repo.TreePath + " at " + ctx.Repo.BranchName
+       ctx.Data["Title"] = ctx.Data["Title"].(string) + " - " + ctx.Tr("repo.file.title", ctx.Repo.TreePath, ctx.Repo.RefName)
 
        fileSize := blob.Size()
        ctx.Data["FileIsSymlink"] = entry.IsLink()
index a2115729b289816162a6e2af72361ecccd6ffd8c..a6120483b5a23f3faf592087d5802f36fc1e99d9 100644 (file)
@@ -7,9 +7,9 @@
                                {{if $release}}
                                        {{.root.i18n.Tr "repo.release.compare"}}
                                {{else}}
-                                       {{svg "octicon-git-branch"}}
-                                       {{if .root.IsViewBranch}}{{.root.i18n.Tr "repo.branch"}}{{else}}{{.root.i18n.Tr "repo.tree"}}{{end}}:
-                                       <strong>{{if .root.IsViewBranch}}{{.root.BranchName}}{{else}}{{ShortSha .root.BranchName}}{{end}}</strong>
+                                       {{if .root.IsViewTag}}{{svg "octicon-tag"}}{{else}}{{svg "octicon-git-branch"}}{{end}}
+                                       {{if .root.IsViewBranch}}{{.root.i18n.Tr "repo.branch"}}{{else if .root.IsViewTag}}{{.root.i18n.Tr "repo.tag"}}{{else}}{{.root.i18n.Tr "repo.tree"}}{{end}}:
+                                       <strong>{{if .root.IsViewBranch}}{{.root.BranchName}}{{else if .root.IsViewTag}}{{.root.TagName}}{{else}}{{ShortSha .root.CommitID}}{{end}}</strong>
                                {{end}}
                        </span>
                        {{svg "octicon-triangle-down" 14 "dropdown icon"}}
                                                <div class="text small">
                                                        {{if or .root.IsViewBranch $release}}
                                                                {{.root.i18n.Tr "repo.branch.create_from" .root.BranchName}}
+                                                       {{else if .root.IsViewTag}}
+                                                               {{.root.i18n.Tr "repo.branch.create_from" .root.TagName}}
                                                        {{else}}
-                                                               {{.root.i18n.Tr "repo.branch.create_from" (ShortSha .root.BranchName)}}
+                                                               {{.root.i18n.Tr "repo.branch.create_from" (ShortSha .root.CommitID)}}
                                                        {{end}}
                                                </div>
                                        </a>
index 4871b688a70e5fde332ae549d946284e1ed4e723..edd5f7285a97a036e4ff34a140e28aec59ae01e5 100644 (file)
@@ -1,12 +1,11 @@
 <h4 class="ui top attached header commits-table df ac sb">
        <div class="commits-table-left df ac">
                {{if or .PageIsCommits (gt .CommitCount 0)}}
-                       {{.CommitCount}} {{.i18n.Tr "repo.commits.commits"}} {{if .Branch}}({{.Branch}}){{end}}
-               {{else if .IsNothingToCompare }}
-                       {{.i18n.Tr "repo.commits.nothing_to_compare" }} {{if .Branch}}({{.Branch}}){{end}}
-
+                       {{.CommitCount}} {{.i18n.Tr "repo.commits.commits"}} {{if .RefName}}({{.RefName}}){{end}}
+               {{else if .IsNothingToCompare}}
+                       {{.i18n.Tr "repo.commits.nothing_to_compare" }} {{if .RefName}}({{.RefName}}){{end}}
                {{else}}
-                       {{.i18n.Tr "repo.commits.no_commits" $.BaseBranch $.HeadBranch }} {{if .Branch}}({{.Branch}}){{end}}
+                       {{.i18n.Tr "repo.commits.no_commits" $.BaseBranch $.HeadBranch}} {{if .RefName}}({{.RefName}}){{end}}
                {{end}}
        </div>
        <div class="commits-table-right df ac">
index 3b05708c74620a48e87ee7c6b4994050ceefcfbf..1fec6dcec13482f80de9eaac1f086bf64358ad78 100644 (file)
@@ -3,7 +3,7 @@
                <div class="ui two horizontal center link list">
                        {{if and (.Permission.CanRead $.UnitTypeCode) (not .IsEmptyRepo)}}
                                <div class="item{{if .PageIsCommits}} active{{end}}">
-                                       <a class="ui" href="{{.RepoLink}}/commits{{if .IsViewBranch}}/branch{{else if .IsViewTag}}/tag{{else if .IsViewCommit}}/commit{{end}}/{{PathEscapeSegments .BranchName}}">{{svg "octicon-history"}} <b>{{.CommitsCount}}</b> {{.i18n.Tr (TrN .i18n.Lang .CommitsCount "repo.commit" "repo.commits") }}</a>
+                                       <a class="ui" href="{{.RepoLink}}/commits/{{.BranchNameSubURL}}">{{svg "octicon-history"}} <b>{{.CommitsCount}}</b> {{.i18n.Tr (TrN .i18n.Lang .CommitsCount "repo.commit" "repo.commits") }}</a>
                                </div>
                                <div class="item{{if .PageIsBranches}} active{{end}}">
                                        <a class="ui" href="{{.RepoLink}}/branches">{{svg "octicon-git-branch"}} <b>{{.BranchesCount}}</b> {{.i18n.Tr (TrN .i18n.Lang .BranchesCount "repo.branch" "repo.branches") }}</a>