| @@ -88,14 +88,29 @@ func (s *Server) smart(w http.ResponseWriter, r *http.Request, owner User, name, |
| 88 | 88 | return |
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | | - dir := s.repoDir(repo) |
| 91 | + var recv, env []string |
| 92 | + limit := int64(0) |
| 93 | + if service == "git-receive-pack" { |
| 94 | + recv = append(receiveArgs(s.root), pushLimit(s.root, repo.Owner.Name, writer)...) |
| 95 | + env = receiveEnv(repo, pusher) |
| 96 | + if over, used, quota := overQuota(s.root, repo.Owner.Name); quota > 0 && !over { |
| 97 | + limit = quota - used + 1<<20 |
| 98 | + } |
| 99 | + if !writer && (limit == 0 || limit > guestPush+1<<20) { |
| 100 | + limit = guestPush + 1<<20 |
| 101 | + } |
| 102 | + } |
| 103 | + s.gitService(w, r, s.repoDir(repo), service, rest, recv, env, limit) |
| 104 | +} |
| 105 | + |
| 106 | +func (s *Server) gitService(w http.ResponseWriter, r *http.Request, dir, service, rest string, recv, env []string, limit int64) { |
| 92 | 107 | w.Header().Set("Cache-Control", "no-cache") |
| 93 | 108 | ctx, cancel := context.WithTimeout(r.Context(), 10*time.Minute) |
| 94 | 109 | defer cancel() |
| 95 | 110 | if rest == "info/refs" { |
| 96 | 111 | argv := []string{strings.TrimPrefix(service, "git-"), "--stateless-rpc", "--advertise-refs", dir} |
| 97 | 112 | if service == "git-receive-pack" { |
| 98 | | - argv = append(receiveArgs(s.root), argv...) |
| 113 | + argv = append(recv, argv...) |
| 99 | 114 | } |
| 100 | 115 | cmd := exec.CommandContext(ctx, "git", argv...) |
| 101 | 116 | cmd.Env = []string{"HOME=/nonexistent", "PATH=" + os.Getenv("PATH")} |
| @@ -121,19 +136,16 @@ func (s *Server) smart(w http.ResponseWriter, r *http.Request, owner User, name, |
| 121 | 136 | } |
| 122 | 137 | argv := []string{strings.TrimPrefix(service, "git-"), "--stateless-rpc", dir} |
| 123 | 138 | if service == "git-receive-pack" { |
| 124 | | - argv = append(append(receiveArgs(s.root), pushLimit(s.root, repo.Owner.Name, writer)...), argv...) |
| 125 | | - if over, used, quota := overQuota(s.root, repo.Owner.Name); quota > 0 && !over { |
| 126 | | - body = io.LimitReader(body, quota-used+1<<20) |
| 127 | | - } |
| 128 | | - if !writer { |
| 129 | | - body = io.LimitReader(body, guestPush+1<<20) |
| 139 | + argv = append(recv, argv...) |
| 140 | + if limit > 0 { |
| 141 | + body = io.LimitReader(body, limit) |
| 130 | 142 | } |
| 131 | 143 | } |
| 132 | 144 | cmd := exec.CommandContext(ctx, "git", argv...) |
| 133 | 145 | cmd.Stdin = body |
| 134 | 146 | cmd.Env = []string{"GIT_PROTOCOL=" + r.Header.Get("Git-Protocol"), "HOME=/nonexistent", "PATH=" + os.Getenv("PATH")} |
| 135 | 147 | if service == "git-receive-pack" { |
| 136 | | - cmd.Env = append(cmd.Env, receiveEnv(repo, pusher)...) |
| 148 | + cmd.Env = append(cmd.Env, env...) |
| 137 | 149 | } |
| 138 | 150 | stdout, err := cmd.StdoutPipe() |
| 139 | 151 | if err != nil { |