summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorlunnyxiao <xiaolunwen@gmail.com>2014-09-17 12:04:18 +0800
committerlunnyxiao <xiaolunwen@gmail.com>2014-09-17 12:04:18 +0800
commit061a879cea39a1cce56dcb394b912fad50d7b77a (patch)
tree26e8c3d25da1b9d785421a6a02b7564798b2e8c4 /modules
parented84adb679f3de70b2bffaead20a87711c38ee3a (diff)
parent9f015b4c73806e65d3ca085b76723dc8cf41eb02 (diff)
downloadgitea-061a879cea39a1cce56dcb394b912fad50d7b77a.tar.gz
gitea-061a879cea39a1cce56dcb394b912fad50d7b77a.zip
Merge branch 'dev' of github.com:gogits/gogs into dev
Conflicts: conf/app.ini
Diffstat (limited to 'modules')
-rw-r--r--modules/git/repo_commit.go8
-rw-r--r--modules/git/version.go76
-rw-r--r--modules/setting/setting.go3
3 files changed, 75 insertions, 12 deletions
diff --git a/modules/git/repo_commit.go b/modules/git/repo_commit.go
index eebe3dd0e0..cd0181c481 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.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))
+ }
+ 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)
diff --git a/modules/git/version.go b/modules/git/version.go
index 683e859b47..9908d11e20 100644
--- a/modules/git/version.go
+++ b/modules/git/version.go
@@ -11,33 +11,85 @@ 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()
case 1:
v.Minor, _ = com.StrTo(s).Int()
case 2:
- v.Patch, _ = com.StrTo(s).Int()
+ v.Patch, _ = com.StrTo(strings.TrimSpace(s)).Int()
}
}
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
+}
+
+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 {
+ 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
+}
diff --git a/modules/setting/setting.go b/modules/setting/setting.go
index 011c00c08c..c56ad2421a 100644
--- a/modules/setting/setting.go
+++ b/modules/setting/setting.go
@@ -10,6 +10,7 @@ import (
"os/exec"
"path"
"path/filepath"
+ "runtime"
"strings"
"time"
@@ -99,12 +100,14 @@ var (
CustomPath string // Custom directory path.
ProdMode bool
RunUser string
+ IsWindows bool
// I18n settings.
Langs, Names []string
)
func init() {
+ IsWindows = runtime.GOOS == "windows"
log.NewLogger(0, "console", `{"level": 0}`)
}