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) |
david | |
Leftover debug output? |
david | |
This should check the return value, no? |
david | |
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:" |
david | |
I think a much better way to do this would be to make execute() return the process return code, and … |
david | |
I don't think any of these options are necessary |
david | |
Some trailing whitespace. |
david | |
I'm not sure if get_root should be in the base class (yet), but this should definitely be moved out into … |
david | |
No parentheses needed, and can check using "not" |
david | |
will fix excess space |
JS jsintal | |
Should I make this a helper function?! |
JS jsintal | |
Leftover debug stuff |
david | |
We should definitely delete it, especially in the success case. |
david | |
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. |
mike_conley | |
This might look better: diffs = self.root_resource \ .get_review_requests() \ .get_item(request_id) \ .get_diffs() |
mike_conley |
- 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
-
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.
-
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.
-
-
-
docstrings should contain a one line summary, followed by a blank line, and then further description.
-
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>]
-
-
This option isn't required. Although, maybe the command should give the option of creating a change list (A different, but similar option).
-
-
-
-
This red block means there is trailing whitespace. You should view the diff before publishing and check for these.
-
-
-
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.
-
-
-
-
-
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.
-
-
This return statement is a little cluttered. Could you try and break this out and make it a little more readable.
-
'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.
-
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.
-
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'
-
-
- 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.
- Change Summary:
-
added pX option, considered overriding pX arg with user's option, error checking if diff does not exist
- Change Summary:
-
- execute() works - some testing performed - logic for determining if the git apply went successful
- Description:
-
[WIP]
RB Patch will download a patch based off a specific review request ID and apply the patch on the local machine.
+ + TODO
+ - Figure out pX logic + - Test with SVN and Perforce/Mercurial? + - Unit testing + - Refactor code (need to talk to Steven about this) + - Get rid of superfluous options - Testing Done:
-
+ - All testing performed on dev server for controlled experiments.
+ + 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.
+ + - TODO: Test with SVN, and Perforce/Mercurial?
+ - TODO: Unit test pX argument if possible
-
-
-
-
-
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 check if it's non-zero.
-
-
-
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.
-
-
-
- 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.
- Change Summary:
-
Added pX logic for SVN.
- Testing Done:
-
- All testing performed on dev server for controlled experiments.
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.
~ - TODO: Test with SVN, and Perforce/Mercurial?
~ - TODO: Unit test pX argument if possible
~ 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 + + + + + + - TODO: Test with other clients, unit testing if time permits?
- Change Summary:
-
Changes to pX logic to handle mercurial cases.
- Description:
-
- [WIP]
- RB Patch will download a patch based off a specific review request ID and apply the patch on the local machine.
~ TODO
~ - Figure out pX logic ~ - Test with SVN and Perforce/Mercurial? ~ - Unit testing ~ - Refactor code (need to talk to Steven about this) ~ - Get rid of superfluous options ~ No longer WIP, should work for SVN, Git, and Mercurial.
~ ~ TODO:
~ - Unit testing of '_get_p_number()' ~ - Get rid of superfluous options (PUNT by Conley) ~ - Get rid of parsing 'Index :' in SVN files. If anyone can give me a hand on getting the 'basedir' via the webapi, that would be greatly appreciated. Right now, I parse SVN files to get this, but I'd like to use the webapi. I recall I need to add a field to some DiffResource, but I have no idea what 'field' and how. I've tried consulting the webapi documentation and that did not solidify what I needed and how. + - I keep getting an error when post-review'ing my mercurial changes (after a hg commit). http://pastie.org/5455551 - Testing Done:
-
- All testing performed on dev server for controlled experiments.
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 - - - - - - - TODO: Test with other clients, unit testing if time permits?
- Change Summary:
-
Change pX logic to use webapi, much better and cleaner!
- Description:
-
RB Patch will download a patch based off a specific review request ID and apply the patch on the local machine.
No longer WIP, should work for SVN, Git, and Mercurial.
+ + TODO:
~ - Unit testing of '_get_p_number()' ~ - Get rid of superfluous options (PUNT by Conley) ~ - Get rid of parsing 'Index :' in SVN files. If anyone can give me a hand on getting the 'basedir' via the webapi, that would be greatly appreciated. Right now, I parse SVN files to get this, but I'd like to use the webapi. I recall I need to add a field to some DiffResource, but I have no idea what 'field' and how. I've tried consulting the webapi documentation and that did not solidify what I needed and how. ~ - 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. ~ - Unit testing necessary? ~ - Get rid of superfluous options - - I keep getting an error when post-review'ing my mercurial changes (after a hg commit). http://pastie.org/5455551 - Testing Done:
-
~ - All testing performed on dev server for controlled experiments.
~ -
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
- Change Summary:
-
Refactored get_server_url(), get_root(), initialize_scm_tool() into base command Minor pep8 style fixes
- Change Summary:
-
Changed the way commands are branched from other features (rb-general). Ex.: http://pastie.org/5468764
- Change Summary:
-
RB Patch has got rid of its unneeded options.
- Description:
-
RB Patch will download a patch based off a specific review request ID and apply the patch on the local machine.
No longer WIP, should work for SVN, Git, and Mercurial.
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. - Unit testing necessary? ~ - Get rid of superfluous options ~ - Test changes on SVN client w/ regards to removing its extra options (only git has been tested)
- Change Summary:
-
import order, svn testing
- Description:
-
RB Patch will download a patch based off a specific review request ID and apply the patch on the local machine.
No longer WIP, should work for SVN, Git, and Mercurial.
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. ~ - 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. - - Unit testing necessary? - - Test changes on SVN client w/ regards to removing its extra options (only git has been tested)
- Change Summary:
-
rebased
- Testing Done:
-
-
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:
-
RB Patch will download a patch based off a specific review request ID and apply the patch on the local machine.
- No longer WIP, should work for SVN, Git, and Mercurial.
- - - 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.