Browse Source

Update to reflect API changes

pull/2135/head
tso 9 years ago
parent
commit
769a1b3096
  1. 66
      routers/repo/view.go

66
routers/repo/view.go

@ -16,7 +16,7 @@ import (
"github.com/Unknwon/com" "github.com/Unknwon/com"
"github.com/Unknwon/paginater" "github.com/Unknwon/paginater"
"github.com/gogits/git-shell" "github.com/gogits/git-module"
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/log"
@ -199,7 +199,7 @@ func Home(ctx *middleware.Context) {
ctx.Data["LastCommit"] = lastCommit ctx.Data["LastCommit"] = lastCommit
ctx.Data["LastCommitUser"] = models.ValidateCommitWithEmail(lastCommit) ctx.Data["LastCommitUser"] = models.ValidateCommitWithEmail(lastCommit)
branchId, err := ctx.Repo.GitRepo.GetCommitIdOfBranch(branchName) branchId, err := ctx.Repo.GitRepo.GetBranchCommitID(branchName)
if err != nil || branchId != lastCommit.ID.String() { if err != nil || branchId != lastCommit.ID.String() {
branchId = lastCommit.ID.String() branchId = lastCommit.ID.String()
} }
@ -313,7 +313,7 @@ func getLanguageStats(ctx *middleware.Context, branchId string) interface{} {
break break
} }
lang := results[p] lang := results[p]
color := linguist.GetColor(lang) color := linguist.LanguageColor(lang)
if color == "" { if color == "" {
color = "#ccc" //grey color = "#ccc" //grey
} }
@ -374,17 +374,10 @@ func linguistlstree(ctx *middleware.Context, treeish string) (files []*file) {
fname := fields[1] fname := fields[1]
switch ftype { switch ftype {
// broken, don't know why case "tree":
// case "tree": subdir := linguistlstree(ctx, fhash)
// subdir := linguistlstree(ctx, fhash) files = append(files, subdir...)
// files = append(files, subdir...)
case "blob": case "blob":
// if it's vendored, don't even look at it
// (vendored means files like README.md, .gitignore, etc...)
if linguist.IsVendored(fname) {
continue
}
ssize := gitcmd(ctx, "cat-file", "-s", fhash) ssize := gitcmd(ctx, "cat-file", "-s", fhash)
fsize, err := strconv.ParseFloat(strings.TrimSpace(ssize), 64) fsize, err := strconv.ParseFloat(strings.TrimSpace(ssize), 64)
tsoErr(ctx, err) tsoErr(ctx, err)
@ -394,48 +387,37 @@ func linguistlstree(ctx *middleware.Context, treeish string) (files []*file) {
continue continue
} }
f := &file{}
f.Name = fname
f.Size = fsize
// //
// language detection // language detection
// see github.com/generaltso/linguist
// //
if linguist.ShouldIgnoreFilename(fname) {
// by file extension
by_ext := linguist.DetectFromFilename(fname)
if by_ext != "" {
f.Language = by_ext
files = append(files, f)
continue continue
} }
// by mimetype
// if we can't guess type by extension, then before jumping into f := &file{}
// lexing and parsing things like image files or cat videos f.Name = fname
// ...or other binary formats which will give erroneous results... f.Size = fsize
// ...or other binary formats which will give erroneous results...
// with the linguist.DetectFromContents method, I posit looking by_name := linguist.LanguageByFilename(fname)
// at mimetype with linguist.DetectMimeFromFilename if by_name != "" {
// f.Language = by_name
// ...however, this is not what github does at all, instead ignoring
// binary files altogether. However, there is no law that states
// git must be used for code only.
by_mime, shouldIgnore, _ := linguist.DetectMimeFromFilename(fname)
if by_mime != "" && shouldIgnore {
f.Language = by_mime
files = append(files, f) files = append(files, f)
continue continue
} }
// by contents hints := linguist.LanguageHints(fname)
// see also: github.com/github/linguist
// see also: github.com/generaltso/linguist
contents := gitcmdbytes(ctx, "cat-file", "blob", fhash) contents := gitcmdbytes(ctx, "cat-file", "blob", fhash)
by_contents := linguist.DetectFromContents(contents)
if linguist.ShouldIgnoreContents(contents) {
continue
}
by_contents := linguist.LanguageByContents(contents, hints)
if by_contents != "" { if by_contents != "" {
f.Language = by_contents f.Language = by_contents
} else { } else {
f.Language = "(undetermined)" f.Language = "(unknown)"
} }
files = append(files, f) files = append(files, f)
} }

Loading…
Cancel
Save