]> Cypherpunks repositories - gostls13.git/commitdiff
gofix: make fix order implicit by date.
authorDavid Symonds <dsymonds@golang.org>
Thu, 3 Nov 2011 21:34:37 +0000 (08:34 +1100)
committerDavid Symonds <dsymonds@golang.org>
Thu, 3 Nov 2011 21:34:37 +0000 (08:34 +1100)
This partially undoes 8fd7e6d070c8, but preserves its semantics.
More importantly, it results in the data about each fix being
decentralised, which makes it easier for new fixes to be added,
and other gofix users to slot new fixes in.

It also adds some useful metadata that could be used in the future.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5306092

24 files changed:
src/cmd/gofix/error.go
src/cmd/gofix/filepath.go
src/cmd/gofix/fix.go
src/cmd/gofix/httpfinalurl.go
src/cmd/gofix/httpfs.go
src/cmd/gofix/httpheaders.go
src/cmd/gofix/httpserver.go
src/cmd/gofix/imagecolor.go
src/cmd/gofix/imagenew.go
src/cmd/gofix/iocopyn.go
src/cmd/gofix/main.go
src/cmd/gofix/mapdelete.go
src/cmd/gofix/math.go
src/cmd/gofix/netdial.go
src/cmd/gofix/netudpgroup.go
src/cmd/gofix/oserrorstring.go
src/cmd/gofix/osopen.go
src/cmd/gofix/procattr.go
src/cmd/gofix/reflect.go
src/cmd/gofix/signal.go
src/cmd/gofix/sorthelpers.go
src/cmd/gofix/sortslice.go
src/cmd/gofix/stringssplit.go
src/cmd/gofix/url.go

