cmd/gitmirror: improve names
mirror -> gitMirror, pollGerritAndTickle -> pollGerritAndTickleLoop.
Change-Id: I419c1c3bfceb3b14dc94ca332e57010fc32039fd
Reviewed-on: https://go-review.googlesource.com/c/build/+/325769
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Carlos Amedee <carlos@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
diff --git a/cmd/gitmirror/gitmirror.go b/cmd/gitmirror/gitmirror.go
index d504e7f..9545ff2 100644
--- a/cmd/gitmirror/gitmirror.go
+++ b/cmd/gitmirror/gitmirror.go
@@ -76,7 +76,7 @@
}
defer os.RemoveAll(credsDir)
- m := &mirror{
+ m := &gitMirror{
mux: http.DefaultServeMux,
repos: map[string]*repo{},
cacheDir: cacheDir,
@@ -108,7 +108,7 @@
for _, repo := range m.repos {
go repo.loop()
}
- go m.pollGerritAndTickle()
+ go m.pollGerritAndTickleLoop()
go m.subscribeToMaintnerAndTickleLoop()
shutdown := make(chan os.Signal, 1)
@@ -203,9 +203,9 @@
return *flagCacheDir, nil
}
-// A mirror watches Gerrit repositories, fetching the latest commits and
+// A gitMirror watches Gerrit repositories, fetching the latest commits and
// optionally mirroring them.
-type mirror struct {
+type gitMirror struct {
mux *http.ServeMux
repos map[string]*repo
cacheDir string
@@ -215,7 +215,7 @@
mirrorGitHub, mirrorCSR bool
}
-func (m *mirror) addRepo(meta *repospkg.Repo) *repo {
+func (m *gitMirror) addRepo(meta *repospkg.Repo) *repo {
name := meta.GoGerritProject
r := &repo{
name: name,
@@ -232,7 +232,7 @@
}
// addMirrors sets up mirroring for repositories that need it.
-func (m *mirror) addMirrors() error {
+func (m *gitMirror) addMirrors() error {
for _, repo := range m.repos {
if m.mirrorGitHub && repo.meta.MirrorToGitHub {
if err := repo.addRemote("github", "git@github.com:"+repo.meta.GitHubRepo+".git"); err != nil {
@@ -251,7 +251,7 @@
// GET /
// or:
// GET /debug/watcher/
-func (m *mirror) handleRoot(w http.ResponseWriter, r *http.Request) {
+func (m *gitMirror) handleRoot(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" && r.URL.Path != "/debug/watcher/" {
http.NotFound(w, r)
return
@@ -319,7 +319,7 @@
changed chan bool // sent to when a change comes in
status statusRing
dests []string // destination remotes to mirror to
- mirror *mirror
+ mirror *gitMirror
mu sync.Mutex
err error
@@ -599,7 +599,7 @@
return err
}
-func (m *mirror) notifyChanged(name string) {
+func (m *gitMirror) notifyChanged(name string) {
repo, ok := m.repos[name]
if !ok {
return
@@ -610,11 +610,11 @@
}
}
-// pollGerritAndTickle polls Gerrit's JSON meta URL of all its URLs
+// pollGerritAndTickleLoop polls Gerrit's JSON meta URL of all its URLs
// and their current branch heads. When this sees that one has
// changed, it tickles the channel for that repo and wakes up its
// poller, if its poller is in a sleep.
-func (m *mirror) pollGerritAndTickle() {
+func (m *gitMirror) pollGerritAndTickleLoop() {
last := map[string]string{} // repo -> last seen hash
for {
gerritRepos, err := m.gerritMetaMap()
@@ -634,7 +634,7 @@
// subscribeToMaintnerAndTickleLoop subscribes to maintner.golang.org
// and watches for any ref changes in realtime.
-func (m *mirror) subscribeToMaintnerAndTickleLoop() {
+func (m *gitMirror) subscribeToMaintnerAndTickleLoop() {
for {
if err := m.subscribeToMaintnerAndTickle(); err != nil {
log.Printf("maintner loop: %v; retrying in 30 seconds", err)
@@ -643,7 +643,7 @@
}
}
-func (m *mirror) subscribeToMaintnerAndTickle() error {
+func (m *gitMirror) subscribeToMaintnerAndTickle() error {
ctx := context.Background()
retryTicker := time.NewTicker(10 * time.Second)
defer retryTicker.Stop() // we never return, though
@@ -670,7 +670,7 @@
// gerritMetaMap returns the map from repo name (e.g. "go") to its
// latest master hash.
-func (m *mirror) gerritMetaMap() (map[string]string, error) {
+func (m *gitMirror) gerritMetaMap() (map[string]string, error) {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
meta, err := m.gerritClient.GetProjects(ctx, "master")
diff --git a/cmd/gitmirror/gitmirror_test.go b/cmd/gitmirror/gitmirror_test.go
index 4a0f567..2898a4f 100644
--- a/cmd/gitmirror/gitmirror_test.go
+++ b/cmd/gitmirror/gitmirror_test.go
@@ -81,7 +81,7 @@
type testMirror struct {
gerrit, github, csr string
- m *mirror
+ m *gitMirror
server *httptest.Server
buildRepo *repo
t *testing.T
@@ -100,7 +100,7 @@
gerrit: t.TempDir(),
github: t.TempDir(),
csr: t.TempDir(),
- m: &mirror{
+ m: &gitMirror{
mux: http.NewServeMux(),
cacheDir: t.TempDir(),
homeDir: t.TempDir(),