Skip to content

Commit af821b3

Browse files
author
Asim
committed
use mixedCaps rather than underscores for function names
1 parent 3e58fe3 commit af821b3

File tree

1 file changed

+65
-65
lines changed

1 file changed

+65
-65
lines changed

git-http-backend.go

Lines changed: 65 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,22 @@ var config Config = Config{
4444
}
4545

4646
var services = map[string] Service {
47-
"(.*?)/git-upload-pack$": Service{"POST", service_rpc, "upload-pack"},
48-
"(.*?)/git-receive-pack$": Service{"POST", service_rpc, "receive-pack"},
49-
"(.*?)/info/refs$": Service{"GET", get_info_refs, ""},
50-
"(.*?)/HEAD$": Service{"GET", get_text_file, ""},
51-
"(.*?)/objects/info/alternates$": Service{"GET", get_text_file, ""},
52-
"(.*?)/objects/info/http-alternates$": Service{"GET", get_text_file, ""},
53-
"(.*?)/objects/info/packs$": Service{"GET", get_info_packs, ""},
54-
"(.*?)/objects/info/[^/]*$": Service{"GET", get_text_file, ""},
55-
"(.*?)/objects/[0-9a-f]{2}/[0-9a-f]{38}$": Service{"GET", get_loose_object, ""},
56-
"(.*?)/objects/pack/pack-[0-9a-f]{40}\\.pack$": Service{"GET", get_pack_file, ""},
57-
"(.*?)/objects/pack/pack-[0-9a-f]{40}\\.idx$": Service{"GET", get_idx_file, ""},
47+
"(.*?)/git-upload-pack$": Service{"POST", serviceRpc, "upload-pack"},
48+
"(.*?)/git-receive-pack$": Service{"POST", serviceRpc, "receive-pack"},
49+
"(.*?)/info/refs$": Service{"GET", getInfoRefs, ""},
50+
"(.*?)/HEAD$": Service{"GET", getTextFile, ""},
51+
"(.*?)/objects/info/alternates$": Service{"GET", getTextFile, ""},
52+
"(.*?)/objects/info/http-alternates$": Service{"GET", getTextFile, ""},
53+
"(.*?)/objects/info/packs$": Service{"GET", getInfoPacks, ""},
54+
"(.*?)/objects/info/[^/]*$": Service{"GET", getTextFile, ""},
55+
"(.*?)/objects/[0-9a-f]{2}/[0-9a-f]{38}$": Service{"GET", getLooseObject, ""},
56+
"(.*?)/objects/pack/pack-[0-9a-f]{40}\\.pack$": Service{"GET", getPackFile, ""},
57+
"(.*?)/objects/pack/pack-[0-9a-f]{40}\\.idx$": Service{"GET", getIdxFile, ""},
5858
}
5959

6060
// Request handling function
6161

