From 4d81e11d78ab0ca147f1f4ea3d67561dcb0c39f8 Mon Sep 17 00:00:00 2001 From: Shenghou Ma Date: Tue, 9 Dec 2014 21:25:00 -0500 Subject: [PATCH] godoc/redirect: update the rules for /cl/ redirect If id is a number greater than 150k, then it is a Rietveld CL, otherwise treat it as a Gerrit change id. Also add support for /cl/ID/, because go commit 0edafefc36 uses this form. Change-Id: I46575e3284faaa727e346b34bbc46ab248cf12b3 Signed-off-by: Shenghou Ma Reviewed-on: https://go-review.googlesource.com/1283 Reviewed-by: Andrew Gerrand --- godoc/redirect/redirect.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/godoc/redirect/redirect.go b/godoc/redirect/redirect.go index 4044598a..b7498b36 100644 --- a/godoc/redirect/redirect.go +++ b/godoc/redirect/redirect.go @@ -177,17 +177,19 @@ func clHandler(w http.ResponseWriter, r *http.Request) { return } id := r.URL.Path[len(prefix):] + // support /cl/152700045/, which is used in commit 0edafefc36. + id = strings.TrimSuffix(id, "/") if !validId.MatchString(id) { http.Error(w, "Not found", http.StatusNotFound) return } target := "" - // the first CL in rietveld is about 152046, so if id is less than - // 150000, treat it as a Gerrit change id. - if n, _ := strconv.Atoi(id); strings.HasPrefix(id, "I") || n < 150000 { - target = "https://go-review.googlesource.com/#/q/" + id - } else { + // the first CL in rietveld is about 152046, so only treat the id as + // a rietveld CL if it is larger than 150000. + if n, err := strconv.Atoi(id); err == nil && n > 150000 { target = "https://codereview.appspot.com/" + id + } else { + target = "https://go-review.googlesource.com/r/" + id } http.Redirect(w, r, target, http.StatusFound) }