cmd/serv.go: use a string slice instead of map for keeping env vars

This commit is contained in:
Saeed Rasooli 2018-04-23 16:56:49 +08:00
parent ca10494f4a
commit a24f52b065

View File

@ -151,15 +151,18 @@ func runServ(c *cli.Context) error {
reponame = reponame[:len(reponame)-5] reponame = reponame[:len(reponame)-5]
} }
env := map[string]string{} env := []string{}
addEnv := func(key string, value string) {
env[models.EnvRepoUsername] = username env = append(env, key+"="+value)
if isWiki {
env[models.EnvRepoIsWiki] = "true"
} else {
env[models.EnvRepoIsWiki] = "false"
} }
env[models.EnvRepoName] = reponame
addEnv(models.EnvRepoUsername, username)
if isWiki {
addEnv(models.EnvRepoIsWiki, "true")
} else {
addEnv(models.EnvRepoIsWiki, "false")
}
addEnv(models.EnvRepoName, reponame)
repo, err := models.GetRepositoryByOwnerAndName(username, reponame) repo, err := models.GetRepositoryByOwnerAndName(username, reponame)
if err != nil { if err != nil {
@ -251,8 +254,8 @@ func runServ(c *cli.Context) error {
user.Name, repoPath) user.Name, repoPath)
} }
env[models.EnvPusherName] = user.Name addEnv(models.EnvPusherName, user.Name)
env[models.EnvPusherID] = fmt.Sprintf("%d", user.ID) addEnv(models.EnvPusherID, fmt.Sprintf("%d", user.ID))
} }
} }
@ -312,12 +315,9 @@ func runServ(c *cli.Context) error {
} }
} }
env[models.ProtectedBranchRepoID] = fmt.Sprintf("%d", repo.ID) addEnv(models.ProtectedBranchRepoID, fmt.Sprintf("%d", repo.ID))
for key, value := range env {
gitcmd.Env = append(gitcmd.Env, fmt.Sprintf("%s=%s", key, value))
}
gitcmd.Env = env
gitcmd.Dir = setting.RepoRootPath gitcmd.Dir = setting.RepoRootPath
gitcmd.Stdout = os.Stdout gitcmd.Stdout = os.Stdout
gitcmd.Stdin = os.Stdin gitcmd.Stdin = os.Stdin