]> source.dussan.org Git - gitea.git/commitdiff
Delete commit and update getlastcommit
authorUnknown <joe2010xtmf@163.com>
Tue, 18 Mar 2014 04:14:05 +0000 (00:14 -0400)
committerUnknown <joe2010xtmf@163.com>
Tue, 18 Mar 2014 04:14:05 +0000 (00:14 -0400)
gogs.go
models/repo.go
routers/repo/single.go
templates/repo/single.tmpl

diff --git a/gogs.go b/gogs.go
index 433b9af09494a531949c45852c03635e72f26bf2..2757fbc115b2956f66b3aa58b3157f74bdf2c7e9 100644 (file)
--- a/gogs.go
+++ b/gogs.go
@@ -20,7 +20,7 @@ import (
 // Test that go1.1 tag above is included in builds. main.go refers to this definition.
 const go11tag = true
 
-const APP_VER = "0.1.0.0317.1"
+const APP_VER = "0.1.0.0318.1"
 
 func init() {
        base.AppVer = APP_VER
index 6e3754acf5dcf4a2d616eaa0b7d600778bfc95a7..21d46aa250853e3afb2679963fab874680a198d1 100644 (file)
@@ -400,15 +400,6 @@ func DeleteRepository(userId, repoId int64, userName string) (err error) {
        return nil
 }
 
-// Commit represents a git commit.
-type Commit struct {
-       Author  string
-       Email   string
-       Date    time.Time
-       SHA     string
-       Message string
-}
-
 var (
        ErrRepoFileNotLoaded = fmt.Errorf("repo file not loaded")
 )
@@ -553,34 +544,16 @@ func GetReposFiles(userName, reposName, branchName, rpath string) ([]*RepoFile,
 }
 
 // GetLastestCommit returns the latest commit of given repository.
-func GetLastestCommit(userName, repoName string) (*Commit, error) {
-       stdout, _, err := com.ExecCmd("git", "--git-dir="+RepoPath(userName, repoName), "log", "-1")
+func GetLastCommit(userName, repoName, branchname string) (*git.Commit, error) {
+       repo, err := git.OpenRepository(RepoPath(userName, repoName))
        if err != nil {
                return nil, err
        }
-
-       commit := new(Commit)
-       for _, line := range strings.Split(stdout, "\n") {
-               if len(line) == 0 {
-                       continue
-               }
-               switch {
-               case line[0] == 'c':
-                       commit.SHA = line[7:]
-               case line[0] == 'A':
-                       infos := strings.SplitN(line, " ", 3)
-                       commit.Author = infos[1]
-                       commit.Email = infos[2][1 : len(infos[2])-1]
-               case line[0] == 'D':
-                       commit.Date, err = time.Parse("Mon Jan 02 15:04:05 2006 -0700", line[8:])
-                       if err != nil {
-                               return nil, err
-                       }
-               case line[:4] == "    ":
-                       commit.Message = line[4:]
-               }
+       r, err := repo.LookupReference(fmt.Sprintf("refs/heads/%s", branchname))
+       if err != nil {
+               return nil, err
        }
-       return commit, nil
+       return r.LastCommit()
 }
 
 // GetCommits returns all commits of given branch of repository.
index 1b5da9d30732d994cc6efdcb13007a65b020b07b..64ea508b0ebedee34b0ffd106391abbcfc7f0c88 100644 (file)
@@ -90,13 +90,13 @@ func Single(ctx *middleware.Context, params martini.Params) {
        }
 
        // Get latest commit according username and repo name
-       commit, err := models.GetLastestCommit(params["username"], params["reponame"])
+       commit, err := models.GetLastCommit(params["username"], params["reponame"], params["branchname"])
        if err != nil {
                log.Error("repo.Single(GetLastestCommit): %v", err)
                ctx.Render.Error(404)
                return
        }
-       ctx.Data["LatestCommit"] = commit
+       ctx.Data["LastCommit"] = commit
 
        var readmeFile *models.RepoFile
 
index 019ec8eaaa90a7212ee9e4766f53c5a62907abe3..3831c2dc41b34f29841160b029a686921f87563c 100644 (file)
 
         <div class="panel panel-default info-box">
             <div class="panel-heading info-head">
-                <a href="/{{$username}}/{{$reponame}}/commit/{{.LatestCommit.SHA}}">{{.LatestCommit.Message}}</a>
+                <a href="/{{$username}}/{{$reponame}}/commit/{{.LastCommit.Oid.String}}">{{.LastCommit.Message}}</a>
             </div>
             <div class="panel-body info-content">
-                <a href="/user/{{.LatestCommit.Author}}">{{.LatestCommit.Author}}</a> <span class="text-muted">{{TimeSince .LatestCommit.Date}}</span>
+                <a href="/user/{{.LastCommit.Author.Name}}">{{.LastCommit.Author.Name}}</a> <span class="text-muted">{{TimeSince .LastCommit.Author.When}}</span>
             </div>
             <table class="panel-footer table file-list">
                 <thead class="hidden">