{"thread":{"id":"11938","subject":"[PATCH 4/4] git.el: Better handling of subprocess errors.","startedAt":"2008-02-07T12:51:34Z","lastAt":"2008-02-07T12:51:34Z","messageCount":1,"participants":["Alexandre Julliard"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"67788","messageId":"87myqdorop.fsf@wine.dyndns.org","threadId":"11938","inReplyTo":null,"subject":"[PATCH 4/4] git.el: Better handling of subprocess errors.","fromName":"Alexandre Julliard","fromEmail":"julliard@winehq.org","sentAt":"2008-02-07T12:51:34Z","receivedAt":"2008-02-07T12:51:34Z","isPatch":true,"sender":{"key":"julliard@winehq.org","avatar":null},"body":"Where possible, capture the output of the git command and display it\nif the command fails.\n\nSigned-off-by: Alexandre Julliard <julliard@winehq.org>\n---\n contrib/emacs/git.el |   88 +++++++++++++++++++++++++++++---------------------\n 1 files changed, 51 insertions(+), 37 deletions(-)\n\ndiff --git a/contrib/emacs/git.el b/contrib/emacs/git.el\nindex e1058b9..a8bf0ef 100644\n--- a/contrib/emacs/git.el\n+++ b/contrib/emacs/git.el\n@@ -35,7 +35,6 @@\n ;;\n ;; TODO\n ;;  - portability to XEmacs\n-;;  - better handling of subprocess errors\n ;;  - diff against other branch\n ;;  - renaming files from the status buffer\n ;;  - creating tags\n@@ -191,6 +190,18 @@ if there is already one that displays the same directory.\"\n              (append (git-get-env-strings env) (list \"git\") args))\n     (apply #'call-process \"git\" nil buffer nil args)))\n \n+(defun git-call-process-display-error (&rest args)\n+  \"Wrapper for call-process that displays error messages.\"\n+  (let* ((dir default-directory)\n+         (buffer (get-buffer-create \"*Git Command Output*\"))\n+         (ok (with-current-buffer buffer\n+               (let ((default-directory dir)\n+                     (buffer-read-only nil))\n+                 (erase-buffer)\n+                 (eq 0 (apply 'call-process \"git\" nil (list buffer t) nil args))))))\n+    (unless ok (display-message-or-buffer buffer))\n+    ok))\n+\n (defun git-call-process-env-string (env &rest args)\n   \"Wrapper for call-process that sets environment strings,\n and returns the process output as a string.\"\n@@ -377,7 +388,7 @@ and returns the process output as a string.\"\n     (when reason\n      (push reason args)\n      (push \"-m\" args))\n-    (eq 0 (apply #'git-call-process-env nil nil \"update-ref\" args))))\n+    (apply 'git-call-process-display-error \"update-ref\" args)))\n \n (defun git-read-tree (tree &optional index-file)\n   \"Read a tree into the index file.\"\n@@ -866,16 +877,17 @@ Return the list of files that haven't been handled.\"\n                       (if (or (not (string-equal tree head-tree))\n                               (yes-or-no-p \"The tree was not modified, do you really want to perform an empty commit? \"))\n                           (let ((commit (git-commit-tree buffer tree head)))\n-                            (condition-case nil (delete-file \".git/MERGE_HEAD\") (error nil))\n-                            (condition-case nil (delete-file \".git/MERGE_MSG\") (error nil))\n-                            (with-current-buffer buffer (erase-buffer))\n-\t\t\t    (git-update-status-files (git-get-filenames files) 'uptodate)\n-                            (git-call-process-env nil nil \"rerere\")\n-                            (git-call-process-env nil nil \"gc\" \"--auto\")\n-                            (git-refresh-files)\n-                            (git-refresh-ewoc-hf git-status)\n-                            (message \"Committed %s.\" commit)\n-                            (git-run-hook \"post-commit\" nil))\n+                            (when commit\n+                              (condition-case nil (delete-file \".git/MERGE_HEAD\") (error nil))\n+                              (condition-case nil (delete-file \".git/MERGE_MSG\") (error nil))\n+                              (with-current-buffer buffer (erase-buffer))\n+                              (git-update-status-files (git-get-filenames files) 'uptodate)\n+                              (git-call-process-env nil nil \"rerere\")\n+                              (git-call-process-env nil nil \"gc\" \"--auto\")\n+                              (git-refresh-files)\n+                              (git-refresh-ewoc-hf git-status)\n+                              (message \"Committed %s.\" commit)\n+                              (git-run-hook \"post-commit\" nil)))\n                         (message \"Commit aborted.\"))))\n                 (message \"No files to commit.\")))\n           (delete-file index-file))))))\n@@ -986,9 +998,9 @@ Return the list of files that haven't been handled.\"\n     ;; FIXME: add support for directories\n     (unless files\n       (push (file-relative-name (read-file-name \"File to add: \" nil nil t)) files))\n-    (apply #'git-call-process-env nil nil \"update-index\" \"--add\" \"--\" files)\n-    (git-update-status-files files 'uptodate)\n-    (git-success-message \"Added\" files)))\n+    (when (apply 'git-call-process-display-error \"update-index\" \"--add\" \"--\" files)\n+      (git-update-status-files files 'uptodate)\n+      (git-success-message \"Added\" files))))\n \n (defun git-ignore-file ()\n   \"Add marked file(s) to the ignore list.\"\n@@ -1014,9 +1026,9 @@ Return the list of files that haven't been handled.\"\n               (if (file-directory-p name)\n                   (delete-directory name)\n                 (delete-file name))))\n-          (apply #'git-call-process-env nil nil \"update-index\" \"--remove\" \"--\" files)\n-          (git-update-status-files files nil)\n-          (git-success-message \"Removed\" files))\n+          (when (apply 'git-call-process-display-error \"update-index\" \"--remove\" \"--\" files)\n+            (git-update-status-files files nil)\n+            (git-success-message \"Removed\" files)))\n       (message \"Aborting\"))))\n \n (defun git-revert-file ()\n@@ -1034,28 +1046,30 @@ Return the list of files that haven't been handled.\"\n           ('unmerged (push (git-fileinfo->name info) modified))\n           ('modified (push (git-fileinfo->name info) modified))))\n       ;; check if a buffer contains one of the files and isn't saved\n-      (dolist (file (append added modified))\n+      (dolist (file modified)\n         (let ((buffer (get-file-buffer file)))\n           (when (and buffer (buffer-modified-p buffer))\n             (error \"Buffer %s is modified. Please kill or save modified buffers before reverting.\" (buffer-name buffer)))))\n-      (when added\n-        (apply #'git-call-process-env nil nil \"update-index\" \"--force-remove\" \"--\" added))\n-      (when modified\n-        (apply #'git-call-process-env nil nil \"checkout\" \"HEAD\" modified))\n-      (git-update-status-files (append added modified) 'uptodate)\n-      (dolist (file (append added modified))\n-        (let ((buffer (get-file-buffer file)))\n-          (when buffer (with-current-buffer buffer (revert-buffer t t t)))))\n-      (git-success-message \"Reverted\" (git-get-filenames files)))))\n+      (let ((ok (and\n+                 (or (not added)\n+                     (apply 'git-call-process-display-error \"update-index\" \"--force-remove\" \"--\" added))\n+                 (or (not modified)\n+                     (apply 'git-call-process-display-error \"checkout\" \"HEAD\" modified)))))\n+        (git-update-status-files (append added modified) 'uptodate)\n+        (when ok\n+          (dolist (file modified)\n+            (let ((buffer (get-file-buffer file)))\n+              (when buffer (with-current-buffer buffer (revert-buffer t t t)))))\n+          (git-success-message \"Reverted\" (git-get-filenames files)))))))\n \n (defun git-resolve-file ()\n   \"Resolve conflicts in marked file(s).\"\n   (interactive)\n   (let ((files (git-get-filenames (git-marked-files-state 'unmerged))))\n     (when files\n-      (apply #'git-call-process-env nil nil \"update-index\" \"--\" files)\n-      (git-update-status-files files 'uptodate)\n-      (git-success-message \"Resolved\" files))))\n+      (when (apply 'git-call-process-display-error \"update-index\" \"--\" files)\n+        (git-update-status-files files 'uptodate)\n+        (git-success-message \"Resolved\" files)))))\n \n (defun git-remove-handled ()\n   \"Remove handled files from the status list.\"\n@@ -1320,12 +1334,12 @@ amended version of it.\"\n   (when (git-empty-db-p) (error \"No commit to amend.\"))\n   (let* ((commit (git-rev-parse \"HEAD\"))\n          (files (git-get-commit-files commit)))\n-    (git-call-process-env nil nil \"reset\" \"--soft\" \"HEAD^\")\n-    (git-update-status-files (copy-sequence files) 'uptodate)\n-    (git-mark-files git-status files)\n-    (git-refresh-files)\n-    (git-setup-commit-buffer commit)\n-    (git-commit-file)))\n+    (when (git-call-process-display-error \"reset\" \"--soft\" \"HEAD^\")\n+      (git-update-status-files (copy-sequence files) 'uptodate)\n+      (git-mark-files git-status files)\n+      (git-refresh-files)\n+      (git-setup-commit-buffer commit)\n+      (git-commit-file))))\n \n (defun git-find-file ()\n   \"Visit the current file in its own buffer.\"\n-- \n1.5.4.38.g0d380\n\n-- \nAlexandre Julliard\njulliard@winehq.org\n"}]}