]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/fix: add rules for net/http -> net/http/httputil renames
authorBrad Fitzpatrick <bradfitz@golang.org>
Mon, 12 Mar 2012 20:25:48 +0000 (13:25 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Mon, 12 Mar 2012 20:25:48 +0000 (13:25 -0700)
And merge the httputil fix into go1rename.

R=golang-dev, r, dsymonds, r, rsc
CC=golang-dev
https://golang.org/cl/5696084

src/cmd/fix/go1rename.go
src/cmd/fix/go1rename_test.go
src/cmd/fix/httputil.go [deleted file]
src/cmd/fix/httputil_test.go [deleted file]

index 4b666720b0e1fa00649da58e2eb00e7cb4e4a69c..9266c749c517767d8c1a9bf4990d9b236cca454d 100644 (file)
@@ -74,4 +74,94 @@ var go1renameReplace = []rename{
                Old:       "runtime.Goroutines",
                New:       "runtime.NumGoroutine",
        },
+       {
+               OldImport: "net/http",
+               NewImport: "net/http/httputil",
+               Old:       "http.ErrPersistEOF",
+               New:       "httputil.ErrPersistEOF",
+       },
+       {
+               OldImport: "net/http",
+               NewImport: "net/http/httputil",
+               Old:       "http.ErrPipeline",
+               New:       "httputil.ErrPipeline",
+       },
+       {
+               OldImport: "net/http",
+               NewImport: "net/http/httputil",
+               Old:       "http.ErrClosed",
+               New:       "httputil.ErrClosed",
+       },
+       {
+               OldImport: "net/http",
+               NewImport: "net/http/httputil",
+               Old:       "http.ServerConn",
+               New:       "httputil.ServerConn",
+       },
+       {
+               OldImport: "net/http",
+               NewImport: "net/http/httputil",
+               Old:       "http.ClientConn",
+               New:       "httputil.ClientConn",
+       },
+       {
+               OldImport: "net/http",
+               NewImport: "net/http/httputil",
+               Old:       "http.NewChunkedReader",
+               New:       "httputil.NewChunkedReader",
+       },
+       {
+               OldImport: "net/http",
+               NewImport: "net/http/httputil",
+               Old:       "http.NewChunkedWriter",
+               New:       "httputil.NewChunkedWriter",
+       },
+       {
+               OldImport: "net/http",
+               NewImport: "net/http/httputil",
+               Old:       "http.ReverseProxy",
+               New:       "httputil.ReverseProxy",
+       },
+       {
+               OldImport: "net/http",
+               NewImport: "net/http/httputil",
+               Old:       "http.NewSingleHostReverseProxy",
+               New:       "httputil.NewSingleHostReverseProxy",
+       },
+       {
+               OldImport: "net/http",
+               NewImport: "net/http/httputil",
+               Old:       "http.DumpRequest",
+               New:       "httputil.DumpRequest",
+       },
+       {
+               OldImport: "net/http",
+               NewImport: "net/http/httputil",
+               Old:       "http.DumpRequestOut",
+               New:       "httputil.DumpRequestOut",
+       },
+       {
+               OldImport: "net/http",
+               NewImport: "net/http/httputil",
+               Old:       "http.DumpResponse",
+               New:       "httputil.DumpResponse",
+       },
+       {
+               OldImport: "net/http",
+               NewImport: "net/http/httputil",
+               Old:       "http.NewClientConn",
+               New:       "httputil.NewClientConn",
+       },
+       {
+               OldImport: "net/http",
+               NewImport: "net/http/httputil",
+               Old:       "http.NewServerConn",
+               New:       "httputil.NewServerConn",
+       },
+       {
+               OldImport: "net/http",
+               NewImport: "net/http/httputil",
+               Old:       "http.NewProxyClientConn",
+               New:       "httputil.NewProxyClientConn",
+       },
 }
