aboutsummaryrefslogtreecommitdiff
path: root/cmd/receivepack9418/main.go
blob: 6884f32654d502d0d824e8522b827234521cd00b (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Command receivepack9418 serves one fixed repository over git:// receive-pack on TCP 9418.
package main

import (
	"flag"
	"log"
	"os"
)

func main() {
	os.Exit(runMain())
}

func runMain() int {
	listenAddr := flag.String("listen", ":9418", "listen address")
	repoPath := flag.String("repo", "", "path to git dir (.git or bare repo root)")
	cpuProfilePath := flag.String("cpuprofile", "", "write CPU profile to file")
	memProfilePath := flag.String("memprofile", "", "write heap profile to file at exit")

	flag.Parse()

	if *repoPath == "" {
		log.Print("must provide -repo <path-to-git-dir>")

		return 2
	}

	if *cpuProfilePath != "" {
		stopCPUProfile, err := startCPUProfile(*cpuProfilePath)
		if err != nil {
			log.Printf("cpuprofile: %v", err)

			return 1
		}

		defer func() {
			stopErr := stopCPUProfile()
			if stopErr != nil {
				log.Printf("cpuprofile: %v", stopErr)
			}
		}()
	}

	if *memProfilePath != "" {
		defer func() {
			memErr := writeMemProfile(*memProfilePath)
			if memErr != nil {
				log.Printf("memprofile: %v", memErr)
			}
		}()
	}

	err := run(*listenAddr, *repoPath)
	if err != nil {
		log.Printf("run: %v", err)

		return 1
	}

	return 0
}