Merge branch 'dev' of github.com:gogits/gogs into dev

This commit is contained in:
skyblue 2014-04-12 09:42:15 +08:00
commit f8e97b75fb
16 changed files with 222 additions and 40 deletions

View file

@ -6,7 +6,9 @@ package models
import (
"bufio"
"bytes"
"container/list"
"errors"
"fmt"
"io"
"os"
@ -409,3 +411,85 @@ func GetDiff(repoPath, commitid string) (*Diff, error) {
defer rd.Close()
return ParsePatch(rd)
}
const prettyLogFormat = `--pretty=format:%H%n%an <%ae> %at%n%s`
func parsePrettyFormatLog(logByts []byte) (*list.List, error) {
l := list.New()
buf := bytes.NewBuffer(logByts)
if buf.Len() == 0 {
return l, nil
}
idx := 0
var commit *git.Commit
for {
line, err := buf.ReadString('\n')
if err != nil && err != io.EOF {
return nil, err
}
line = strings.TrimSpace(line)
// fmt.Println(line)
var parseErr error
switch idx {
case 0: // SHA1.
commit = &git.Commit{}
commit.Oid, parseErr = git.NewOidFromString(line)
case 1: // Signature.
commit.Author, parseErr = git.NewSignatureFromCommitline([]byte(line + " "))
case 2: // Commit message.
commit.CommitMessage = line
l.PushBack(commit)
idx = -1
}
if parseErr != nil {
return nil, parseErr
}
idx++
if err == io.EOF {
break
}
}
return l, nil
}
// SearchCommits searches commits in given branch and keyword of repository.
func SearchCommits(repoPath, branch, keyword string) (*list.List, error) {
stdout, stderr, err := com.ExecCmdDirBytes(repoPath, "git", "log", branch, "-100",
"-i", "--grep="+keyword, prettyLogFormat)
if err != nil {
return nil, err
} else if len(stderr) > 0 {
return nil, errors.New(string(stderr))
}
return parsePrettyFormatLog(stdout)
}
// GetCommitsByRange returns certain number of commits with given page of repository.
func GetCommitsByRange(repoPath, branch string, page int) (*list.List, error) {
stdout, stderr, err := com.ExecCmdDirBytes(repoPath, "git", "log", branch,
"--skip="+base.ToStr((page-1)*50), "--max-count=50", prettyLogFormat)
if err != nil {
return nil, err
} else if len(stderr) > 0 {
return nil, errors.New(string(stderr))
}
return parsePrettyFormatLog(stdout)
}
// GetCommitsCount returns the commits count of given branch of repository.
func GetCommitsCount(repoPath, branch string) (int, error) {
stdout, stderr, err := com.ExecCmdDir(repoPath, "git", "rev-list", "--count", branch)
if err != nil {
return 0, err
} else if len(stderr) > 0 {
return 0, errors.New(stderr)
}
return base.StrTo(strings.TrimSpace(stdout)).Int()
}

View file

@ -32,7 +32,7 @@ var (
func init() {
tables = append(tables, new(User), new(PublicKey), new(Repository), new(Watch),
new(Action), new(Access), new(Issue), new(Comment), new(Oauth2))
new(Action), new(Access), new(Issue), new(Comment), new(Oauth2), new(Follow))
}
func LoadModelsConfig() {

View file

@ -192,12 +192,6 @@ func CreateRepository(user *User, repoName, desc, repoLang, license string, priv
return nil, err
}
c := exec.Command("git", "update-server-info")
c.Dir = repoPath
if err = c.Run(); err != nil {
log.Error("repo.CreateRepository(exec update-server-info): %v", err)
}
if err = NewRepoAction(user, repo); err != nil {
log.Error("repo.CreateRepository(NewRepoAction): %v", err)
}
@ -210,6 +204,12 @@ func CreateRepository(user *User, repoName, desc, repoLang, license string, priv
return nil, err
}
c := exec.Command("git", "update-server-info")
c.Dir = repoPath
if err = c.Run(); err != nil {
log.Error("repo.CreateRepository(exec update-server-info): %v", err)
}
return repo, nil
}

View file

@ -294,6 +294,8 @@ func DeleteUser(user *User) error {
return err
}
// Delete oauth2.
// Delete all feeds.
if _, err = orm.Delete(&Action{UserId: user.Id}); err != nil {
return err