Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(397)

Issue 153300043: cmd/gomovepkg: a package moving tool.

Can't Edit
Can't Publish+Mail
Start Review
Created:
11 years, 3 months ago by matloob
Modified:
2 hours, 43 minutes ago
Reviewers:
adonovan
Visibility:
Public.

Description

cmd/gomovepkg: a package moving tool. Currently very rough. It has basic functionality for moving a directory and renaming imports to the directory's subpackages.

Patch Set 1 #

Patch Set 2 : diff -r a9cbf58422bba01fd4a6c6db5c95530003e31c3a https://code.google.com/p/go.tools #

Patch Set 3 : diff -r a9cbf58422bba01fd4a6c6db5c95530003e31c3a https://code.google.com/p/go.tools #

Total comments: 40

Patch Set 4 : diff -r a9cbf58422bba01fd4a6c6db5c95530003e31c3a https://code.google.com/p/go.tools #

Patch Set 5 : diff -r a9cbf58422bba01fd4a6c6db5c95530003e31c3a https://code.google.com/p/go.tools #

Patch Set 6 : diff -r a9cbf58422bba01fd4a6c6db5c95530003e31c3a https://code.google.com/p/go.tools #

Total comments: 15
Unified diffs Side-by-side diffs Delta from patch set Stats (+754 lines, -2 lines) Patch
A cmd/gomovepkg/main.go View 1 2 3 1 chunk +28 lines, -0 lines 3 comments Download
M go/buildutil/util.go View 1 2 3 4 1 chunk +11 lines, -1 line 0 comments Download
A refactor/movepkg/movepkg.go View 1 2 3 4 5 1 chunk +406 lines, -0 lines 12 comments Download
A refactor/movepkg/movepkg_test.go View 1 2 3 4 5 1 chunk +308 lines, -0 lines 0 comments Download
M refactor/rename/check.go View 1 1 chunk +1 line, -1 line 0 comments Download

Messages

Total messages: 5
adonovan
Looking good. When you say it "doesn't do anything yet", what do you mean? It ...
11 years, 3 months ago (2014-10-21 21:26:45 UTC) #1
matloob
The "doesn' https://codereview.appspot.com/153300043/diff/40001/cmd/gomovepkg/main.go File cmd/gomovepkg/main.go (right): https://codereview.appspot.com/153300043/diff/40001/cmd/gomovepkg/main.go#newcode6 cmd/gomovepkg/main.go:6: // to the package to point to ...
11 years, 2 months ago (2014-10-23 19:13:43 UTC) #2
matloob
I had just forgotten to update the change description. Responded to some comments, added TODOs ...
11 years, 2 months ago (2014-10-23 19:14:33 UTC) #3
adonovan
Let me know if/when you want me to take another look over it. https://codereview.appspot.com/153300043/diff/40001/cmd/gomovepkg/main.go File ...
11 years, 2 months ago (2014-10-23 19:22:20 UTC) #4
adonovan
11 years, 1 month ago (2014-12-03 20:52:52 UTC) #5
https://codereview.appspot.com/153300043/diff/100001/cmd/gomovepkg/main.go
File cmd/gomovepkg/main.go (right):

