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 #1044] Prefer call-process to shell-command-to-string #1045

Merged
merged 1 commit into from Sep 26, 2016

Conversation

colonelpanic8
Copy link
Contributor

@colonelpanic8 colonelpanic8 commented Aug 16, 2016

This change makes it so that a direct call-process invocation is used
when it is possible to determine what binary should be used for the
command. This avoids the cost of shell startup time that is incurred
when shell-command-to-string is invoked instead.

Fixes #1044

@colonelpanic8 colonelpanic8 force-pushed the avoid_shell_command_to_string branch 2 times, most recently from 99e5797 to bc74472 Compare August 16, 2016 21:37
@bbatsov
Copy link
Owner

bbatsov commented Sep 19, 2016

The tests are failing.

@@ -1058,9 +1059,22 @@ they are excluded from the results of this function."
(let ((cmd (projectile-get-ext-ignored-command)))
(projectile-files-via-ext-command cmd)))

(defun projectile-call-process-to-string (program &rest args)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a docstring here.

(apply 'call-process program nil (current-buffer) nil args)
(buffer-string)))

(defun projectile-shell-command-to-string (command)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a docstring here as well.

(require 'compile)
(require 'dash)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebase on top of the current master - we're no longer using dash.el.

(let ((command "command arg1 arg2")
(command-path "/path/to/command")
shell-command-args call-process-args)
(noflet ((shell-command-to-string (&rest args)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The noflet indentation seems broken. Probably you didn't load noflet before indenting this buffer.

This change makes it so that a direct `call-process` invocation is used
when it is possible to determine what binary should be used for the
command. This avoids the cost of shell startup time that is incurred
when `shell-command-to-string` is invoked instead.
@colonelpanic8
Copy link
Contributor Author

Thanks for the review. Things should be fixed now!

@bbatsov bbatsov merged commit ee5ce8d into bbatsov:master Sep 26, 2016
@bbatsov
Copy link
Owner

bbatsov commented Sep 26, 2016

👍

@bsuh
Copy link

bsuh commented Sep 28, 2016

Been debugging why listing of submodule project files stopped working in projectile-find-file

Executing this (projectile-files-via-ext-command (projectile-get-sub-projects-command))

Gives me this in Messages

("/usr/local/Cellar/git/2.10.0/libexec/git-core/git-submodule: line 336: 'echo: command not found
Stopping at 'Assets'; script returned non-zero status.
")

This MR parses commands naively by splitting via spaces creating an argument list like
("submodule" "--quiet" "foreach" "'echo" "$path'" "|" "tr" "'\\n'" "'\\0'")

@bbatsov
Copy link
Owner

bbatsov commented Sep 29, 2016

File a bug report for this.

On Wednesday, 28 September 2016, Brian Suh notifications@github.com wrote:

Been debugging why listing of submodule project files stopped working in
projectile-find-file

Executing this (projectile-files-via-ext-command
(projectile-get-sub-projects-command))

Gives me this in Messages

("/usr/local/Cellar/git/2.10.0/libexec/git-core/git-submodule: line 336: 'echo: command not found
Stopping at 'Assets'; script returned non-zero status.
")

This MR parses arguments naively by splitting via spaces creating an
argument list like
("submodule" "--quiet" "foreach" "'echo" "$path'" "|" "tr" "'\n'" "'\0'")


You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
#1045 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAGVyqIcwhP7Ef7ORIW_sZCPNDU1HHpHks5qusLrgaJpZM4Jl3yf
.

Best Regards,
Bozhidar Batsov

http://www.batsov.com

@colonelpanic8
Copy link
Contributor Author

This MR parses commands naively by splitting via spaces creating an argument list like
("submodule" "--quiet" "foreach" "'echo" "$path'" "|" "tr" "'\n'" "'\0'")

Yeah makes sense. Actually in this case, it seems that thats not the only issue, since the pipe at the end of this command will likely also fail when passed to call process.

I wasn't really aware that projectile ran commands that actually rely on shell features like this, and the only obvious way to fix this is to revert this change. The other alternative is to make it so that projectile commands are always specified as lists of arguments, but that seems like a much larger change.

@bbatsov
Copy link
Owner

bbatsov commented Sep 29, 2016

Not all commands rely on this behaviour. I guess only a few commands rely on pipes and probably we can rewrite some on them - e.g. they can be a sequence of two commands or some processing can be done in Elisp instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants