From 0d9c41be7d7d4ae1d2a28931be5565c8f6d3f792 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Tue, 16 Sep 2014 10:10:33 -0400 Subject: Work on #476 --- modules/git/repo_commit.go | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'modules/git/repo_commit.go') diff --git a/modules/git/repo_commit.go b/modules/git/repo_commit.go index eebe3dd0..c9258927 100644 --- a/modules/git/repo_commit.go +++ b/modules/git/repo_commit.go @@ -137,6 +137,14 @@ func (repo *Repository) GetCommit(commitId string) (*Commit, error) { } func (repo *Repository) commitsCount(id sha1) (int, error) { + if gitVer.Compare(MustParseVersion("1.8.0")) == -1 { + stdout, stderr, err := com.ExecCmdDirBytes(repo.Path, "git", "log", "--pretty=format:''", id.String()) + if err != nil { + return 0, errors.New(string(stderr)) + } + return len(bytes.Split(stdout, []byte("\n"))), nil + } + stdout, stderr, err := com.ExecCmdDir(repo.Path, "git", "rev-list", "--count", id.String()) if err != nil { return 0, errors.New(stderr) -- cgit v1.2.3 From 62f21ff3ed1b85a1d3a1eab73da354e4f6e8794a Mon Sep 17 00:00:00 2001 From: Unknwon Date: Tue, 16 Sep 2014 11:29:53 -0400 Subject: Work on #476 --- models/repo.go | 2 +- modules/git/repo_commit.go | 2 +- modules/git/version.go | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-) (limited to 'modules/git/repo_commit.go') diff --git a/models/repo.go b/models/repo.go index a8e53dbc..2e162704 100644 --- a/models/repo.go +++ b/models/repo.go @@ -100,7 +100,7 @@ func NewRepoContext() { if err != nil { log.Fatal(4, "Fail to parse required Git version: %v", err) } - if ver.Compare(reqVer) == -1 { + if ver.LessThan(reqVer) { log.Fatal(4, "Gogs requires Git version greater or equal to 1.7.1") } diff --git a/modules/git/repo_commit.go b/modules/git/repo_commit.go index c9258927..cd0181c4 100644 --- a/modules/git/repo_commit.go +++ b/modules/git/repo_commit.go @@ -137,7 +137,7 @@ func (repo *Repository) GetCommit(commitId string) (*Commit, error) { } func (repo *Repository) commitsCount(id sha1) (int, error) { - if gitVer.Compare(MustParseVersion("1.8.0")) == -1 { + if gitVer.LessThan(MustParseVersion("1.8.0")) { stdout, stderr, err := com.ExecCmdDirBytes(repo.Path, "git", "log", "--pretty=format:''", id.String()) if err != nil { return 0, errors.New(string(stderr)) diff --git a/modules/git/version.go b/modules/git/version.go index 653503c0..546397aa 100644 --- a/modules/git/version.go +++ b/modules/git/version.go @@ -47,7 +47,7 @@ func MustParseVersion(verStr string) *Version { } // Compare compares two versions, -// it returns 1 if original is greater, 1 if original is smaller, 0 if equal. +// it returns 1 if original is greater, -1 if original is smaller, 0 if equal. func (v *Version) Compare(that *Version) int { if v.Major > that.Major { return 1 @@ -70,6 +70,10 @@ func (v *Version) Compare(that *Version) int { return 0 } +func (v *Version) LessThan(that *Version) bool { + return v.Compare(that) < 0 +} + // GetVersion returns current Git version installed. func GetVersion() (*Version, error) { if gitVer != nil { -- cgit v1.2.3 From 2a031c13658458df9f8f56ce295a8ba72bf35dff Mon Sep 17 00:00:00 2001 From: Unknwon Date: Tue, 30 Sep 2014 04:39:53 -0400 Subject: Fix #515 --- gogs.go | 2 +- modules/git/repo_commit.go | 4 ++-- modules/git/repo_tag.go | 2 +- modules/git/tree.go | 5 ++++- modules/middleware/repo.go | 5 ++--- public/ng/css/gogs.css | 1 - public/ng/less/gogs/dashboard.less | 1 - routers/repo/view.go | 1 + templates/.VERSION | 2 +- 9 files changed, 12 insertions(+), 11 deletions(-) (limited to 'modules/git/repo_commit.go') diff --git a/gogs.go b/gogs.go index e7615c9b..0ea64d26 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.5.4.0929 Beta" +const APP_VER = "0.5.4.0930 Beta" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/modules/git/repo_commit.go b/modules/git/repo_commit.go index cd0181c4..7c47b53d 100644 --- a/modules/git/repo_commit.go +++ b/modules/git/repo_commit.go @@ -40,11 +40,11 @@ func (repo *Repository) GetCommitIdOfTag(tagName string) (string, error) { } func (repo *Repository) GetCommitOfTag(tagName string) (*Commit, error) { - commitId, err := repo.GetCommitIdOfTag(tagName) + tag, err := repo.GetTag(tagName) if err != nil { return nil, err } - return repo.GetCommit(commitId) + return tag.Commit() } // Parse commit information from the (uncompressed) raw diff --git a/modules/git/repo_tag.go b/modules/git/repo_tag.go index dd31e441..77ae3db0 100644 --- a/modules/git/repo_tag.go +++ b/modules/git/repo_tag.go @@ -52,6 +52,7 @@ func (repo *Repository) getTag(id sha1) (*Tag, error) { if err != nil { return nil, errors.New(stderr) } + tp = strings.TrimSpace(tp) // Tag is a commit. if ObjectType(tp) == COMMIT { @@ -77,7 +78,6 @@ func (repo *Repository) getTag(id sha1) (*Tag, error) { } tag.Id = id - tag.Object = id tag.repo = repo repo.tagCache[id] = tag diff --git a/modules/git/tree.go b/modules/git/tree.go index a3012443..be77bfce 100644 --- a/modules/git/tree.go +++ b/modules/git/tree.go @@ -109,9 +109,12 @@ func (t *Tree) ListEntries(relpath string) (Entries, error) { } t.entriesParsed = true - stdout, _, err := com.ExecCmdDirBytes(t.repo.Path, + stdout, stderr, err := com.ExecCmdDirBytes(t.repo.Path, "git", "ls-tree", t.Id.String()) if err != nil { + if strings.Contains(err.Error(), "exit status 128") { + return nil, errors.New(strings.TrimSpace(string(stderr))) + } return nil, err } t.entries, err = parseTreeData(t, stdout) diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go index c0290b2e..c6250f6d 100644 --- a/modules/middleware/repo.go +++ b/modules/middleware/repo.go @@ -208,10 +208,9 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler { } else if gitRepo.IsTagExist(refName) { ctx.Repo.IsTag = true ctx.Repo.BranchName = refName - - ctx.Repo.Commit, err = gitRepo.GetCommitOfTag(refName) + ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetCommitOfTag(refName) if err != nil { - ctx.Handle(500, "RepoAssignment invalid tag", err) + ctx.Handle(500, "Fail to get tag commit", err) return } ctx.Repo.CommitId = ctx.Repo.Commit.Id.String() diff --git a/public/ng/css/gogs.css b/public/ng/css/gogs.css index 6d38ac9b..feb21c97 100644 --- a/public/ng/css/gogs.css +++ b/public/ng/css/gogs.css @@ -833,7 +833,6 @@ ol.linenums { } #dashboard-my-repo .repo-count { margin-left: 4px; - font-size: .8em; } #dashboard-my-org, #dashboard-my-mirror { diff --git a/public/ng/less/gogs/dashboard.less b/public/ng/less/gogs/dashboard.less index e7a1e90c..a40debe5 100644 --- a/public/ng/less/gogs/dashboard.less +++ b/public/ng/less/gogs/dashboard.less @@ -139,7 +139,6 @@ } .repo-count { margin-left: 4px; - font-size: .8em; } } #dashboard-my-org, diff --git a/routers/repo/view.go b/routers/repo/view.go index 82f34600..ba76a6ad 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -118,6 +118,7 @@ func Home(ctx *middleware.Context) { ctx.Handle(404, "SubTree", err) return } + entries, err := tree.ListEntries(treename) if err != nil { ctx.Handle(500, "ListEntries", err) diff --git a/templates/.VERSION b/templates/.VERSION index 2d0d24c2..c734a8f0 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.5.4.0929 Beta \ No newline at end of file +0.5.4.0930 Beta \ No newline at end of file -- cgit v1.2.3