Skip to content

Commit

Permalink
Revert "[Fix #1044] Prefer call-process to shell-command-to-string (
Browse files Browse the repository at this point in the history
#1045)"

This reverts commit ee5ce8d.
  • Loading branch information
bbatsov committed Oct 4, 2016
1 parent 5ad4275 commit 53fa8c0
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 53 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/elpa
/.elpa
/.cask
*.elc
*~
[#]*[#]
/TAGS
/TAGS
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
* [#1024](https://github.com/bbatsov/projectile/issues/1024): Do not cache ignored project files.
* [#1022](https://github.com/bbatsov/projectile/issues/1022): Scan for Fossil's checkout DB, not its config DB.
* [#1007](https://github.com/bbatsov/projectile/issues/1007): Make use of `projectile-go-function`.
* [#1044](https://github.com/bbatsov/projectile/issues/1044): Replace `shell-command-to-string` invocations with `call-process` invocations where possible to avoid shell startup cost.

## 0.14.0 (2016-07-08)

Expand Down
3 changes: 1 addition & 2 deletions Cask
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@
(development
(depends-on "noflet")
(depends-on "helm")
(depends-on "ag")
(depends-on "el-mock"))
(depends-on "ag"))
33 changes: 6 additions & 27 deletions projectile.el
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@
;;; Code:

(require 'cl-lib)
(require 'thingatpt)
(require 'ibuffer)
(require 'ibuf-ext)
(require 'compile)
(require 'eshell)
(require 'grep)
(require 'ibuf-ext)
(require 'ibuffer)
(require 'thingatpt)

(eval-when-compile
(defvar ag-ignore-list)
Expand Down Expand Up @@ -1076,29 +1075,9 @@ they are excluded from the results of this function."
(when cmd
(projectile-files-via-ext-command cmd))))

(defun projectile-call-process-to-string (program &rest args)
"Invoke the executable PROGRAM with ARGS and return the output as a string."
(with-temp-buffer
(apply 'call-process program nil (current-buffer) nil args)
(buffer-string)))

(defun projectile-shell-command-to-string (command)
"Try to run COMMAND without actually using a shell and return the output.
The function `eshell-search-path' will be used to search the PATH
environment variable for an appropriate executable using the text
occuring before the first space. If no executable is found,
fallback to `shell-command-to-string'."
(cl-destructuring-bind
(the-command . args) (split-string command " ")
(let ((binary-path (eshell-search-path the-command)))
(if binary-path
(apply 'projectile-call-process-to-string binary-path args)
(shell-command-to-string command)))))

(defun projectile-files-via-ext-command (command)
"Get a list of relative file names in the project root by executing COMMAND."
(split-string (projectile-shell-command-to-string command) "\0" t))
(split-string (shell-command-to-string command) "\0" t))

(defun projectile-index-directory (directory patterns progress-reporter)
"Index DIRECTORY taking into account PATTERNS.
Expand Down Expand Up @@ -2867,8 +2846,8 @@ Invokes the command referenced by `projectile-switch-project-action' on switch.
With a prefix ARG invokes `projectile-commander' instead of
`projectile-switch-project-action.'"
(let ((switch-project-action (if arg
'projectile-commander
projectile-switch-project-action)))
'projectile-commander
projectile-switch-project-action)))
(run-hooks 'projectile-before-switch-project-hook)
;; use a temporary buffer to load PROJECT-TO-SWITCH's dir-locals before calling SWITCH-PROJECT-ACTION
(with-temp-buffer
Expand Down
21 changes: 0 additions & 21 deletions test/projectile-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -717,27 +717,6 @@
(should (equal (list (expand-file-name "vendor/client-submodule/" project))
(projectile-get-all-sub-projects project)))))))

(ert-deftest projectile-test-projectile-shell-command-to-string-fallback ()
(let ((command "command arg1 arg2")
(command-path "/path/to/command")
shell-command-args call-process-args)
(noflet ((shell-command-to-string (&rest args)
(setq shell-command-args args))
(call-process (&rest args)
(setq call-process-args args)))
(noflet ((eshell-search-path (_command) nil))
(projectile-shell-command-to-string command)
(should (equal shell-command-args (list command)))
(should (equal call-process-args nil)))
(setq shell-command-args nil
call-process-args nil)
(noflet ((eshell-search-path (_command-name) command-path))
(projectile-shell-command-to-string command)
(should (equal shell-command-args nil))
(should (equal (car call-process-args) command-path))
(should (equal (-slice call-process-args 4)
(cdr (split-string command " "))))))))

;; Local Variables:
;; indent-tabs-mode: nil
;; End:

0 comments on commit 53fa8c0

Please sign in to comment.