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

This commit is contained in:
Unknown 2014-05-03 01:38:22 -04:00
commit bb0bc0a240
7 changed files with 45 additions and 36 deletions

View File

@ -175,7 +175,7 @@ func runServ(k *cli.Context) {
qlog.Fatal("Unknown command") qlog.Fatal("Unknown command")
} }
models.SetRepoEnvs(user.Id, user.Name, repoName) models.SetRepoEnvs(user.Id, user.Name, repoName, repoUserName)
gitcmd := exec.Command(verb, repoPath) gitcmd := exec.Command(verb, repoPath)
gitcmd.Dir = base.RepoRootPath gitcmd.Dir = base.RepoRootPath

View File

@ -76,10 +76,10 @@ func runUpdate(c *cli.Context) {
//updateEnv(args[0], args[1], args[2]) //updateEnv(args[0], args[1], args[2])
userName := os.Getenv("userName") userName := os.Getenv("userName")
userId := os.Getenv("userId") userId, _ := strconv.ParseInt(os.Getenv("userId"), 10, 64)
iUserId, _ := strconv.ParseInt(userId, 10, 64)
//repoId := os.Getenv("repoId") //repoId := os.Getenv("repoId")
repoUserName := os.Getenv("repoUserName")
repoName := os.Getenv("repoName") repoName := os.Getenv("repoName")
models.Update(args[0], args[1], args[2], userName, repoName, iUserId) models.Update(args[0], args[1], args[2], userName, repoUserName, repoName, userId)
} }

View File

