Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing of editor commandline in git-pr #259

Closed
wants to merge 1 commit into from

Conversation

RealCLanger
Copy link
Contributor

@RealCLanger RealCLanger commented Nov 19, 2019

For git editor configurations that aren't a simple call to an editor but have more parameters, the starting of the editor in git pr does not work.
At least, I observed this in my windows environment, where I have the following git config entry:
core.editor="C:\Program Files\Notepad++\notepad++.exe" -multiInst -notabbar -nosession -noPlugin

Progress

  • Change must not contain extraneous whitespace
  • Change must be properly reviewed

Approvers

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Nov 19, 2019

👋 Welcome back clanger! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request (refresh this page to view it).

@mlbridge
Copy link

@mlbridge mlbridge bot commented Nov 19, 2019

@edvbld
Copy link
Member

@edvbld edvbld commented Nov 20, 2019

Hi Christoph,

thanks for contributing! Just two small nits before I will continue to review this:

  1. Please describe what you changed in this pull request. You did not provide a description in this PR.
  2. One usually do not end PR titles with a ., so please remove that from the title of the PR.

Thanks!
Erik

@RealCLanger RealCLanger changed the title Fix parsing of editor commandline in git-pr. Fix parsing of editor commandline in git-pr Nov 20, 2019
@RealCLanger
Copy link
Contributor Author

@RealCLanger RealCLanger commented Nov 20, 2019

Hi Christoph,

thanks for contributing! Just two small nits before I will continue to review this:

  1. Please describe what you changed in this pull request. You did not provide a description in this PR.
  2. One usually do not end PR titles with a ., so please remove that from the title of the PR.

Thanks!
Erik

Hi Erik,

thanks for pointing out these points. I think I've addressed them.

I created the pull request via the Skara tool call "git pr create". I'm wondering whether there is any documentation about this tool?
E.g. is there an option to give a pull request description? Also, how is one supposed to refer to a JBS bug (if I created one).
Furthermore, git pr has quite a few suboptions. Is there some documentation on what these all are supposed to do?

Thanks
Christoph

@rwestberg
Copy link
Member

@rwestberg rwestberg commented Nov 20, 2019

The cli tools have documentation in man format here: https://github.com/openjdk/skara/tree/master/cli/resources/man/man1 - unfortunately, this documentation isn't complete yet..

Erik knows most about these tools, but I think when you are prompted to enter a description, it should be of the format:

issue number: title
blank line
Longer multiline description

@edvbld
Copy link
Member

@edvbld edvbld commented Nov 20, 2019

Christopher, as Robin says, we unfortunately only have a man page at the moment (which won't help you very much since you are on Windows). You can get more abbreviated help information by running git pr -h. Robin is also right in how you add a longer multiline description to the pull request.

As for the regular expression, could you please add a comments above with a few examples. Also, do you really need the quotation marks around the path to notepad.exe for core.editor? Won't the following suffice:

core.editor = C:\Program Files\Notepad++\notepad++.exe -multiInst -notabbar -nosession -noPlugin

Thanks,
Erik

@edvbld
Copy link
Member

@edvbld edvbld commented Nov 25, 2019

@RealCLanger did you see mine and Robin's comments?

@RealCLanger RealCLanger force-pushed the fix-git-pr2 branch 2 times, most recently from 67cdd0c to 40e03b4 Compare Feb 10, 2020
@RealCLanger
Copy link
Contributor Author

@RealCLanger RealCLanger commented Feb 10, 2020

Hi,

finally I got back to this.

As for the regular expression, could you please add a comments above with a few examples.

I've done that.

Also, do you really need the quotation marks around the path to notepad.exe for core.editor? Won't the following suffice:

core.editor = C:\Program Files\Notepad++\notepad++.exe -multiInst -notabbar -nosession -noPlugin

Probably yes, but that's how I found my git configuration without manual changes that I'm aware of. So it should work. And I think, even if I remove the quotation marks, it still wouldn't work.

Please review :)

@edvbld
Copy link
Member

@edvbld edvbld commented Feb 11, 2020

Thanks Christopher! I agree, if it is possible to have quotation marks around the binary in core.editor, then we should support that. Looking at your patch, what do you think about doing something perhaps a bit simpler than a regular expression:

var parts = editor.split(" ");
if (parts.length > 0) {
    var binary = parts[0];
    // Binary might be wrapped in quotes on Windows
    if (binary.startsWith("\"") && binary.endsWith("\"")) {
        parts[0] = binary.substring(1, binary.length() - 1);
    }
}
var pb = new ProcessBuilder(parts);

