{"thread":{"id":"3673","subject":"[PATCH 1/3] git.el: More robust handling of subprocess errors when returning strings.","startedAt":"2006-03-19T09:05:22Z","lastAt":"2006-03-19T09:05:22Z","messageCount":1,"participants":["Alexandre Julliard"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"17662","messageId":"871wwydctp.fsf@wine.dyndns.org","threadId":"3673","inReplyTo":null,"subject":"[PATCH 1/3] git.el: More robust handling of subprocess errors when returning strings.","fromName":"Alexandre Julliard","fromEmail":"julliard@winehq.org","sentAt":"2006-03-19T09:05:22Z","receivedAt":"2006-03-19T09:05:22Z","isPatch":true,"sender":{"key":"julliard@winehq.org","avatar":null},"body":"Make sure that functions that call a git process and return a string\nalways return nil when the subprocess failed.\n\nSigned-off-by: Alexandre Julliard <julliard@winehq.org>\n\n---\n\n contrib/emacs/git.el |   29 +++++++++++++----------------\n 1 files changed, 13 insertions(+), 16 deletions(-)\n\n66a8d3c3e63a2d4178c9917e0c172bdc2cbec3bb\ndiff --git a/contrib/emacs/git.el b/contrib/emacs/git.el\nindex 5135e36..cf650da 100644\n--- a/contrib/emacs/git.el\n+++ b/contrib/emacs/git.el\n@@ -148,6 +148,12 @@ The default is to fall back to `add-log-\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-env-string (env &rest args)\n+  \"Wrapper for call-process that sets environment strings, and returns the process output as a string.\"\n+  (with-temp-buffer\n+    (and (eq 0 (apply #' git-call-process-env t env args))\n+         (buffer-string))))\n+\n (defun git-run-process-region (buffer start end program args)\n   \"Run a git process with a buffer region as input.\"\n   (let ((output-buffer (current-buffer))\n@@ -189,8 +195,9 @@ The default is to fall back to `add-log-\n \n (defun git-get-string-sha1 (string)\n   \"Read a SHA1 from the specified string.\"\n-  (let ((pos (string-match \"[0-9a-f]\\\\{40\\\\}\" string)))\n-    (and pos (substring string pos (match-end 0)))))\n+  (and string\n+       (string-match \"[0-9a-f]\\\\{40\\\\}\" string)\n+       (match-string 0 string)))\n \n (defun git-get-committer-name ()\n   \"Return the name to use as GIT_COMMITTER_NAME.\"\n@@ -259,18 +266,12 @@ The default is to fall back to `add-log-\n (defun git-rev-parse (rev)\n   \"Parse a revision name and return its SHA1.\"\n   (git-get-string-sha1\n-   (with-output-to-string\n-     (with-current-buffer standard-output\n-       (git-call-process-env t nil \"rev-parse\" rev)))))\n+   (git-call-process-env-string nil \"rev-parse\" rev)))\n \n (defun git-symbolic-ref (ref)\n   \"Wrapper for the git-symbolic-ref command.\"\n-  (car\n-   (split-string\n-    (with-output-to-string\n-      (with-current-buffer standard-output\n-        (git-call-process-env t nil \"symbolic-ref\" ref)))\n-    \"\\n\")))\n+  (let ((str (git-call-process-env-string nil \"symbolic-ref\" ref)))\n+    (and str (car (split-string str \"\\n\")))))\n \n (defun git-update-ref (ref val &optional oldval)\n   \"Update a reference by calling git-update-ref.\"\n@@ -285,11 +286,7 @@ The default is to fall back to `add-log-\n (defun git-write-tree (&optional index-file)\n   \"Call git-write-tree and return the resulting tree SHA1 as a string.\"\n   (git-get-string-sha1\n-   (with-output-to-string\n-     (with-current-buffer standard-output\n-       (git-call-process-env t\n-        (if index-file `((\"GIT_INDEX_FILE\" . ,index-file)) nil)\n-        \"write-tree\")))))\n+   (git-call-process-env-string (and index-file `((\"GIT_INDEX_FILE\" . ,index-file))) \"write-tree\")))\n \n (defun git-commit-tree (buffer tree head)\n   \"Call git-commit-tree with buffer as input and return the resulting commit SHA1.\"\n-- \n1.2.4.g9c5a7\n\n-- \nAlexandre Julliard\njulliard@winehq.org\n"}]}