https://codereview.appspot.com/153300043/diff/100001/cmd/gomovepkg/main.go#ne...
cmd/gomovepkg/main.go:13: fromFlag = flag.String("from", "", "directory to be
moved")
"Import path of package to be moved"

https://codereview.appspot.com/153300043/diff/100001/cmd/gomovepkg/main.go#ne...
cmd/gomovepkg/main.go:14: toFlag   = flag.String("to", "", "new location for
directory")
"Destination import path for package"

https://codereview.appspot.com/153300043/diff/100001/cmd/gomovepkg/main.go#ne...
cmd/gomovepkg/main.go:25: fmt.Fprintf(os.Stderr, "Error: %s.\n", err)
"gomovepkg: %s.\n"

https://codereview.appspot.com/153300043/diff/100001/refactor/movepkg/movepkg.go
File refactor/movepkg/movepkg.go (right):

https://codereview.appspot.com/153300043/diff/100001/refactor/movepkg/movepkg...
refactor/movepkg/movepkg.go:1: // TODO(matloob): what happens if the package is
moving across version
// Package movepkg moves ...
package movepkg

// TODO(matloob):
// - item1
// - item2
// - item3

This section would be a good place for a general description of the package, its
concepts and algorithm.

https://codereview.appspot.com/153300043/diff/100001/refactor/movepkg/movepkg...
refactor/movepkg/movepkg.go:29: // TODO(matloob): Is this affected by the github
migration?
All of these can now be:

"golang.org/x/tools/go/buildutil"

etc.

You should also do:
 % mv code.google.com/p/go.tools golang.org/x/tools
in your workspace.  You don't need to run any hg commands.

https://codereview.appspot.com/153300043/diff/100001/refactor/movepkg/movepkg...
refactor/movepkg/movepkg.go:36: // anything other than directory already
existing that needs to be checked?
Just a piece of general advice: don't share code for review (no matter how
unfinished you feel the logic is) without first cleaning up the syntax (writing
comments, eliminating cruft, etc).

Remember, the point of review is to get someone else's brain to help analyze the
underlying problem, so make sure the appearance of the code doesn't get in the
way.  It rarely takes long to clean up a piece of code without changing its
behaviour, so long as you understand what it does at this moment.  ("TODO"
comments are fine for things you plan to do later.)

https://codereview.appspot.com/153300043/diff/100001/refactor/movepkg/movepkg...
refactor/movepkg/movepkg.go:48: for _, srcDir := range ctxt.SrcDirs() {
You can avoid calling SrcDirs by using the logic in refactor/importgraph: you
need to know the set of direct dependencies anyway, and you should always design
applications around the minimal number of I/O calls.

https://codereview.appspot.com/153300043/diff/100001/refactor/movepkg/movepkg...
refactor/movepkg/movepkg.go:149: // TODO(matloob): Would it be better to have
the code in move in this
No, this is fine.  You don't have an iprog until now.

https://codereview.appspot.com/153300043/diff/100001/refactor/movepkg/movepkg...
refactor/movepkg/movepkg.go:170: //			pkg/
FYI: "src/pkg" is now just "src", everywhere.

https://codereview.appspot.com/153300043/diff/100001/refactor/movepkg/movepkg...
refactor/movepkg/movepkg.go:178: //  Could pkg and pkg/sub exist in the same
importgraph? If they could, pkg/sub
I would expect that the go/build API operates on the logical, combined
hierarchy, with all contributions from GOROOT, GOPATH[0], ... GOPATH[n-1] taken
into account.  If the implementations don't match that, report a bug.

https://codereview.appspot.com/153300043/diff/100001/refactor/movepkg/movepkg...
refactor/movepkg/movepkg.go:209: // TODO(matloob): figure out how to reuse the
methods from package rename
Copy/paste (with a comment) is always fine as a starting point, but I'm starting
to think that moving at least part of this package into rename is a good idea. 
See below.

https://codereview.appspot.com/153300043/diff/100001/refactor/movepkg/movepkg...
refactor/movepkg/movepkg.go:263: var filesToUpdate = make(map[*ast.File]bool)
filesToUpdate :=

https://codereview.appspot.com/153300043/diff/100001/refactor/movepkg/movepkg...
refactor/movepkg/movepkg.go:264: var importRenames = []importRename{}
var importRenames []importRename

https://codereview.appspot.com/153300043/diff/100001/refactor/movepkg/movepkg...
refactor/movepkg/movepkg.go:266: // rename package name of "from" package
(subpackages are not affected)
// Change the moved package's "package" declaration to its new base name.

https://codereview.appspot.com/153300043/diff/100001/refactor/movepkg/movepkg...
refactor/movepkg/movepkg.go:367: err := rename.Main(m.ctxt, "",
fmt.Sprintf("%s::%s", r.file, r.from), r.to)
The "file::from" notation won't always uniquely match the import spec, so this
could fail spuriously if there's (say) a local var also called 'from'.

Also, it's very inefficient to call rename.Main sequentially for each file since
it reloads all the dependencies.

I recommend that you make this function similar to rename.Main (called it
rename.Imports):

   package rename 

   func Imports(iprog *loader.Program, fromPkg *types.Package, to string) error
{
        for each info in iprog {       
          for each file f in info.Files {
            from := the import spec of 'fromPkg' in file f
            if from == nil, continue
    	    r := renamer{
		iprog:        iprog,
		objsToUpdate: make(map[types.Object]bool),
		to:           to,
		packages:     map[*types.Package]*loader.PackageInfo{info.Pkg: info},
	    }
	    r.check(from)
            if errors, print as warnings and continue
            r.update()
       }
       if any r.update() call failed, return an error
   }

Individual failures should be tolerated: e.g. if a renaming would shadow a
built-in such as len, then we should just skip that file.   Currently your loop
breaks out.
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b