tokarchuk/v1.17
Lunny Xiao 11 years ago
parent 6ef3e8b3c9
commit d24a4a142e
  1. 55
      serve.go

@ -109,20 +109,25 @@ func runServ(k *cli.Context) {
repoName = repoName[:len(repoName)-4] repoName = repoName[:len(repoName)-4]
} }
isWrite := In(verb, COMMANDS_WRITE)
isRead := In(verb, COMMANDS_READONLY)
repo, err := models.GetRepositoryByName(user.Id, repoName) repo, err := models.GetRepositoryByName(user.Id, repoName)
var isExist bool = true var isExist bool = true
if err != nil { if err != nil {
if err == models.ErrRepoNotExist { if err == models.ErrRepoNotExist {
isExist = false isExist = false
if isRead {
println("Repository", user.Name+"/"+repoName, "is not exist")
return
}
} else { } else {
println("Unavilable repository", err) println("Get repository error:", err)
return return
} }
} }
isWrite := In(verb, COMMANDS_WRITE) // access check
isRead := In(verb, COMMANDS_READONLY)
switch { switch {
case isWrite: case isWrite:
has, err := models.HasAccess(user.Name, repoName, models.AU_WRITABLE) has, err := models.HasAccess(user.Name, repoName, models.AU_WRITABLE)
@ -156,12 +161,11 @@ func runServ(k *cli.Context) {
return return
} }
var rep *git.Repository
repoPath := models.RepoPath(user.Name, repoName)
if !isExist { if !isExist {
if isRead { if isWrite {
println("Repository", user.Name+"/"+repoName, "is not exist") _, err = models.CreateRepository(user, repoName, "", "", "", false, true)
return
} else if isWrite {
_, err := models.CreateRepository(user, repoName, "", "", "", false, true)
if err != nil { if err != nil {
println("Create repository failed") println("Create repository failed")
return return
@ -169,11 +173,11 @@ func runServ(k *cli.Context) {
} }
} }
rep, err := git.OpenRepository(models.RepoPath(user.Name, repoName)) rep, err = git.OpenRepository(repoPath)
if err != nil { if err != nil {
println(err.Error()) println(err.Error())
return return
} }
refs, err := rep.AllReferencesMap() refs, err := rep.AllReferencesMap()
if err != nil { if err != nil {
@ -194,17 +198,14 @@ func runServ(k *cli.Context) {
if err = gitcmd.Run(); err != nil { if err = gitcmd.Run(); err != nil {
println("execute command error:", err.Error()) println("execute command error:", err.Error())
return
} }
if !strings.HasPrefix(cmd, "git-receive-pack") { if isRead {
return return
} }
// update // find push reference name
//w, _ := os.Create("serve.log")
//defer w.Close()
//log.SetOutput(w)
var t = "ok refs/heads/" var t = "ok refs/heads/"
var i int var i int
var refname string var refname string
@ -220,12 +221,17 @@ func runServ(k *cli.Context) {
refname = l[idx+len(t):] refname = l[idx+len(t):]
} }
} }
if refname == "" {
println("No find any reference name:", b.String())
return
}
var ref *git.Reference var ref *git.Reference
var ok bool var ok bool
var l *list.List var l *list.List
//log.Info("----", refname, "-----") //log.Info("----", refname, "-----")
if ref, ok = refs[refname]; !ok { if ref, ok = refs[refname]; !ok {
// for new branch
refs, err = rep.AllReferencesMap() refs, err = rep.AllReferencesMap()
if err != nil { if err != nil {
println(err.Error()) println(err.Error())
@ -280,13 +286,8 @@ func runServ(k *cli.Context) {
repo.Id, repoName, refname, &base.PushCommits{l.Len(), commits}); err != nil { repo.Id, repoName, refname, &base.PushCommits{l.Len(), commits}); err != nil {
log.Error("runUpdate.models.CommitRepoAction: %v", err, commits) log.Error("runUpdate.models.CommitRepoAction: %v", err, commits)
} else { } else {
//log.Info("refname", refname)
//log.Info("Listen: %v", cmd)
//fmt.Println("...", cmd)
//runUpdate(k)
c := exec.Command("git", "update-server-info") c := exec.Command("git", "update-server-info")
c.Dir = models.RepoPath(user.Name, repoName) c.Dir = repoPath
err := c.Run() err := c.Run()
if err != nil { if err != nil {
log.Error("update-server-info: %v", err) log.Error("update-server-info: %v", err)

Loading…
Cancel
Save