|
|
@ -49,7 +49,7 @@ func init() {
|
|
|
|
level := "0"
|
|
|
|
level := "0"
|
|
|
|
os.MkdirAll("log", os.ModePerm)
|
|
|
|
os.MkdirAll("log", os.ModePerm)
|
|
|
|
log.NewLogger(10000, "file", fmt.Sprintf(`{"level":%s,"filename":"%s"}`, level, "log/serv.log"))
|
|
|
|
log.NewLogger(10000, "file", fmt.Sprintf(`{"level":%s,"filename":"%s"}`, level, "log/serv.log"))
|
|
|
|
log.Info("start logging...")
|
|
|
|
log.Trace("start logging...")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func parseCmd(cmd string) (string, string) {
|
|
|
|
func parseCmd(cmd string) (string, string) {
|
|
|
@ -73,6 +73,8 @@ func In(b string, sl map[string]int) bool {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func runServ(k *cli.Context) {
|
|
|
|
func runServ(k *cli.Context) {
|
|
|
|
|
|
|
|
log.Trace("new serv request")
|
|
|
|
|
|
|
|
|
|
|
|
base.NewConfigContext()
|
|
|
|
base.NewConfigContext()
|
|
|
|
models.LoadModelsConfig()
|
|
|
|
models.LoadModelsConfig()
|
|
|
|
models.NewEngine()
|
|
|
|
models.NewEngine()
|
|
|
@ -80,17 +82,20 @@ func runServ(k *cli.Context) {
|
|
|
|
keys := strings.Split(os.Args[2], "-")
|
|
|
|
keys := strings.Split(os.Args[2], "-")
|
|
|
|
if len(keys) != 2 {
|
|
|
|
if len(keys) != 2 {
|
|
|
|
fmt.Println("auth file format error")
|
|
|
|
fmt.Println("auth file format error")
|
|
|
|
|
|
|
|
log.Error("auth file format error")
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
keyId, err := strconv.ParseInt(keys[1], 10, 64)
|
|
|
|
keyId, err := strconv.ParseInt(keys[1], 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("auth file format error")
|
|
|
|
fmt.Println("auth file format error")
|
|
|
|
|
|
|
|
log.Error("auth file format error")
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
user, err := models.GetUserByKeyId(keyId)
|
|
|
|
user, err := models.GetUserByKeyId(keyId)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("You have no right to access")
|
|
|
|
fmt.Println("You have no right to access")
|
|
|
|
|
|
|
|
log.Error("You have no right to access")
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -105,6 +110,7 @@ func runServ(k *cli.Context) {
|
|
|
|
rr := strings.SplitN(rRepo, "/", 2)
|
|
|
|
rr := strings.SplitN(rRepo, "/", 2)
|
|
|
|
if len(rr) != 2 {
|
|
|
|
if len(rr) != 2 {
|
|
|
|
println("Unavilable repository", args)
|
|
|
|
println("Unavilable repository", args)
|
|
|
|
|
|
|
|
log.Error("Unavilable repository %v", args)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
repoName := rr[1]
|
|
|
|
repoName := rr[1]
|
|
|
@ -122,11 +128,12 @@ func runServ(k *cli.Context) {
|
|
|
|
isExist = false
|
|
|
|
isExist = false
|
|
|
|
if isRead {
|
|
|
|
if isRead {
|
|
|
|
println("Repository", user.Name+"/"+repoName, "is not exist")
|
|
|
|
println("Repository", user.Name+"/"+repoName, "is not exist")
|
|
|
|
|
|
|
|
log.Error("Repository " + user.Name + "/" + repoName + " is not exist")
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
println("Get repository error:", err)
|
|
|
|
println("Get repository error:", err)
|
|
|
|
log.Error(err.Error())
|
|
|
|
log.Error("Get repository error: " + err.Error())
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -142,6 +149,7 @@ func runServ(k *cli.Context) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !has {
|
|
|
|
if !has {
|
|
|
|
println("You have no right to write this repository")
|
|
|
|
println("You have no right to write this repository")
|
|
|
|
|
|
|
|
log.Error("You have no right to access this repository")
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case isRead:
|
|
|
|
case isRead:
|
|
|
@ -161,10 +169,12 @@ func runServ(k *cli.Context) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !has {
|
|
|
|
if !has {
|
|
|
|
println("You have no right to access this repository")
|
|
|
|
println("You have no right to access this repository")
|
|
|
|
|
|
|
|
log.Error("You have no right to access this repository")
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
println("Unknown command")
|
|
|
|
println("Unknown command")
|
|
|
|
|
|
|
|
log.Error("Unknown command")
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -175,23 +185,23 @@ func runServ(k *cli.Context) {
|
|
|
|
_, err = models.CreateRepository(user, repoName, "", "", "", false, true)
|
|
|
|
_, err = models.CreateRepository(user, repoName, "", "", "", false, true)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
println("Create repository failed")
|
|
|
|
println("Create repository failed")
|
|
|
|
log.Error(err.Error())
|
|
|
|
log.Error("Create repository failed: " + err.Error())
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
rep, err = git.OpenRepository(repoPath)
|
|
|
|
rep, err = git.OpenRepository(repoPath)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
println("OpenRepository failed:", err.Error())
|
|
|
|
println("OpenRepository failed:", err.Error())
|
|
|
|
log.Error(err.Error())
|
|
|
|
log.Error("OpenRepository failed: " + err.Error())
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
refs, err := rep.AllReferencesMap()
|
|
|
|
refs, err := rep.AllReferencesMap()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
println("Get All References failed:", err.Error())
|
|
|
|
println("Get All References failed:", err.Error())
|
|
|
|
log.Error(err.Error())
|
|
|
|
log.Error("Get All References failed: " + err.Error())
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -208,7 +218,7 @@ 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())
|
|
|
|
log.Error(err.Error())
|
|
|
|
log.Error("execute command error: " + err.Error())
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -236,6 +246,7 @@ func runServ(k *cli.Context) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if refname == "" {
|
|
|
|
if refname == "" {
|
|
|
|
println("No find any reference name:", b.String())
|
|
|
|
println("No find any reference name:", b.String())
|
|
|
|
|
|
|
|
log.Error("No find any reference name: " + b.String())
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -248,17 +259,18 @@ func runServ(k *cli.Context) {
|
|
|
|
refs, err = rep.AllReferencesMap()
|
|
|
|
refs, err = rep.AllReferencesMap()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
println("Get All References failed:", err.Error())
|
|
|
|
println("Get All References failed:", err.Error())
|
|
|
|
log.Error(err.Error())
|
|
|
|
log.Error("Get All References failed: " + err.Error())
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ref, ok = refs[refname]; !ok {
|
|
|
|
if ref, ok = refs[refname]; !ok {
|
|
|
|
|
|
|
|
log.Error("unknow reference name -", refname, "-", b.String())
|
|
|
|
log.Error("unknow reference name -", refname, "-", b.String())
|
|
|
|
log.Error("unknow reference name -", refname, "-", b.String())
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
l, err = ref.AllCommits()
|
|
|
|
l, err = ref.AllCommits()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
println("Get All Commits failed:", err.Error())
|
|
|
|
println("Get All Commits failed:", err.Error())
|
|
|
|
log.Error(err.Error())
|
|
|
|
log.Error("Get All Commits failed: " + err.Error())
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -268,14 +280,14 @@ func runServ(k *cli.Context) {
|
|
|
|
last, err = ref.LastCommit()
|
|
|
|
last, err = ref.LastCommit()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
println("Get last commit failed:", err.Error())
|
|
|
|
println("Get last commit failed:", err.Error())
|
|
|
|
log.Error(err.Error())
|
|
|
|
log.Error("Get last commit failed: " + err.Error())
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ref2, err := rep.LookupReference(ref.Name)
|
|
|
|
ref2, err := rep.LookupReference(ref.Name)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
println("look up reference failed:", err.Error())
|
|
|
|
println("look up reference failed:", err.Error())
|
|
|
|
log.Error(err.Error())
|
|
|
|
log.Error("look up reference failed: " + err.Error())
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -283,7 +295,7 @@ func runServ(k *cli.Context) {
|
|
|
|
before, err := ref2.LastCommit()
|
|
|
|
before, err := ref2.LastCommit()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
println("Get last commit failed:", err.Error())
|
|
|
|
println("Get last commit failed:", err.Error())
|
|
|
|
log.Error(err.Error())
|
|
|
|
log.Error("Get last commit failed: " + err.Error())
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//log.Info("----", before.Id(), "-----", last.Id())
|
|
|
|
//log.Info("----", before.Id(), "-----", last.Id())
|
|
|
|