From 1e3f94437e05ebd49c93562f491184b9a5677ff0 Mon Sep 17 00:00:00 2001 From: Marius Vollmer Date: Sun, 15 Feb 2009 23:58:10 +0200 Subject: [PATCH] Pass "--no-pager" to Git. * magit.el (magit-git-standard-options): New. Changed almost all uses of magit-git-executable to also pass magit-git-standard-options. --- magit.el | 300 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 155 insertions(+), 145 deletions(-) diff --git a/magit.el b/magit.el index 765eb7f1..c9d56b9c 100644 --- a/magit.el +++ b/magit.el @@ -166,6 +166,8 @@ Many Magit faces inherit from this one by default." "Face for branch head labels shown in log buffer." :group 'magit) +(defconst magit-git-standard-options '("--no-pager")) + ;;; Macros (defmacro magit-with-refresh (&rest body) @@ -186,18 +188,20 @@ Many Magit faces inherit from this one by default." (goto-char 1) (forward-line (1- line)))) -(defun magit-shell (cmd &rest args) - (let ((str (shell-command-to-string - (apply 'format cmd (mapcar #'magit-escape-for-shell args))))) - (if (string= str "") - nil - (if (equal (elt str (- (length str) 1)) ?\n) - (substring str 0 (- (length str) 1)) - str)))) +(defun magit-format-shell-command (fmt args) + (apply 'format fmt (mapcar #'magit-escape-for-shell args))) -(defun magit-shell-lines (cmd &rest args) - (let ((str (shell-command-to-string - (apply 'format cmd (mapcar #'magit-escape-for-shell args))))) +(defun magit-format-git-command (fmt args) + (concat (magit-concat-with-delim + " " + (mapcar #'magit-escape-for-shell + (cons magit-git-executable + magit-git-standard-options))) + " " + (magit-format-shell-command fmt args))) + +(defun magit-shell-lines (command) + (let ((str (shell-command-to-string command))) (if (string= str "") nil (let ((lines (nreverse (split-string str "\n")))) @@ -205,14 +209,28 @@ Many Magit faces inherit from this one by default." (setq lines (cdr lines))) (nreverse lines))))) -(defun magit-shell-exit-code (cmd &rest args) +(defun magit-shell (command) + (let ((str (shell-command-to-string command))) + (if (string= str "") + nil + (if (equal (elt str (- (length str) 1)) ?\n) + (substring str 0 (- (length str) 1)) + str)))) + +(defun magit-git-lines (fmt &rest args) + (magit-shell-lines (magit-format-git-command fmt args))) + +(defun magit-git-string (fmt &rest args) + (magit-shell (magit-format-git-command fmt args))) + +(defun magit-git-exit-code (fmt &rest args) (call-process shell-file-name nil nil nil shell-command-switch - (apply 'format cmd (mapcar #'magit-escape-for-shell args)))) + (magit-format-git-command fmt args))) (defun magit-file-lines (file) (if (file-exists-p file) - (magit-shell-lines "cat %s" file) + (magit-shell-lines (magit-format-shell-command "cat %s" (list file))) nil)) (defun magit-concat-with-delim (delim seqs) @@ -224,31 +242,24 @@ Many Magit faces inherit from this one by default." (concat (car seqs) delim (magit-concat-with-delim delim (cdr seqs)))))) (defun magit-get (&rest keys) - (magit-shell "%s config %s" - magit-git-executable - (magit-concat-with-delim "." keys))) + (magit-git-string "config %s" (magit-concat-with-delim "." keys))) (defun magit-set (val &rest keys) (if val - (magit-shell "%s config %s %s" - magit-git-executable - (magit-concat-with-delim "." keys) val) - (magit-shell "%s config --unset %s" - magit-git-executable - (magit-concat-with-delim "." keys)))) + (magit-git-string "config %s %s" (magit-concat-with-delim "." keys) val) + (magit-git-string "config --unset %s" (magit-concat-with-delim "." keys)))) (defun magit-get-top-dir (cwd) (let ((cwd (expand-file-name cwd))) (and (file-directory-p cwd) - (let ((magit-dir (magit-shell - "cd %s && %s rev-parse --git-dir 2>/dev/null" - cwd magit-git-executable))) + (let* ((default-dir cwd) + (magit-dir (magit-git-string "rev-parse --git-dir 2>/dev/null"))) (and magit-dir (file-name-as-directory (or (file-name-directory magit-dir) cwd))))))) (defun magit-get-ref (ref) - (magit-shell "%s symbolic-ref -q %s" magit-git-executable ref)) + (magit-git-string "symbolic-ref -q %s" ref)) (defun magit-get-current-branch () (let* ((head (magit-get-ref "HEAD")) @@ -264,8 +275,7 @@ Many Magit faces inherit from this one by default." (defun magit-name-rev (rev) (and rev - (let ((name (magit-shell "%s name-rev --name-only %s" - magit-git-executable rev))) + (let ((name (magit-git-string "name-rev --name-only %s" rev))) (if (or (not name) (string= name "undefined")) rev name)))) @@ -278,10 +288,7 @@ Many Magit faces inherit from this one by default." (concat "'" (replace-regexp-in-string "'" "'\\''" str) "'")) (defun magit-format-commit (commit format) - (magit-shell "%s log --max-count=1 --pretty=format:%s %s" - magit-git-executable - format - commit)) + (magit-git-string "log --max-count=1 --pretty=format:%s %s" format commit)) (defun magit-current-line () (buffer-substring-no-properties (line-beginning-position) @@ -299,25 +306,18 @@ Many Magit faces inherit from this one by default." (insert text)))) (defun magit-file-uptodate-p (file) - (eq (magit-shell-exit-code "%s diff --quiet -- %s" - magit-git-executable file) - 0)) + (eq (magit-git-exit-code "diff --quiet -- %s" file) 0)) (defun magit-anything-staged-p () - (not (eq (magit-shell-exit-code "%s diff --quiet --cached" - magit-git-executable) - 0))) + (not (eq (magit-git-exit-code "diff --quiet --cached") 0))) (defun magit-everything-clean-p () (and (not (magit-anything-staged-p)) - (eq (magit-shell-exit-code "%s diff --quiet" - magit-git-executable) - 0))) + (eq (magit-git-exit-code "diff --quiet") 0))) (defun magit-commit-parents (commit) - (cdr (magit-shell-lines "%s rev-list -1 --parents %s | tr ' ' '\n'" - magit-git-executable - commit))) + (cdr (magit-git-lines "rev-list -1 --parents %s | tr ' ' '\n'" + commit))) ;; XXX - let the user choose the parent @@ -336,8 +336,8 @@ Many Magit faces inherit from this one by default." ;;; Revisions and ranges (defun magit-list-interesting-revisions () - (append (magit-shell-lines "%s branch -a | cut -c3-" magit-git-executable) - (magit-shell-lines "%s tag" magit-git-executable))) + (append (magit-git-lines "branch -a | cut -c3-") + (magit-git-lines "tag"))) (defun magit-read-rev (prompt &optional def) (let* ((prompt (if def @@ -552,6 +552,15 @@ Many Magit faces inherit from this one by default." (insert "\n")) section)) +(defun magit-git-section (section-title-and-type + buffer-title washer &rest args) + (apply #'magit-insert-section + section-title-and-type + buffer-title + washer + magit-git-executable + (append magit-git-standard-options args))) + (defun magit-next-section (section) (let ((parent (magit-section-parent section))) (if parent @@ -869,7 +878,7 @@ Many Magit faces inherit from this one by default." "\n") (cond (nowait (setq magit-process - (apply 'start-process magit-git-executable buf cmd args)) + (apply 'start-process cmd buf cmd args)) (set-process-sentinel magit-process 'magit-process-sentinel) (set-process-filter magit-process 'magit-process-filter) (when input @@ -944,20 +953,32 @@ Many Magit faces inherit from this one by default." (defun magit-run-git (&rest args) (magit-with-refresh - (magit-run* (cons magit-git-executable args)))) + (magit-run* (append (cons magit-git-executable + magit-git-standard-options) + args)))) (defun magit-run-with-input (input cmd &rest args) (magit-with-refresh (magit-run* (cons cmd args) nil nil nil nil input))) +(defun magit-run-git-with-input (input &rest args) + (magit-with-refresh + (magit-run* (append (cons magit-git-executable + magit-git-standard-options) + args) + nil nil nil nil input))) + (defun magit-run-shell (fmt &rest args) (let ((cmd (apply #'format fmt (mapcar #'magit-escape-for-shell args)))) (magit-with-refresh (magit-run* (list shell-file-name shell-command-switch cmd) cmd)))) -(defun magit-run-async (cmd &rest args) - (magit-run* (cons cmd args) nil nil nil t)) +(defun magit-run-git-async (&rest args) + (magit-run* (append (cons magit-git-executable + magit-git-standard-options) + args) + nil nil nil t)) (defun magit-run-async-with-input (input cmd &rest args) (magit-run* (cons cmd args) nil nil nil t input)) @@ -1301,10 +1322,9 @@ Please see the manual for a complete description of Magit. (magit-wash-sequence #'magit-wash-untracked-file)) (defun magit-insert-untracked-files () - (magit-insert-section 'untracked "Untracked files:" - 'magit-wash-untracked-files - magit-git-executable - "ls-files" "-t" "--others" "--exclude-standard")) + (magit-git-section 'untracked "Untracked files:" + 'magit-wash-untracked-files + "ls-files" "-t" "--others" "--exclude-standard")) ;;; Diffs and Hunks @@ -1410,8 +1430,8 @@ Please see the manual for a complete description of Magit. (let ((magit-section-hidden-default nil)) (magit-wash-sequence #'magit-wash-hunk)) t))))) - (t - nil))) + (t + nil))) (defun magit-diff-item-kind (diff) (car (magit-section-info diff))) @@ -1535,8 +1555,8 @@ Please see the manual for a complete description of Magit. (magit-insert-hunk-item-region-patch hunk reverse (region-beginning) (region-end) tmp) (magit-insert-hunk-item-patch hunk tmp)) - (apply #'magit-run-with-input tmp - magit-git-executable "apply" (append args (list "-"))))) + (apply #'magit-run-git-with-input tmp + "apply" (append args (list "-"))))) (defun magit-apply-hunk-item (hunk &rest args) (apply #'magit-apply-hunk-item* hunk nil args)) @@ -1546,21 +1566,18 @@ Please see the manual for a complete description of Magit. (defun magit-insert-unstaged-changes (title) (let ((magit-hide-diffs t)) - (magit-insert-section 'unstaged title 'magit-wash-diffs - magit-git-executable "diff" - (magit-diff-U-arg)))) + (magit-git-section 'unstaged title 'magit-wash-diffs + "diff" (magit-diff-U-arg)))) (defun magit-insert-staged-changes (no-commit) (let ((magit-hide-diffs t)) (if no-commit - (let ((null-tree (magit-shell "git mktree