diff --git a/website/camweb.go b/website/camweb.go index aafbb3004..544d25f93 100644 --- a/website/camweb.go +++ b/website/camweb.go @@ -252,14 +252,15 @@ func serveError(w http.ResponseWriter, r *http.Request, relpath string, err erro const gerritURLPrefix = "https://camlistore.googlesource.com/camlistore/+/" -var commitHash = regexp.MustCompile(`^p=camlistore.git;a=commit;h=([0-9a-f]+)$`) +var commitHash = regexp.MustCompile(`^(?i)[0-9a-f]+$`) +var gitwebCommit = regexp.MustCompile(`^p=camlistore.git;a=commit;h=([0-9a-f]+)$`) // empty return value means don't redirect. func redirectPath(u *url.URL) string { - // Example: + // Redirect old gitweb URLs to gerrit. Example: // /code/?p=camlistore.git;a=commit;h=b0d2a8f0e5f27bbfc025a96ec3c7896b42d198ed if strings.HasPrefix(u.Path, "/code/") { - m := commitHash.FindStringSubmatch(u.RawQuery) + m := gitwebCommit.FindStringSubmatch(u.RawQuery) if len(m) == 2 { return gerritURLPrefix + m[1] } @@ -267,11 +268,11 @@ func redirectPath(u *url.URL) string { if strings.HasPrefix(u.Path, "/gw/") { path := strings.TrimPrefix(u.Path, "/gw/") - if strings.HasPrefix(path, "clients") || strings.HasPrefix(path, "server") { - return gerritURLPrefix + "master/" + path + if commitHash.MatchString(path) { + // Assume it's a commit + return gerritURLPrefix + path } - // Assume it's a commit - return gerritURLPrefix + path + return gerritURLPrefix + "master/" + path } if strings.HasPrefix(u.Path, "/docs/") { diff --git a/website/camweb_test.go b/website/camweb_test.go index 7a192eb11..9c19703a6 100644 --- a/website/camweb_test.go +++ b/website/camweb_test.go @@ -28,6 +28,7 @@ func TestRedirect(t *testing.T) { }{ {"/foo", ""}, {"/gw/502aff1fd522c454e39a3723b596aca43d206d4e", "https://camlistore.googlesource.com/camlistore/+/502aff1fd522c454e39a3723b596aca43d206d4e"}, + {"/gw/502AFF", "https://camlistore.googlesource.com/camlistore/+/502AFF"}, {"/gw/server", "https://camlistore.googlesource.com/camlistore/+/master/server"}, {"/code/?p=camlistore.git;a=commit;h=b0d2a8f0e5f27bbfc025a96ec3c7896b42d198ed", "https://camlistore.googlesource.com/camlistore/+/b0d2a8f0e5f27bbfc025a96ec3c7896b42d198ed"}, {"/docs/schema/", "/doc/schema/"},