@ -20,7 +20,7 @@ import (
// Test that go1.2 tag above is included in builds. main.go refers to this definition. // Test that go1.2 tag above is included in builds. main.go refers to this definition.
const go12tag = true const go12tag = true
const APP_VER = "0.3.2.0502 Alpha" const APP_VER = "0.3.2.0503 Alpha"
func init() { func init() {
base.AppVer = APP_VER base.AppVer = APP_VER

View File

@ -10,6 +10,7 @@ import (
"time" "time"
"github.com/gogits/git" "github.com/gogits/git"
qlog "github.com/qiniu/log"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/log"
@ -38,6 +39,7 @@ type Action struct {
ActUserName string // Action user name. ActUserName string // Action user name.
ActEmail string ActEmail string
RepoId int64 RepoId int64
RepoUserName string
RepoName string RepoName string
RefName string RefName string
IsPrivate bool `xorm:"NOT NULL DEFAULT false"` IsPrivate bool `xorm:"NOT NULL DEFAULT false"`
@ -70,8 +72,8 @@ func (a Action) GetContent() string {
} }
// CommitRepoAction adds new action for committing repository. // CommitRepoAction adds new action for committing repository.
func CommitRepoAction(userId int64, userName, actEmail string, func CommitRepoAction(userId, repoUserId int64, userName, actEmail string,
repoId int64, repoName string, refName string, commit *base.PushCommits) error { repoId int64, repoUserName, repoName string, refName string, commit *base.PushCommits) error {
// log.Trace("action.CommitRepoAction(start): %d/%s", userId, repoName) // log.Trace("action.CommitRepoAction(start): %d/%s", userId, repoName)
opType := OP_COMMIT_REPO opType := OP_COMMIT_REPO
@ -85,30 +87,31 @@ func CommitRepoAction(userId int64, userName, actEmail string,
bs, err := json.Marshal(commit) bs, err := json.Marshal(commit)
if err != nil { if err != nil {
log.Error("action.CommitRepoAction(json): %d/%s", userId, repoName) qlog.Error("action.CommitRepoAction(json): %d/%s", repoUserId, repoName)
return err return err
} }
// Change repository bare status and update last updated time. // Change repository bare status and update last updated time.
repo, err := GetRepositoryByName(userId, repoName) repo, err := GetRepositoryByName(repoUserId, repoName)
if err != nil { if err != nil {
log.Error("action.CommitRepoAction(GetRepositoryByName): %d/%s", userId, repoName) qlog.Error("action.CommitRepoAction(GetRepositoryByName): %d/%s", repoUserId, repoName)
return err return err
} }
repo.IsBare = false repo.IsBare = false
if err = UpdateRepository(repo); err != nil { if err = UpdateRepository(repo); err != nil {
log.Error("action.CommitRepoAction(UpdateRepository): %d/%s", userId, repoName) qlog.Error("action.CommitRepoAction(UpdateRepository): %d/%s", repoUserId, repoName)
return err return err
} }
if err = NotifyWatchers(&Action{ActUserId: userId, ActUserName: userName, ActEmail: actEmail, if err = NotifyWatchers(&Action{ActUserId: userId, ActUserName: userName, ActEmail: actEmail,
OpType: opType, Content: string(bs), RepoId: repoId, RepoName: repoName, RefName: refName, OpType: opType, Content: string(bs), RepoId: repoId, RepoUserName: repoUserName,
RepoName: repoName, RefName: refName,
IsPrivate: repo.IsPrivate}); err != nil { IsPrivate: repo.IsPrivate}); err != nil {
log.Error("action.CommitRepoAction(notify watchers): %d/%s", userId, repoName) qlog.Error("action.CommitRepoAction(notify watchers): %d/%s", userId, repoName)
return err return err
} }
log.Trace("action.CommitRepoAction(end): %d/%s", userId, repoName) qlog.Info("action.CommitRepoAction(end): %d/%s", repoUserId, repoName)
return nil return nil
} }

View File

@ -379,10 +379,11 @@ func createHookUpdate(hookPath, content string) error {
} }
// SetRepoEnvs sets environment variables for command update. // SetRepoEnvs sets environment variables for command update.
func SetRepoEnvs(userId int64, userName, repoName string) { func SetRepoEnvs(userId int64, userName, repoName, repoUserName string) {
os.Setenv("userId", base.ToStr(userId)) os.Setenv("userId", base.ToStr(userId))
os.Setenv("userName", userName) os.Setenv("userName", userName)
os.Setenv("repoName", repoName) os.Setenv("repoName", repoName)
os.Setenv("repoUserName", repoUserName)
} }
// InitRepository initializes README and .gitignore if needed. // InitRepository initializes README and .gitignore if needed.
@ -459,7 +460,7 @@ func initRepository(f string, user *User, repo *Repository, initReadme bool, rep
return nil return nil
} }
SetRepoEnvs(user.Id, user.Name, repo.Name) SetRepoEnvs(user.Id, user.Name, repo.Name, user.Name)
// Apply changes and commit. // Apply changes and commit.
return initRepoCommit(tmpDir, user.NewGitSig()) return initRepoCommit(tmpDir, user.NewGitSig())

View File

@ -16,14 +16,14 @@ import (
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
) )
func Update(refName, oldCommitId, newCommitId, userName, repoName string, userId int64) { func Update(refName, oldCommitId, newCommitId, userName, repoUserName, repoName string, userId int64) {
isNew := strings.HasPrefix(oldCommitId, "0000000") isNew := strings.HasPrefix(oldCommitId, "0000000")
if isNew && if isNew &&
strings.HasPrefix(newCommitId, "0000000") { strings.HasPrefix(newCommitId, "0000000") {
qlog.Fatal("old rev and new rev both 000000") qlog.Fatal("old rev and new rev both 000000")
} }
f := RepoPath(userName, repoName) f := RepoPath(repoUserName, repoName)
gitUpdate := exec.Command("git", "update-server-info") gitUpdate := exec.Command("git", "update-server-info")
gitUpdate.Dir = f gitUpdate.Dir = f
@ -65,7 +65,12 @@ func Update(refName, oldCommitId, newCommitId, userName, repoName string, userId
qlog.Fatalf("runUpdate.Commit repoId: %v", err) qlog.Fatalf("runUpdate.Commit repoId: %v", err)
} }
repos, err := GetRepositoryByName(userId, repoName) ru, err := GetUserByName(repoUserName)
if err != nil {
qlog.Fatalf("runUpdate.GetUserByName: %v", err)
}
repos, err := GetRepositoryByName(ru.Id, repoName)
if err != nil { if err != nil {
qlog.Fatalf("runUpdate.GetRepositoryByName userId: %v", err) qlog.Fatalf("runUpdate.GetRepositoryByName userId: %v", err)
} }
@ -89,8 +94,8 @@ func Update(refName, oldCommitId, newCommitId, userName, repoName string, userId
} }
//commits = append(commits, []string{lastCommit.Id().String(), lastCommit.Message()}) //commits = append(commits, []string{lastCommit.Id().String(), lastCommit.Message()})
if err = CommitRepoAction(userId, userName, actEmail, if err = CommitRepoAction(userId, ru.Id, userName, actEmail,
repos.Id, repoName, refName, &base.PushCommits{l.Len(), commits}); err != nil { repos.Id, repoUserName, repoName, refName, &base.PushCommits{l.Len(), commits}); err != nil {
qlog.Fatalf("runUpdate.models.CommitRepoAction: %v", err) qlog.Fatalf("runUpdate.models.CommitRepoAction: %v", err)
} }
} }

View File

@ -60,8 +60,8 @@ func Http(ctx *middleware.Context, params martini.Params) {
// only public pull don't need auth // only public pull don't need auth
isPublicPull := !repo.IsPrivate && isPull isPublicPull := !repo.IsPrivate && isPull
var askAuth = !isPublicPull || base.Service.RequireSignInView var askAuth = !isPublicPull || base.Service.RequireSignInView
var authUser *models.User var authUser *models.User
var authUsername, passwd string
// check access // check access
if askAuth { if askAuth {
@ -79,7 +79,7 @@ func Http(ctx *middleware.Context, params martini.Params) {
ctx.Handle(401, "no basic auth and digit auth", nil) ctx.Handle(401, "no basic auth and digit auth", nil)
return return
} }
authUsername, passwd, err := basicDecode(auths[1]) authUsername, passwd, err = basicDecode(auths[1])
if err != nil { if err != nil {
ctx.Handle(401, "no basic auth and digit auth", nil) ctx.Handle(401, "no basic auth and digit auth", nil)
return return
@ -133,7 +133,7 @@ func Http(ctx *middleware.Context, params martini.Params) {
newCommitId := fields[1] newCommitId := fields[1]
refName := fields[2] refName := fields[2]
models.Update(refName, oldCommitId, newCommitId, username, reponame, authUser.Id) models.Update(refName, oldCommitId, newCommitId, authUsername, username, reponame, authUser.Id)
} }
} }
} }