RB Patch
Review Request #3440 — Created Oct. 21, 2012 and submitted
RB Patch will download a patch based off a specific review request ID and apply the patch on the local machine. TODO: - I keep getting an error when post-review'ing my mercurial changes (after a hg commit). http://pastie.org/5455551 which prevents me from fully testing Mercurial, though it should work.
- All testing performed on dev server for controlled experiments. - Tested when user uses a specific revision id (--diff-revision) - Tested when user specifices own pX argument (--px) ** GIT ** Steps performed: 1. Made a new review request (with commit A) 2. Made some changes to local files 3. Git commit those changes (commit B) and updated the request to create a diff (between B and A) 4. On local drive, reverted to commit A 5. Ran 'rb patch <r>' and viewed the results and affected files. I did this for a positive and negative test. ** Mercurial ** Similar to Git. I am assuming there's no need for pX logic here, just like Git's apply patch. ** SVN ** Steps performed: 1. Made a new review request (with commit A) 2. Made some changes to local file(s)* 3. post-review a request to create a diff (between B and A) 4. On local drive, reverted to commit A 5. Ran 'rb patch <r>' and viewed the results and affected files. One or more file changes: - one file change (/trunk/file1.txt) - multiple file changes (/trunk/file1.txt and /trunk/file2.txt) and files in different subdirectories (e.g. /trunk/file1.txt, /trunk/a/file2.txt, /trunk/a/b/file3.txt) Sample directory cases #1: server: /trunk/a/b/c/file.txt local checked out: /../b (I just checked out from /trunk/a/b) patch applied from /b/, /b/c/ <-- all succeeded Sample directory cases #2: server: /trunk/a/b/c/file.txt local checked out: /trunk (I just checked out from /trunk) patch applied from trunk, /trunk/a/, trunk/a/b/, trunk/a/b/c/ <-- all succeeded -- Tested again with new changes made in rb-general branch (removal of extra options).
Description | From | Last Updated |
---|---|---|
Imports should be order like this: Standard Library imports (e.g. os, sys, etc.) ===BLANK LINE=== Third Party imports ===BLANK LINE=== … |
SM smacleod | |
This is imported twice. |
SM smacleod | |
This should be removed when not debugging. |
SM smacleod | |
docstrings should contain a one line summary, followed by a blank line, and then further description. |
SM smacleod | |
You'll want to get rid of these options. The user should be passing the review request id and diff revision … |
SM smacleod | |
You shouldn't need these options for patch. |
SM smacleod | |
This option isn't required. Although, maybe the command should give the option of creating a change list (A different, but … |
SM smacleod | |
This option isn't needed. |
SM smacleod | |
Clear out the options which should be removed, as you remove them. |
SM smacleod | |
This won't be needed for patch. |
SM smacleod | |
This red block means there is trailing whitespace. You should view the diff before publishing and check for these. |
SM smacleod | |
You never initialize self.tool, so this will fail. |
SM smacleod | |
ridorigcwd isn't an option. It looks like you've prepended 'self.options.rid' to the line. Also, this variable (or origcwd) are never … |
SM smacleod | |
The comment explaining why this is set should probably be restored. |
SM smacleod | |
These might be better off factored out, and have server_url passed into the method. |
SM smacleod | |
You don't need this pass here. |
SM smacleod | |
Same thing as my previous comment on docstrings. |
SM smacleod | |
You should consolidate your calls to things like get_review_requests, and git_item. Each of these calls causes a HTTP request to … |
SM smacleod | |
\ isn't needed to continue on the next line when you are inside an open parentheses. |
SM smacleod | |
This return statement is a little cluttered. Could you try and break this out and make it a little more … |
SM smacleod | |
'with' isn't introduced until python 2.5, and we need to support 2.4, so you'll have to change this. Also, rbtools.utils.filesystem … |
SM smacleod | |
You'll want to use rbtools.utils.process.execute here instead of executing the command yourself. for examples, take a look at the ./rbtools/clients/*.py … |
SM smacleod | |
You'll need the tool since you'll be passing the patch to it. The actual code for applying your patch to … |
SM smacleod | |
The patch should be removed, but you'll want to use the temp files stuff I mentioned previously. |
SM smacleod | |
Trailing whitespace. |
SM smacleod | |
Do I have all the ingredients/args to derive the pX number here? |
JS jsintal | |
A more concise way to write this is: p_num = p or self._get_p_number(patch_file) |
|
|
Leftover debug output? |
|
|
This should check the return value, no? |
|
|
Will fix in next submit |
JS jsintal | |
If statements in python don't need parentheses. Also, a good way to check for falsiness is "if not p:" |
|
|
I think a much better way to do this would be to make execute() return the process return code, and … |
|
|
I don't think any of these options are necessary |
|
|
Some trailing whitespace. |
|
|
I'm not sure if get_root should be in the base class (yet), but this should definitely be moved out into … |
|
|
No parentheses needed, and can check using "not" |
|
|
will fix excess space |
JS jsintal | |
Should I make this a helper function?! |
JS jsintal | |
Leftover debug stuff |
|
|
We should definitely delete it, especially in the success case. |
|
|
I made a helper in base class to get cookie, is this okay? |
JS jsintal | |
Alphabetical: import re import sys (I had think about it for a sec to make sure, haha) |
SL slchen | |
Should this and other occurrences of this start on the 1st line: """Returns... ? |
SL slchen | |
r before s. |
|
|
This might look better: diffs = self.root_resource \ .get_review_requests() \ .get_item(request_id) \ .get_diffs() |
|
Change Summary:
rebased with rbdiff, renamed rbdiff.py, more outlining/planning
Diff: |
Revision 2 (+227 -83) |
---|
Change Summary:
- saves file to disk - can delete file - executing patch from os - next: work on pX argument place - next: work on GIT specific application of patching
Diff: |
Revision 4 (+376 -279) |
---|
-
It appears that the 'rb diff' changes were shown in the latest diff. Make sure to use '--parent=rbdiff' when updating the request so the changes are hidden.
-
rbtools/commands/rbpatch.py (Diff revision 4) Imports should be order like this: Standard Library imports (e.g. os, sys, etc.) ===BLANK LINE=== Third Party imports ===BLANK LINE=== Local Imports (e.g. 'rbtools...') Also, imports should be order alphabetically within the three categories.
-
-
-
rbtools/commands/rbpatch.py (Diff revision 4) docstrings should contain a one line summary, followed by a blank line, and then further description.
-
rbtools/commands/rbpatch.py (Diff revision 4) You'll want to get rid of these options. The user should be passing the review request id and diff revision as arguments, not options. Right now the command would be called like this: rb patch -r <request_id> [--diff-revision=<diff_revision>] We want to call the command like this: rb patch <request_id> [<diff_revision>]
-
-
rbtools/commands/rbpatch.py (Diff revision 4) This option isn't required. Although, maybe the command should give the option of creating a change list (A different, but similar option).
-
-
rbtools/commands/rbpatch.py (Diff revision 4) Clear out the options which should be removed, as you remove them.
-
-
rbtools/commands/rbpatch.py (Diff revision 4) This red block means there is trailing whitespace. You should view the diff before publishing and check for these.
-
-
rbtools/commands/rbpatch.py (Diff revision 4) Yeah, I've been trying to decide how I want to handle this.
-
rbtools/commands/rbpatch.py (Diff revision 4) ridorigcwd isn't an option. It looks like you've prepended 'self.options.rid' to the line. Also, this variable (or origcwd) are never referenced again.
-
rbtools/commands/rbpatch.py (Diff revision 4) The comment explaining why this is set should probably be restored.
-
rbtools/commands/rbpatch.py (Diff revision 4) These might be better off factored out, and have server_url passed into the method.
-
-
-
rbtools/commands/rbpatch.py (Diff revision 4) You should consolidate your calls to things like get_review_requests, and git_item. Each of these calls causes a HTTP request to the server, which is just returning the same data in this case.
-
rbtools/commands/rbpatch.py (Diff revision 4) \ isn't needed to continue on the next line when you are inside an open parentheses.
-
rbtools/commands/rbpatch.py (Diff revision 4) This return statement is a little cluttered. Could you try and break this out and make it a little more readable.
-
rbtools/commands/rbpatch.py (Diff revision 4) 'with' isn't introduced until python 2.5, and we need to support 2.4, so you'll have to change this. Also, rbtools.utils.filesystem has functions for creating temporary files etc. You should use those instead of just writing in the working directory.
-
rbtools/commands/rbpatch.py (Diff revision 4) You'll want to use rbtools.utils.process.execute here instead of executing the command yourself. for examples, take a look at the ./rbtools/clients/*.py files.
-
rbtools/commands/rbpatch.py (Diff revision 4) You'll need the tool since you'll be passing the patch to it. The actual code for applying your patch to the tree should live inside the clients. The base class will handle the default of calling out to 'patch', but sub classes can override this and use things such as 'git apply'
-
rbtools/commands/rbpatch.py (Diff revision 4) The patch should be removed, but you'll want to use the temp files stuff I mentioned previously.
-
Change Summary:
Addressed most of Steven's comments from rev 4. Still need to work on pX logic and the actual patching for GIT case. Also, I need to deal with all the superfluous OPTIONS.
Diff: |
Revision 5 (+231 -85) |
---|
Change Summary:
added pX option, considered overriding pX arg with user's option, error checking if diff does not exist
Diff: |
Revision 7 (+255 -83) |
---|
Change Summary:
- execute() works - some testing performed - logic for determining if the git apply went successful
Description: |
|
||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Testing Done: |
|
||||||||||||||||||||||||||||||||||||||||||
Diff: |
Revision 8 (+258 -83) |
-
-
rbtools/clients/__init__.py (Diff revision 8) A more concise way to write this is: p_num = p or self._get_p_number(patch_file)
-
-
-
rbtools/clients/git.py (Diff revision 8) If statements in python don't need parentheses. Also, a good way to check for falsiness is "if not p:"
-
rbtools/clients/git.py (Diff revision 8) I think a much better way to do this would be to make execute() return the process return code, and check if it's non-zero.
-
-
-
rbtools/commands/rbpatch.py (Diff revision 8) I'm not sure if get_root should be in the base class (yet), but this should definitely be moved out into a helper function.
-
-
-
rbtools/commands/rbpatch.py (Diff revision 8) We should definitely delete it, especially in the success case.
Change Summary:
- Addressed most of David's raised issues in his review - Fixed some bugs - Made execute print command and result as a helper function - Informed the user of what patch he's applying (rev id, patch id) - Marked as TODO the various issues that cannot be immediately addressed, such as the options - Minor comment changes here and there.
Diff: |
Revision 9 (+250 -85) |
---|
-
-
rbtools/clients/__init__.py (Diff revisions 8 - 9) Do I have all the ingredients/args to derive the pX number here?
-
-
-
-
rbtools/commands/__init__.py (Diff revision 9) I made a helper in base class to get cookie, is this okay?
Change Summary:
Added pX logic for SVN.
Testing Done: |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Diff: |
Revision 10 (+266 -85) |
Change Summary:
Changes to pX logic to handle mercurial cases.
Description: |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Testing Done: |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Diff: |
Revision 11 (+271 -85) |
Change Summary:
Change pX logic to use webapi, much better and cleaner!
Description: |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Testing Done: |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Diff: |
Revision 12 (+244 -85) |
Change Summary:
Refactored get_server_url(), get_root(), initialize_scm_tool() into base command Minor pep8 style fixes
Diff: |
Revision 14 (+235 -86) |
---|
Change Summary:
Changed the way commands are branched from other features (rb-general). Ex.: http://pastie.org/5468764
Diff: |
Revision 15 (+176 -83) |
---|
Change Summary:
RB Patch has got rid of its unneeded options.
Description: |
|
|||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Diff: |
Revision 16 (+146 -86) |
-
-
rbtools/clients/__init__.py (Diff revision 16) Alphabetical: import re import sys (I had think about it for a sec to make sure, haha)
-
rbtools/clients/__init__.py (Diff revision 16) Should this and other occurrences of this start on the 1st line: """Returns... ?
Change Summary:
import order, svn testing
Description: |
|
|||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Diff: |
Revision 17 (+146 -86) |
Change Summary:
rebased
Testing Done: |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Diff: |
Revision 18 (+139 -83) |
Change Summary:
Rebased on using the gettatr(options, field, default method for ALL
Diff: |
Revision 19 (+139 -83) |
---|
-
This is looking really good - only two nits this time. One more pass, and I think this has my ship-it.
-
-
rbtools/commands/rbpatch.py (Diff revision 19) This might look better: diffs = self.root_resource \ .get_review_requests() \ .get_item(request_id) \ .get_diffs()
Description: |
|
---|