@RealCLanger
Copy link
Contributor Author

@RealCLanger RealCLanger commented Feb 11, 2020

Thanks Christopher! I agree, if it is possible to have quotation marks around the binary in core.editor, then we should support that. Looking at your patch, what do you think about doing something perhaps a bit simpler than a regular expression:

var parts = editor.split(" ");
if (parts.length > 0) {
    var binary = parts[0];
    // Binary might be wrapped in quotes on Windows
    if (binary.startsWith("\"") && binary.endsWith("\"")) {
        parts[0] = binary.substring(1, binary.length() - 1);
    }
}
var pb = new ProcessBuilder(parts);

Hm, I agree that something simpler and more explicit than such a regexp would be desirable. But, as for your suggestion, what if the binary path contains blanks? Then it would be distributed along parts[0...n]. Furthermore, the options for the editor could also be quoted items with blanks in it. So, I guess the regexp would handle all that.

@edvbld
Copy link
Member

@edvbld edvbld commented Feb 11, 2020

Ah right, my UNIX brain forgot about paths with spaces in them 😄 Yes, seems like we need the regular expression here. Just a quick question on the last part of the regex, \\s*, will that turn into groups? I wanted to make sure that we execute the editor with all the arguments the user might have added.

Added comment about regex and an example.
Fixed regex to recognize leading whitespace.
@RealCLanger
Copy link
Contributor Author

@RealCLanger RealCLanger commented Feb 11, 2020

Ah right, my UNIX brain forgot about paths with spaces in them 😄 Yes, seems like we need the regular expression here. Just a quick question on the last part of the regex, \\s*, will that turn into groups? I wanted to make sure that we execute the editor with all the arguments the user might have added.

The \s* in the end will not turn into a group. It'll just lead to accepting trailing whitespace. I've tested the regex again in a small testprogram with several variations in input. One thing I've added is a \s* in the beginning to accept leading whitespace - just in case. So the regex basically is:
-optional leading whitespace(non-quoted token|quoted token)optional trailing whitespace-
The group is just formed out of the token.

PR is updated, hopefully the final version :)

Copy link
Member

@rwestberg rwestberg left a comment

Looks good to me! Hopefully we won't need more complex shell lexing than this :) My only concern is that the quotes will remain around the arguments, but I guess that's fine for at least the binary name.

@openjdk
Copy link

@openjdk openjdk bot commented Feb 12, 2020

@RealCLanger This change now passes all automated pre-integration checks. When the change also fulfills all project specific requirements, type /integrate in a new comment to proceed. After integration, the commit message will be:

Fix parsing of editor commandline in git-pr

Reviewed-by: rwestberg
  • If you would like to add a summary, use the /summary command.
  • To credit additional contributors, use the /contributor command.
  • To add additional solved issues, use the /solves command.

Since the source branch of this PR was last updated there have been 3 commits pushed to the master branch. Since there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid automatic rebasing, please merge master into your branch, and then specify the current head hash when integrating, like this: /integrate 4248ba2d279d76c3fb3fee530fc715156cc05473.

As you do not have Committer status in this project, an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@rwestberg) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the ready label Feb 12, 2020
@RealCLanger
Copy link
Contributor Author

@RealCLanger RealCLanger commented Feb 12, 2020

/integrate

@openjdk
Copy link

@openjdk openjdk bot commented Feb 12, 2020

@RealCLanger
Your change (at version fcfba39) is now ready to be sponsored by a Committer.

@openjdk openjdk bot added the sponsor label Feb 12, 2020
@rwestberg
Copy link
Member

@rwestberg rwestberg commented Feb 12, 2020

/sponsor

@openjdk openjdk bot closed this Feb 12, 2020
@openjdk
Copy link

@openjdk openjdk bot commented Feb 12, 2020

@rwestberg @RealCLanger The following commits have been pushed to master since your change was applied:

  • 4248ba2: Improve cooldown test stability
  • 9e9559a: Use different scratch folders for different repos
  • 8a386af: pr-bot: throw on unexpected jcheck issues

Your commit was automatically rebased without conflicts.

Pushed as commit 9b9160b.

@openjdk openjdk bot removed the rfr label Feb 12, 2020
@RealCLanger RealCLanger deleted the fix-git-pr2 branch Feb 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants