]> source.dussan.org Git - gitea.git/commitdiff
Work on #476
authorUnknwon <joe2010xtmf@163.com>
Tue, 16 Sep 2014 14:10:33 +0000 (10:10 -0400)
committerUnknwon <joe2010xtmf@163.com>
Tue, 16 Sep 2014 14:10:33 +0000 (10:10 -0400)
README.md
README_ZH.md
gogs.go
models/repo.go
modules/git/repo_commit.go
modules/git/version.go
templates/.VERSION

index 3c319896af974771154bde43beccfb26b921113c..43d75c264bd33c42b74f63916f4ce92b3c216683 100644 (file)
--- a/README.md
+++ b/README.md
@@ -5,7 +5,7 @@ Gogs(Go Git Service) is a painless self-hosted Git Service written in Go.
 
 ![Demo](https://gowalker.org/public/gogs_demo.gif)
 
-##### Current version: 0.5.0 Beta
+##### Current version: 0.5.2 Beta
 
 ### NOTICES
 
index 7faeee2beadd586c796f49d0793484d17f71520c..bf6c1d03a1578e9bc4f6c9431ca34648dc1f7284 100644 (file)
@@ -5,7 +5,7 @@ Gogs(Go Git Service) 是一个基于 Go 语言的自助 Git 服务。
 
 ![Demo](https://gowalker.org/public/gogs_demo.gif)
 
-##### 当前版本:0.5.1 Beta
+##### 当前版本:0.5.2 Beta
 
 ## 开发目的
 
diff --git a/gogs.go b/gogs.go
index f0aebf03673a49594e1825abe58a3bbd5cbdae1d..8ae7449e2b99777fa52d33c56c6f6fd27e778d8d 100644 (file)
--- a/gogs.go
+++ b/gogs.go
@@ -17,7 +17,7 @@ import (
        "github.com/gogits/gogs/modules/setting"
 )
 
-const APP_VER = "0.5.1.0916 Beta"
+const APP_VER = "0.5.2.0916 Beta"
 
 func init() {
        runtime.GOMAXPROCS(runtime.NumCPU())
index 25876872eb8acfaabdf19ab722c1fd216acd8cbf..a8e53dbcd7378579ee990ab6974a0361b5b0cdef 100644 (file)
@@ -95,8 +95,13 @@ func NewRepoContext() {
        if err != nil {
                log.Fatal(4, "Fail to get Git version: %v", err)
        }
-       if ver.Major < 2 && ver.Minor < 8 {
-               log.Fatal(4, "Gogs requires Git version greater or equal to 1.8.0")
+
+       reqVer, err := git.ParseVersion("1.7.1")
+       if err != nil {
+               log.Fatal(4, "Fail to parse required Git version: %v", err)
+       }
+       if ver.Compare(reqVer) == -1 {
+               log.Fatal(4, "Gogs requires Git version greater or equal to 1.7.1")
        }
 
        // Check if server has basic git setting and set if not.
index eebe3dd0e0869392c767864deac3a7c1a80d3ad1..c9258927bb132b66d1b3d147385d5acaaf161508 100644 (file)
@@ -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)
index 683e859b4798a76914d4675736c2f72f89245f86..653503c03cb12aff9a4036ac712ff68c8ac895b5 100644 (file)
@@ -11,25 +11,24 @@ import (
        "github.com/Unknwon/com"
 )
 
+var (
+       // Cached Git version.
+       gitVer *Version
+)
+
 // Version represents version of Git.
 type Version struct {
        Major, Minor, Patch int
 }
 
-// GetVersion returns current Git version installed.
-func GetVersion() (Version, error) {
-       stdout, stderr, err := com.ExecCmd("git", "version")
-       if err != nil {
-               return Version{}, errors.New(stderr)
-       }
-
-       infos := strings.Split(stdout, " ")
+func ParseVersion(verStr string) (*Version, error) {
+       infos := strings.Split(verStr, ".")
        if len(infos) < 3 {
-               return Version{}, errors.New("not enough output")
+               return nil, errors.New("incorrect version input")
        }
 
-       v := Version{}
-       for i, s := range strings.Split(strings.TrimSpace(infos[2]), ".") {
+       v := &Version{}
+       for i, s := range infos {
                switch i {
                case 0:
                        v.Major, _ = com.StrTo(s).Int()
@@ -41,3 +40,52 @@ func GetVersion() (Version, error) {
        }
        return v, nil
 }
+
+func MustParseVersion(verStr string) *Version {
+       v, _ := ParseVersion(verStr)
+       return v
+}
+
+// Compare compares two versions,
+// 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
+       } else if v.Major < that.Major {
+               return -1
+       }
+
+       if v.Minor > that.Minor {
+               return 1
+       } else if v.Minor < that.Minor {
+               return -1
+       }
+
+       if v.Patch > that.Patch {
+               return 1
+       } else if v.Patch < that.Patch {
+               return -1
+       }
+
+       return 0
+}
+
+// GetVersion returns current Git version installed.
+func GetVersion() (*Version, error) {
+       if gitVer != nil {
+               return gitVer, nil
+       }
+
+       stdout, stderr, err := com.ExecCmd("git", "version")
+       if err != nil {
+               return nil, errors.New(stderr)
+       }
+
+       infos := strings.Split(stdout, " ")
+       if len(infos) < 3 {
+               return nil, errors.New("not enough output")
+       }
+
+       gitVer, err = ParseVersion(infos[2])
+       return gitVer, err
+}
index 261667dbe15798d7ab16bdd84c04015213c21ebc..aada89d11a0b30bb18a82280df82cbc1546dbc73 100644 (file)
@@ -1 +1 @@
-0.5.1.0916 Beta
\ No newline at end of file
+0.5.2.0916 Beta
\ No newline at end of file