index 481ebea8e7bb2fcd4575a751ba7507d985235aba..90219ba710051743607e0ff059c46dc4bb6e440c 100644 (file)
@@ -17,6 +17,7 @@ import (
        "crypto/aes"
        "crypto/des"
        "encoding/json"
+       "net/http"
        "net/url"
        "os"
        "runtime"
@@ -34,6 +35,15 @@ var (
        _ = os.Exec
        _ = runtime.Cgocalls
        _ = runtime.Goroutines
+       _ = http.ErrPersistEOF
+       _ = http.ErrPipeline
+       _ = http.ErrClosed
+       _ = http.NewSingleHostReverseProxy
+       _ = http.NewChunkedReader
+       _ = http.NewChunkedWriter
+       _ *http.ReverseProxy
+       _ *http.ClientConn
+       _ *http.ServerConn
 )
 `,
                Out: `package main
@@ -42,6 +52,7 @@ import (
        "crypto/aes"
        "crypto/cipher"
        "encoding/json"
+       "net/http/httputil"
        "net/url"
        "runtime"
        "syscall"
@@ -59,7 +70,126 @@ var (
        _ = syscall.Exec
        _ = runtime.NumCgoCall
        _ = runtime.NumGoroutine
+       _ = httputil.ErrPersistEOF
+       _ = httputil.ErrPipeline
+       _ = httputil.ErrClosed
+       _ = httputil.NewSingleHostReverseProxy
+       _ = httputil.NewChunkedReader
+       _ = httputil.NewChunkedWriter
+       _ *httputil.ReverseProxy
+       _ *httputil.ClientConn
+       _ *httputil.ServerConn
 )
+`,
+       },
+       {
+               Name: "httputil.0",
+               In: `package main
+
+import "net/http"
+
+func f() {
+       http.DumpRequest(nil, false)
+       http.DumpRequestOut(nil, false)
+       http.DumpResponse(nil, false)
+       http.NewChunkedReader(nil)
+       http.NewChunkedWriter(nil)
+       http.NewClientConn(nil, nil)
+       http.NewProxyClientConn(nil, nil)
+       http.NewServerConn(nil, nil)
+       http.NewSingleHostReverseProxy(nil)
+}
+`,
+               Out: `package main
+
+import "net/http/httputil"
+
+func f() {
+       httputil.DumpRequest(nil, false)
+       httputil.DumpRequestOut(nil, false)
+       httputil.DumpResponse(nil, false)
+       httputil.NewChunkedReader(nil)
+       httputil.NewChunkedWriter(nil)
+       httputil.NewClientConn(nil, nil)
+       httputil.NewProxyClientConn(nil, nil)
+       httputil.NewServerConn(nil, nil)
+       httputil.NewSingleHostReverseProxy(nil)
+}
+`,
+       },
+       {
+               Name: "httputil.1",
+               In: `package main
+
+import "net/http"
+
+func f() {
+       http.DumpRequest(nil, false)
+       http.DumpRequestOut(nil, false)
+       http.DumpResponse(nil, false)
+       http.NewChunkedReader(nil)
+       http.NewChunkedWriter(nil)
+       http.NewClientConn(nil, nil)
+       http.NewProxyClientConn(nil, nil)
+       http.NewServerConn(nil, nil)
+       http.NewSingleHostReverseProxy(nil)
+}
+`,
+               Out: `package main
+
+import "net/http/httputil"
+
+func f() {
+       httputil.DumpRequest(nil, false)
+       httputil.DumpRequestOut(nil, false)
+       httputil.DumpResponse(nil, false)
+       httputil.NewChunkedReader(nil)
+       httputil.NewChunkedWriter(nil)
+       httputil.NewClientConn(nil, nil)
+       httputil.NewProxyClientConn(nil, nil)
+       httputil.NewServerConn(nil, nil)
+       httputil.NewSingleHostReverseProxy(nil)
+}
+`,
+       },
+       {
+               Name: "httputil.2",
+               In: `package main
+
+import "net/http"
+
+func f() {
+       http.DumpRequest(nil, false)
+       http.DumpRequestOut(nil, false)
+       http.DumpResponse(nil, false)
+       http.NewChunkedReader(nil)
+       http.NewChunkedWriter(nil)
+       http.NewClientConn(nil, nil)
+       http.NewProxyClientConn(nil, nil)
+       http.NewServerConn(nil, nil)
+       http.NewSingleHostReverseProxy(nil)
+       http.Get("")
+}
+`,
+               Out: `package main
+
+import (
+       "net/http"
+       "net/http/httputil"
+)
+
+func f() {
+       httputil.DumpRequest(nil, false)
+       httputil.DumpRequestOut(nil, false)
+       httputil.DumpResponse(nil, false)
+       httputil.NewChunkedReader(nil)
+       httputil.NewChunkedWriter(nil)
+       httputil.NewClientConn(nil, nil)
+       httputil.NewProxyClientConn(nil, nil)
+       httputil.NewServerConn(nil, nil)
+       httputil.NewSingleHostReverseProxy(nil)
+       http.Get("")
+}
 `,
        },
 }
diff --git a/src/cmd/fix/httputil.go b/src/cmd/fix/httputil.go
deleted file mode 100644 (file)
index 86c42e1..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-// Copyright 2011 The Go Authors.  All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package main
-
-import "go/ast"
-
-func init() {
-       register(httputilFix)
-}
-
-var httputilFix = fix{
-       "httputil",
-       "2011-11-18",
-       httputil,
-       `Move some functions in http package into httputil package.
-
-http://codereview.appspot.com/5336049
-`,
-}
-
-var httputilFuncs = []string{
-       "DumpRequest",
-       "DumpRequestOut",
-       "DumpResponse",
-       "NewChunkedReader",
-       "NewChunkedWriter",
-       "NewClientConn",
-       "NewProxyClientConn",
-       "NewServerConn",
-       "NewSingleHostReverseProxy",
-}
-
-func httputil(f *ast.File) bool {
-       if imports(f, "net/http/httputil") {
-               return false
-       }
-
-       fixed := false
-
-       walk(f, func(n interface{}) {
-               // Rename package name.
-               if expr, ok := n.(ast.Expr); ok {
-                       for _, s := range httputilFuncs {
-                               if isPkgDot(expr, "http", s) {
-                                       if !fixed {
-                                               addImport(f, "net/http/httputil")
-                                               fixed = true
-                                       }
-                                       expr.(*ast.SelectorExpr).X.(*ast.Ident).Name = "httputil"
-                               }
-                       }
-               }
-       })
-
-       // Remove the net/http import if no longer needed.
-       if fixed && !usesImport(f, "net/http") {
-               deleteImport(f, "net/http")
-       }
-
-       return fixed
-}
diff --git a/src/cmd/fix/httputil_test.go b/src/cmd/fix/httputil_test.go
deleted file mode 100644 (file)
index 83e9f6d..0000000
+++ /dev/null
@@ -1,122 +0,0 @@
-// Copyright 2011 The Go Authors.  All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package main
-
-func init() {
-       addTestCases(httputilTests, httputil)
-}
-
-var httputilTests = []testCase{
-       {
-               Name: "httputil.0",
-               In: `package main
-
-import "net/http"
-
-func f() {
-       http.DumpRequest(nil, false)
-       http.DumpRequestOut(nil, false)
-       http.DumpResponse(nil, false)
-       http.NewChunkedReader(nil)
-       http.NewChunkedWriter(nil)
-       http.NewClientConn(nil, nil)
-       http.NewProxyClientConn(nil, nil)
-       http.NewServerConn(nil, nil)
-       http.NewSingleHostReverseProxy(nil)
-}
-`,
-               Out: `package main
-
-import "net/http/httputil"
-
-func f() {
-       httputil.DumpRequest(nil, false)
-       httputil.DumpRequestOut(nil, false)
-       httputil.DumpResponse(nil, false)
-       httputil.NewChunkedReader(nil)
-       httputil.NewChunkedWriter(nil)
-       httputil.NewClientConn(nil, nil)
-       httputil.NewProxyClientConn(nil, nil)
-       httputil.NewServerConn(nil, nil)
-       httputil.NewSingleHostReverseProxy(nil)
-}
-`,
-       },
-       {
-               Name: "httputil.1",
-               In: `package main
-
-import "net/http"
-
-func f() {
-       http.DumpRequest(nil, false)
-       http.DumpRequestOut(nil, false)
-       http.DumpResponse(nil, false)
-       http.NewChunkedReader(nil)
-       http.NewChunkedWriter(nil)
-       http.NewClientConn(nil, nil)
-       http.NewProxyClientConn(nil, nil)
-       http.NewServerConn(nil, nil)
-       http.NewSingleHostReverseProxy(nil)
-}
-`,
-               Out: `package main
-
-import "net/http/httputil"
-
-func f() {
-       httputil.DumpRequest(nil, false)
-       httputil.DumpRequestOut(nil, false)
-       httputil.DumpResponse(nil, false)
-       httputil.NewChunkedReader(nil)
-       httputil.NewChunkedWriter(nil)
-       httputil.NewClientConn(nil, nil)
-       httputil.NewProxyClientConn(nil, nil)
-       httputil.NewServerConn(nil, nil)
-       httputil.NewSingleHostReverseProxy(nil)
-}
-`,
-       },
-       {
-               Name: "httputil.2",
-               In: `package main
-
-import "net/http"
-
-func f() {
-       http.DumpRequest(nil, false)
-       http.DumpRequestOut(nil, false)
-       http.DumpResponse(nil, false)
-       http.NewChunkedReader(nil)
-       http.NewChunkedWriter(nil)
-       http.NewClientConn(nil, nil)
-       http.NewProxyClientConn(nil, nil)
-       http.NewServerConn(nil, nil)
-       http.NewSingleHostReverseProxy(nil)
-       http.Get("")
-}
-`,
-               Out: `package main
-
-import (
-       "net/http"
-       "net/http/httputil"
-)
-
-func f() {
-       httputil.DumpRequest(nil, false)
-       httputil.DumpRequestOut(nil, false)
-       httputil.DumpResponse(nil, false)
-       httputil.NewChunkedReader(nil)
-       httputil.NewChunkedWriter(nil)
-       httputil.NewClientConn(nil, nil)
-       httputil.NewProxyClientConn(nil, nil)
-       httputil.NewServerConn(nil, nil)
-       httputil.NewSingleHostReverseProxy(nil)
-       http.Get("")
-}
-`,
-       },
-}