0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-12-23 15:53:07 -05:00
This commit is contained in:
Unknown 2014-05-12 20:22:35 -04:00
parent f979d0d6b9
commit c117f9e73f
5 changed files with 69 additions and 5 deletions

View file

@ -210,6 +210,7 @@ func runWeb(*cli.Context) {
r.Get("/raw/:branchname/**", repo.SingleDownload) r.Get("/raw/:branchname/**", repo.SingleDownload)
r.Get("/commits/:branchname", repo.Commits) r.Get("/commits/:branchname", repo.Commits)
r.Get("/commits/:branchname/search", repo.SearchCommits) r.Get("/commits/:branchname/search", repo.SearchCommits)
r.Get("/commits/:branchname/**", repo.FileHistory)
r.Get("/commit/:branchname", repo.Diff) r.Get("/commit/:branchname", repo.Diff)
r.Get("/commit/:branchname/**", repo.Diff) r.Get("/commit/:branchname/**", repo.Diff)
r.Get("/releases", repo.Releases) r.Get("/releases", repo.Releases)

View file

@ -50,7 +50,7 @@ func Commits(ctx *middleware.Context, params martini.Params) {
//both `git log branchName` and `git log commitId` work //both `git log branchName` and `git log commitId` work
commits, err := ctx.Repo.Commit.CommitsByRange(page) commits, err := ctx.Repo.Commit.CommitsByRange(page)
if err != nil { if err != nil {
ctx.Handle(500, "repo.Commits(get commits)", err) ctx.Handle(500, "repo.Commits(CommitsByRange)", err)
return return
} }
@ -149,3 +149,65 @@ func SearchCommits(ctx *middleware.Context, params martini.Params) {
ctx.Data["IsRepoToolbarCommits"] = true ctx.Data["IsRepoToolbarCommits"] = true
ctx.HTML(200, "repo/commits") ctx.HTML(200, "repo/commits")
} }
func FileHistory(ctx *middleware.Context, params martini.Params) {
fileName := params["_1"]
if len(fileName) == 0 {
Commits(ctx, params)
return
}
userName := ctx.Repo.Owner.Name
repoName := ctx.Repo.Repository.Name
branchName := params["branchname"]
brs, err := ctx.Repo.GitRepo.GetBranches()
if err != nil {
ctx.Handle(500, "repo.FileHistory", err)
return
} else if len(brs) == 0 {
ctx.Handle(404, "repo.FileHistory", nil)
return
}
commitsCount, err := ctx.Repo.GitRepo.FileCommitsCount(branchName, fileName)
if err != nil {
ctx.Handle(500, "repo.FileHistory(GetCommitsCount)", err)
return
}
if commitsCount == 0 {
ctx.Handle(404, "repo.FileHistory", nil)
return
}
// Calculate and validate page number.
page, _ := base.StrTo(ctx.Query("p")).Int()
if page < 1 {
page = 1
}
lastPage := page - 1
if lastPage < 0 {
lastPage = 0
}
nextPage := page + 1
if nextPage*50 > commitsCount {
nextPage = 0
}
//both `git log branchName` and `git log commitId` work
commits, err := ctx.Repo.GitRepo.CommitsByFileAndRange(branchName, fileName, page)
if err != nil {
ctx.Handle(500, "repo.FileHistory(CommitsByRange)", err)
return
}
ctx.Data["Username"] = userName
ctx.Data["Reponame"] = repoName
ctx.Data["FileName"] = fileName
ctx.Data["CommitCount"] = commitsCount
ctx.Data["Commits"] = commits
ctx.Data["LastPageNum"] = lastPage
ctx.Data["NextPageNum"] = nextPage
ctx.Data["IsRepoToolbarCommits"] = true
ctx.HTML(200, "repo/commits")
}

View file

@ -254,6 +254,7 @@ func Single(ctx *middleware.Context, params martini.Params) {
ctx.Data["LastCommit"] = ctx.Repo.Commit ctx.Data["LastCommit"] = ctx.Repo.Commit
ctx.Data["Paths"] = Paths ctx.Data["Paths"] = Paths
ctx.Data["TreeName"] = treename
ctx.Data["Treenames"] = treenames ctx.Data["Treenames"] = treenames
ctx.Data["TreePath"] = treePath ctx.Data["TreePath"] = treePath
ctx.Data["BranchLink"] = branchLink ctx.Data["BranchLink"] = branchLink

View file

@ -41,8 +41,8 @@
</table> </table>
</div> </div>
{{if not .IsSearchPage}}<ul class="pagination" id="commits-pager"> {{if not .IsSearchPage}}<ul class="pagination" id="commits-pager">
{{if .LastPageNum}}<li><a href="{{.RepoLink}}/commits/{{.BranchName}}?p={{.LastPageNum}}" rel="nofollow">&laquo; Newer</a></li>{{end}} {{if .LastPageNum}}<li><a href="{{.RepoLink}}/commits/{{.BranchName}}{{if .FileName}}/{{.FileName}}{{end}}?p={{.LastPageNum}}" rel="nofollow">&laquo; Newer</a></li>{{end}}
{{if .NextPageNum}}<li><a href="{{.RepoLink}}/commits/{{.BranchName}}?p={{.NextPageNum}}" rel="nofollow">&raquo; Older</a></li>{{end}} {{if .NextPageNum}}<li><a href="{{.RepoLink}}/commits/{{.BranchName}}{{if .FileName}}/{{.FileName}}{{end}}?p={{.NextPageNum}}" rel="nofollow">&raquo; Older</a></li>{{end}}
</ul>{{end}} </ul>{{end}}
</div> </div>
</div> </div>

View file

@ -16,7 +16,7 @@
<a class="btn btn-default hidden" href="#">Edit</a> <a class="btn btn-default hidden" href="#">Edit</a>
<a class="btn btn-default" href="{{.FileLink}}" rel="nofollow">Raw</a> <a class="btn btn-default" href="{{.FileLink}}" rel="nofollow">Raw</a>
<a class="btn btn-default hidden" href="#">Blame</a> <a class="btn btn-default hidden" href="#">Blame</a>
<a class="btn btn-default hidden" href="#">History</a> <a class="btn btn-default" href="{{.RepoLink}}/commits/{{.BranchName}}/{{.TreeName}}">History</a>
<a class="btn btn-danger hidden" href="#">Delete</a> <a class="btn btn-danger hidden" href="#">Delete</a>
</div> </div>
{{end}} {{end}}