62-
func request_handler() http.HandlerFunc {
62+
func requestHandler() http.HandlerFunc {
6363
return func(w http.ResponseWriter, r *http.Request) {
6464
log.Printf("%s %s %s %s", r.RemoteAddr, r.Method, r.URL.Path, r.Proto)
6565
for match, service := range services {
@@ -70,17 +70,17 @@ func request_handler() http.HandlerFunc {
7070

7171
if m := re.FindStringSubmatch(r.URL.Path); m != nil {
7272
if service.Method != r.Method {
73-
render_method_not_allowed(w, r)
73+
renderMethodNotAllowed(w, r)
7474
return
7575
}
7676

7777
rpc := service.Rpc
7878
file := strings.Replace(r.URL.Path, m[1] + "/", "", 1)
79-
dir, err := get_git_dir(m[1])
79+
dir, err := getGitDir(m[1])
8080

8181
if err != nil {
8282
log.Print(err)
83-
render_not_found(w)
83+
renderNotFound(w)
8484
return
8585
}
8686

@@ -89,19 +89,19 @@ func request_handler() http.HandlerFunc {
8989
return
9090
}
9191
}
92-
render_not_found(w)
92+
renderNotFound(w)
9393
return
9494
}
9595
}
9696

9797
// Actual command handling functions
9898

99-
func service_rpc(hr HandlerReq) {
99+
func serviceRpc(hr HandlerReq) {
100100
w, r, rpc, dir := hr.w, hr.r, hr.Rpc, hr.Dir
101-
access := has_access(r, dir, rpc, true)
101+
access := hasAccess(r, dir, rpc, true)
102102

103103
if access == false {
104-
render_no_access(w)
104+
renderNoAccess(w)
105105
return
106106
}
107107

@@ -133,62 +133,62 @@ func service_rpc(hr HandlerReq) {
133133
cmd.Wait()
134134
}
135135

136-
func get_info_refs(hr HandlerReq) {
136+
func getInfoRefs(hr HandlerReq) {
137137
w, r, dir := hr.w, hr.r, hr.Dir
138-
service_name := get_service_type(r)
139-
access := has_access(r, dir, service_name, false)
138+
service_name := getServiceType(r)
139+
access := hasAccess(r, dir, service_name, false)
140140

141141
if access {
142142
args := []string{service_name, "--stateless-rpc", "--advertise-refs", "."}
143-
refs := git_command(dir, args...)
143+
refs := gitCommand(dir, args...)
144144

145-
hdr_nocache(w)
145+
hdrNocache(w)
146146
w.Header().Set("Content-Type", fmt.Sprintf("application/x-git-%s-advertisement", service_name))
147147
w.WriteHeader(http.StatusOK)
148-
w.Write(packet_write("# service=git-" + service_name + "\n"))
149-
w.Write(packet_flush())
148+
w.Write(packetWrite("# service=git-" + service_name + "\n"))
149+
w.Write(packetFlush())
150150
w.Write(refs)
151151
} else {
152-
update_server_info(dir)
153-
hdr_nocache(w)
154-
send_file("text/plain; charset=utf-8", hr)
152+
updateServerInfo(dir)
153+
hdrNocache(w)
154+
sendFile("text/plain; charset=utf-8", hr)
155155
}
156156
}
157157

158-
func get_info_packs(hr HandlerReq) {
159-
hdr_cache_forever(hr.w)
160-
send_file("text/plain; charset=utf-8", hr)
158+
func getInfoPacks(hr HandlerReq) {
159+
hdrCacheForever(hr.w)
160+
sendFile("text/plain; charset=utf-8", hr)
161161
}
162162

163-
func get_loose_object(hr HandlerReq) {
164-
hdr_cache_forever(hr.w)
165-
send_file("application/x-git-loose-object", hr)
163+
func getLooseObject(hr HandlerReq) {
164+
hdrCacheForever(hr.w)
165+
sendFile("application/x-git-loose-object", hr)
166166
}
167167

168-
func get_pack_file(hr HandlerReq) {
169-
hdr_cache_forever(hr.w)
170-
send_file("application/x-git-packed-objects", hr)
168+
func getPackFile(hr HandlerReq) {
169+
hdrCacheForever(hr.w)
170+
sendFile("application/x-git-packed-objects", hr)
171171
}
172172

173-
func get_idx_file(hr HandlerReq) {
174-
hdr_cache_forever(hr.w)
175-
send_file("application/x-git-packed-objects-toc", hr)
173+
func getIdxFile(hr HandlerReq) {
174+
hdrCacheForever(hr.w)
175+
sendFile("application/x-git-packed-objects-toc", hr)
176176
}
177177

178-
func get_text_file(hr HandlerReq) {
179-
hdr_nocache(hr.w)
180-
send_file("text/plain", hr)
178+
func getTextFile(hr HandlerReq) {
179+
hdrNocache(hr.w)
180+
sendFile("text/plain", hr)
181181
}
182182

183183
// Logic helping functions
184184

185-
func send_file(content_type string, hr HandlerReq) {
185+
func sendFile(content_type string, hr HandlerReq) {
186186
w, r := hr.w, hr.r
187187
req_file := path.Join(hr.Dir, hr.File)
188188

189189
f, err := os.Stat(req_file)
190190
if os.IsNotExist(err) {
191-
render_not_found(w)
191+
renderNotFound(w)
192192
return
193193
}
194194

@@ -199,7 +199,7 @@ func send_file(content_type string, hr HandlerReq) {
199199
}
200200

201201

202-
func get_git_dir(file_path string) (string, error) {
202+
func getGitDir(file_path string) (string, error) {
203203
root := config.ProjectRoot
204204

205205
if root == "" {
@@ -221,7 +221,7 @@ func get_git_dir(file_path string) (string, error) {
221221
return f, nil
222222
}
223223

224-
func get_service_type(r *http.Request) string {
224+
func getServiceType(r *http.Request) string {
225225
service_type := r.FormValue("service")
226226

227227
if s := strings.HasPrefix(service_type, "git-"); !s {
@@ -231,7 +231,7 @@ func get_service_type(r *http.Request) string {
231231
return strings.Replace(service_type, "git-", "", 1)
232232
}
233233

234-
func has_access(r *http.Request, dir string, rpc string, check_content_type bool) bool {
234+
func hasAccess(r *http.Request, dir string, rpc string, check_content_type bool) bool {
235235
if check_content_type {
236236
if r.Header.Get("Content-Type") != fmt.Sprintf("application/x-git-%s-request", rpc) {
237237
return false
@@ -248,12 +248,12 @@ func has_access(r *http.Request, dir string, rpc string, check_content_type bool
248248
return config.UploadPack
249249
}
250250

251-
return get_config_setting(rpc, dir)
251+
return getConfigSetting(rpc, dir)
252252
}
253253

254-
func get_config_setting(service_name string, dir string) bool {
254+
func getConfigSetting(service_name string, dir string) bool {
255255
service_name = strings.Replace(service_name, "-", "", -1)
256-
setting := get_git_config("http." + service_name, dir)
256+
setting := getGitConfig("http." + service_name, dir)
257257

258258
if service_name == "uploadpack" {
259259
return setting != "false"
@@ -262,18 +262,18 @@ func get_config_setting(service_name string, dir string) bool {
262262
return setting == "true"
263263
}
264264

265-
func get_git_config(config_name string, dir string) string {
265+
func getGitConfig(config_name string, dir string) string {
266266
args := []string{"config", config_name}
267-
out := string(git_command(dir, args...))
267+
out := string(gitCommand(dir, args...))
268268
return out[0:len(out)-1]
269269
}
270270

271-
func update_server_info(dir string) []byte {
271+
func updateServerInfo(dir string) []byte {
272272
args := []string{"update-server-info"}
273-
return git_command(dir, args...)
273+
return gitCommand(dir, args...)
274274
}
275275

276-
func git_command(dir string, args ...string) []byte {
276+
func gitCommand(dir string, args ...string) []byte {
277277
command := exec.Command(config.GitBinPath, args...)
278278
command.Dir = dir
279279
out, err := command.Output()
@@ -287,7 +287,7 @@ func git_command(dir string, args ...string) []byte {
287287

288288
// HTTP error response handling functions
289289

290-
func render_method_not_allowed(w http.ResponseWriter, r *http.Request) {
290+
func renderMethodNotAllowed(w http.ResponseWriter, r *http.Request) {
291291
if r.Proto == "HTTP/1.1" {
292292
w.WriteHeader(http.StatusMethodNotAllowed)
293293
w.Write([]byte("Method Not Allowed"))
@@ -297,23 +297,23 @@ func render_method_not_allowed(w http.ResponseWriter, r *http.Request) {
297297
}
298298
}
299299

300-
func render_not_found(w http.ResponseWriter) {
300+
func renderNotFound(w http.ResponseWriter) {
301301
w.WriteHeader(http.StatusNotFound)
302302
w.Write([]byte("Not Found"))
303303
}
304304

305-
func render_no_access(w http.ResponseWriter) {
305+
func renderNoAccess(w http.ResponseWriter) {
306306
w.WriteHeader(http.StatusForbidden)
307307
w.Write([]byte("Forbidden"))
308308
}
309309

310310
// Packet-line handling function
311311

312-
func packet_flush() []byte {
312+
func packetFlush() []byte {
313313
return []byte("0000")
314314
}
315315

316-
func packet_write(str string) []byte {
316+
func packetWrite(str string) []byte {
317317
s := strconv.FormatInt(int64(len(str) + 4), 16)
318318

319319
if len(s) % 4 != 0 {
@@ -325,13 +325,13 @@ func packet_write(str string) []byte {
325325

326326
// Header writing functions
327327

328-
func hdr_nocache(w http.ResponseWriter) {
328+
func hdrNocache(w http.ResponseWriter) {
329329
w.Header().Set("Expires", "Fri, 01 Jan 1980 00:00:00 GMT")
330330
w.Header().Set("Pragma", "no-cache")
331331
w.Header().Set("Cache-Control", "no-cache, max-age=0, must-revalidate")
332332
}
333333

334-
func hdr_cache_forever(w http.ResponseWriter) {
334+
func hdrCacheForever(w http.ResponseWriter) {
335335
now := time.Now().Unix()
336336
expires := now + 31536000
337337
w.Header().Set("Date", fmt.Sprintf("%d", now))
@@ -342,7 +342,7 @@ func hdr_cache_forever(w http.ResponseWriter) {
342342
// Main
343343

344344
func main() {
345-
http.HandleFunc("/", request_handler())
345+
http.HandleFunc("/", requestHandler())
346346

347347
err := http.ListenAndServe(":8080", nil)
348348
if err != nil {

0 commit comments

Comments
 (0)