Fix errors found during additional testing#30
Open
gwurster wants to merge 1 commit intomeido:masterfrom
Open
Conversation
This patch fixes a number of errors encountered during internal testing: 1. Processing of hunks within a patch file was incorrect. We were starting a new hunk every time we saw a --- or +++, but we should have been looking at the number of lines remaining in the current hunk (which started with a @@) to determine if we were at the end of the hunk. In the rare case where the patch is removing a line that starts with --, or adding a line that starts with ++, you'll have a --- or +++ within the hunk which we were treating as a new hunk even though it should not have been. Now, instead of looking for a +++ or --- on every line, we count the number of lines which should be in the hunk and treat those lines as part of the hunk instead of starting a new hunk. As part of implementing this feature, we renamed the _lineschanged array to the more descriptive _oldStart, _oldLength, _newStart, and _newLength variables. 2. We were not handling hunks which created or removed files correctly. In this case, either the source or target file will appear as /dev/null and we should be able to handle this. 3. On occasion, srcml was hanging which meant that apply.py also hung. Implement a timeout on the external program calls so that we can detect hangs and error out. 4. We do not handle binary patches, but we should be able to detect when they appear and raise an appropriate error. 5. Update the Makefile to automatically install srcml if it's not already installed. The http://gehry.sdml.cs.kent.edu site is unfortunately not available over HTTPS (it's a self-signed certificate and a default Apache testing page) and so for now we are downloading over HTTP. We install it into the env path. 6. Only ask questions about the possible files to apply the patch to if we are running over a TTY. This avoids the questions being asked if the output of apply.py is being piped to a file or another program. Unit tests are added for meido#1, meido#2, and meido#4 above.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This patch fixes a number of errors encountered during internal testing:
Processing of hunks within a patch file was incorrect. We were starting a new hunk every time we saw a --- or +++, but we should have been looking at the number of lines remaining in the current hunk (which started with a @@) to determine if we were at the end of the hunk. In the rare case where the patch is removing a line that starts with --, or adding a line that starts with ++, you'll have a --- or +++ within the hunk which we were treating as a new hunk even though it should not have been. Now, instead of looking for a +++ or --- on every line, we count the number of lines which should be in the hunk and treat those lines as part of the hunk instead of starting a new hunk. As part of implementing this feature, we renamed the _lineschanged array to the more descriptive _oldStart, _oldLength, _newStart, and _newLength variables.
We were not handling hunks which created or removed files correctly. In this case, either the source or target file will appear as /dev/null and we should be able to handle this.
On occasion, srcml was hanging which meant that apply.py also hung. Implement a timeout on the external program calls so that we can detect hangs and error out.
We do not handle binary patches, but we should be able to detect when they appear and raise an appropriate error.
Update the Makefile to automatically install srcml if it's not already installed. The http://gehry.sdml.cs.kent.edu site is unfortunately not available over HTTPS (it's a self-signed certificate and a default Apache testing page) and so for now we are downloading over HTTP. We install it into the env path.
Only ask questions about the possible files to apply the patch to if we are running over a TTY. This avoids the questions being asked if the output of apply.py is being piped to a file or another program.
Unit tests are added for 1, 2, and 4 above.