index e0ced633d94e0cd4f9e1a387bfa9b0963c495bdb..5e20ff683bf3ae3a1c8a395f31c109b10e5f19b4 100644 (file)
@@ -11,11 +11,12 @@ import (
 )
 
 func init() {
-       fixes = append(fixes, errorFix)
+       register(errorFix)
 }
 
 var errorFix = fix{
        "error",
+       "2011-11-02",
        errorFn,
        `Use error instead of os.Error.
 
index 3edccabfa6757cc5c69dc82f71257e5dba3baee6..f31226018aa46daf33ecab93fcc51dd94f9f65f7 100644 (file)
@@ -8,8 +8,13 @@ import (
        "go/ast"
 )
 
+func init() {
+       register(filepathFix)
+}
+
 var filepathFix = fix{
        "filepath",
+       "2011-06-26",
        filepathFunc,
        `Adapt code from filepath.[List]SeparatorString to string(filepath.[List]Separator).
 
index f7b55b073d4d7e17e608479faa940a646d25fa8e..394685a15abd6f3ae06fcc9f71e31976ccee32ec 100644 (file)
@@ -24,45 +24,29 @@ import (
 
 type fix struct {
        name string
+       date string // date that fix was introduced, in YYYY-MM-DD format
        f    func(*ast.File) bool
        desc string
 }
 
-// main runs sort.Sort(fixes) before printing list of fixes.
-type fixlist []fix
-
-func (f fixlist) Len() int           { return len(f) }
-func (f fixlist) Swap(i, j int)      { f[i], f[j] = f[j], f[i] }
-func (f fixlist) Less(i, j int) bool { return f[i].name < f[j].name }
-
-var fixes = fixlist{
-       // NOTE: This list must be in chronological order,
-       // so that code using APIs that changed multiple times
-       // can be updated in the correct order.
-       // Add new fixes to bottom of list.  Do not sort.
-       httpserverFix,
-       procattrFix,
-       netdialFix,
-       netlookupFix,
-       tlsdialFix,
-       osopenFix,
-       reflectFix,
-       httpFinalURLFix,
-       httpHeadersFix,
-       oserrorstringFix,
-       sortsliceFix,
-       filepathFix,
-       httpFileSystemFix,
-       stringssplitFix,
-       signalFix,
-       sorthelpersFix,
-       urlFix,
-       netudpgroupFix,
-       imagenewFix,
-       mathFix,
-       ioCopyNFix,
-       imagecolorFix,
-       mapdeleteFix,
+// main runs sort.Sort(byName(fixes)) before printing list of fixes.
+type byName []fix
+
+func (f byName) Len() int           { return len(f) }
+func (f byName) Swap(i, j int)      { f[i], f[j] = f[j], f[i] }
+func (f byName) Less(i, j int) bool { return f[i].name < f[j].name }
+
+// main runs sort.Sort(byDate(fixes)) before applying fixes.
+type byDate []fix
+
+func (f byDate) Len() int           { return len(f) }
+func (f byDate) Swap(i, j int)      { f[i], f[j] = f[j], f[i] }
+func (f byDate) Less(i, j int) bool { return f[i].date < f[j].date }
+
+var fixes []fix
+
+func register(f fix) {
+       fixes = append(fixes, f)
 }
 
 // walk traverses the AST x, calling visit(y) for each node y in the tree but
index 6051a2f3f9927b4a7b808e530792e4ce417e9936..49b9f1c516232d804d31818ab93f160de69384f8 100644 (file)
@@ -8,8 +8,13 @@ import (
        "go/ast"
 )
 
+func init() {
+       register(httpFinalURLFix)
+}
+
 var httpFinalURLFix = fix{
        "httpfinalurl",
+       "2011-05-13",
        httpfinalurl,
        `Adapt http Get calls to not have a finalURL result parameter.
 
index 317330619e20c2c770e4cad3d9f1e462a3655c4a..625dd0f7db19097ea244b5019f5139d71ab09063 100644 (file)
@@ -9,8 +9,13 @@ import (
        "go/token"
 )
 
+func init() {
+       register(httpFileSystemFix)
+}
+
 var httpFileSystemFix = fix{
        "httpfs",
+       "2011-06-27",
        httpfs,
        `Adapt http FileServer to take a FileSystem.
 
index e9856f5db494bb008d4d205ffca3f3a14d00814a..0bce12b512a93040afe59314995b8115dc3e158e 100644 (file)
@@ -8,8 +8,13 @@ import (
        "go/ast"
 )
 
+func init() {
+       register(httpHeadersFix)
+}
+
 var httpHeadersFix = fix{
        "httpheaders",
+       "2011-06-16",
        httpheaders,
        `Rename http Referer, UserAgent, Cookie, SetCookie, which are now methods.
 
index cf8d16a978eb45c8d8f74419029a6e74bcdbc997..7aa65178640a8de5bb38502b46e81b8e930deebb 100644 (file)
@@ -9,8 +9,13 @@ import (
        "go/token"
 )
 
+func init() {
+       register(httpserverFix)
+}
+
 var httpserverFix = fix{
        "httpserver",
+       "2011-03-15",
        httpserver,
        `Adapt http server methods and functions to changes
 made to the http ResponseWriter interface.
index c7900e46577d17bfe2b3b59ab499512fd019de5f..1aac40a6fdbb8b33d77fdb406fdefef647a9ce11 100644 (file)
@@ -8,8 +8,13 @@ import (
        "go/ast"
 )
 
+func init() {
+       register(imagecolorFix)
+}
+
 var imagecolorFix = fix{
        "imagecolor",
+       "2011-10-04",
        imagecolor,
        `Adapt code to types moved from image to color.
 
index 07cbef5697df9674b343255636fea36d0b06f7a0..b4e36d4f0c9c104191e4804f3582a30ada40aeb2 100644 (file)
@@ -8,8 +8,13 @@ import (
        "go/ast"
 )
 
+func init() {
+       register(imagenewFix)
+}
+
 var imagenewFix = fix{
        "imagenew",
+       "2011-09-14",
        imagenew,
        `Adapt image.NewXxx calls to pass an image.Rectangle instead of (w, h int).
 
index f911dd740337c9ac5504e8cbc6a419c5f658f24f..720f3c68902bb1668a652b6540ac7ca34fdec9d8 100644 (file)
@@ -8,8 +8,13 @@ import (
        "go/ast"
 )
 
+func init() {
+       register(ioCopyNFix)
+}
+
 var ioCopyNFix = fix{
        "iocopyn",
+       "2011-09-30",
        ioCopyN,
        `Rename io.Copyn to io.CopyN.
 
index 1d0f4b0f0733f38ce11fe4cebf712818e61a604f..fbb705c076312fcc7f7286c8db73a0cfe3f99ad1 100644 (file)
@@ -40,7 +40,7 @@ func usage() {
        fmt.Fprintf(os.Stderr, "usage: gofix [-diff] [-r fixname,...] [-force fixname,...] [path ...]\n")
        flag.PrintDefaults()
        fmt.Fprintf(os.Stderr, "\nAvailable rewrites are:\n")
-       sort.Sort(fixes)
+       sort.Sort(byName(fixes))
        for _, f := range fixes {
                fmt.Fprintf(os.Stderr, "\n%s\n", f.name)
                desc := strings.TrimSpace(f.desc)
@@ -54,6 +54,8 @@ func main() {
        flag.Usage = usage
        flag.Parse()
 
+       sort.Sort(byDate(fixes))
+
        if *allowedRewrites != "" {
                allowed = make(map[string]bool)
                for _, f := range strings.Split(*allowedRewrites, ",") {
index b99602dcc2d5c281a346151c64869b59dc07eac8..db89c7bf45abc5c3b72ecb7297a2a7580c6694bf 100644 (file)
@@ -6,8 +6,13 @@ package main
 
 import "go/ast"
 
+func init() {
+       register(mapdeleteFix)
+}
+
 var mapdeleteFix = fix{
        "mapdelete",
+       "2011-10-18",
        mapdelete,
        `Use delete(m, k) instead of m[k] = 0, false.
 
index a9a11ed615bfc412f2d0b5c4d95557ea87900024..2ec837eb00bfddc40cf1b5356f440e99656471b6 100644 (file)
@@ -6,8 +6,13 @@ package main
 
 import "go/ast"
 
+func init() {
+       register(mathFix)
+}
+
 var mathFix = fix{
        "math",
+       "2011-09-29",
        math,
        `Remove the leading F from math functions such as Fabs.
 
index 6984cdc37238e136b6dcca5aaa5476dc7dee316a..2de994cffe55b404d69484bfc36e2909f2c85f1f 100644 (file)
@@ -8,8 +8,15 @@ import (
        "go/ast"
 )
 
+func init() {
+       register(netdialFix)
+       register(tlsdialFix)
+       register(netlookupFix)
+}
+
 var netdialFix = fix{
        "netdial",
+       "2011-03-28",
        netdial,
        `Adapt 3-argument calls of net.Dial to use 2-argument form.
 
@@ -19,6 +26,7 @@ http://codereview.appspot.com/4244055
 
 var tlsdialFix = fix{
        "tlsdial",
+       "2011-03-28",
        tlsdial,
        `Adapt 4-argument calls of tls.Dial to use 3-argument form.
 
@@ -28,6 +36,7 @@ http://codereview.appspot.com/4244055
 
 var netlookupFix = fix{
        "netlookup",
+       "2011-03-28",
        netlookup,
        `Adapt 3-result calls to net.LookupHost to use 2-result form.
 
index 9bbb2d79199ff18749093824ec0c820fddf56612..12a2efa2878a37823027fbd7ab45e6df401ed8e1 100644 (file)
@@ -8,8 +8,13 @@ import (
        "go/ast"
 )
 
+func init() {
+       register(netudpgroupFix)
+}
+
 var netudpgroupFix = fix{
        "netudpgroup",
+       "2011-08-18",
        netudpgroup,
        `Adapt 1-argument calls of net.(*UDPConn).JoinGroup, LeaveGroup to use 2-argument form.
 
index 416333fc12174f8f5d2ca1bf22af435570331576..a75a2c12d392be8622502e31c11f8720b010cfbf 100644 (file)
@@ -8,8 +8,13 @@ import (
        "go/ast"
 )
 
+func init() {
+       register(oserrorstringFix)
+}
+
 var oserrorstringFix = fix{
        "oserrorstring",
+       "2011-06-22",
        oserrorstring,
        `Replace os.ErrorString() conversions with calls to os.NewError().
 
index 7e7fbbb037b9580478ff4c36277f0e5bc0a38665..af2796ac225cc615d11933ff22ca34d5e5d1a236 100644 (file)
@@ -8,8 +8,13 @@ import (
        "go/ast"
 )
 
+func init() {
+       register(osopenFix)
+}
+
 var osopenFix = fix{
        "osopen",
+       "2011-04-04",
        osopen,
        `Adapt os.Open calls to new, easier API and rename O_CREAT O_CREATE.
 
index 86a8fd10359b8ca6932d956b0f1602f318764bb7..ea375ec9dd9743d891e2aaca23a8023cbdb17c5e 100644 (file)
@@ -9,8 +9,13 @@ import (
        "go/token"
 )
 
+func init() {
+       register(procattrFix)
+}
+
 var procattrFix = fix{
        "procattr",
+       "2011-03-15",
        procattr,
        `Adapt calls to os.StartProcess to use new ProcAttr type.
 
index 2227d69b44986be61966525e9f9006832527bcbc..6670ef2774d9523ec772cfa8ac99dc111036b699 100644 (file)
@@ -15,8 +15,13 @@ import (
        "strings"
 )
 
+func init() {
+       register(reflectFix)
+}
+
 var reflectFix = fix{
        "reflect",
+       "2011-04-08",
        reflectFn,
        `Adapt code to new reflect API.
 
index 9b548bd0892fe711bce5bf338a08f486748b02e0..5a583d41e96fd2fbb78644da96d02c8ef7f13f9a 100644 (file)
@@ -9,8 +9,13 @@ import (
        "strings"
 )
 
+func init() {
+       register(signalFix)
+}
+
 var signalFix = fix{
        "signal",
+       "2011-06-29",
        signal,
        `Adapt code to types moved from os/signal to signal.
 
index 74d0daa3a9f625294bd66b46cd092e0c5c8b863d..fa549313ebddb02448280725587a0106be541254 100644 (file)
@@ -8,8 +8,13 @@ import (
        "go/ast"
 )
 
+func init() {
+       register(sorthelpersFix)
+}
+
 var sorthelpersFix = fix{
        "sorthelpers",
+       "2011-07-08",
        sorthelpers,
        `Adapt code from sort.Sort[Ints|Float64s|Strings] to sort.[Ints|Float64s|Strings].
 `,
index 847f0d57fb5970cf64eb8061660e2bade66ff994..89267b847e3fe68b98885c289171d3ceb51e0dff 100644 (file)
@@ -8,8 +8,13 @@ import (
        "go/ast"
 )
 
+func init() {
+       register(sortsliceFix)
+}
+
 var sortsliceFix = fix{
        "sortslice",
+       "2011-06-26",
        sortslice,
        `Adapt code from sort.[Float64|Int|String]Array to  sort.[Float64|Int|String]Slice.
                
index e3886dd729ea75104d8588c8e18473501c890c90..d89ecf039c345be5a2e612bb273547b37d4c3f2f 100644 (file)
@@ -9,8 +9,13 @@ import (
        "go/token"
 )
 
+func init() {
+       register(stringssplitFix)
+}
+
 var stringssplitFix = fix{
        "stringssplit",
+       "2011-06-28",
        stringssplit,
        `Restore strings.Split to its original meaning and add strings.SplitN. Bytes too.
 
index d90f2b0cc12b72fcdc923d9992184e3104b5e7ba..49aac739b3586ca7e77d92ee6098ad9a55a39f8a 100644 (file)
@@ -6,8 +6,13 @@ package main
 
 import "go/ast"
 
+func init() {
+       register(urlFix)
+}
+
 var urlFix = fix{
        "url",
+       "2011-08-17",
        url,
        `Move the URL pieces of package http into a new package, url.