diff options
| author | Glenn Morris | 2015-06-12 21:22:00 -0400 |
|---|---|---|
| committer | Glenn Morris | 2015-06-12 21:22:00 -0400 |
| commit | 147c3915a5badb09cc7708fdac30fb57b90a538f (patch) | |
| tree | 5e4432842e6591bdc6437044a011cd26c3a37596 | |
| parent | 351739ba1446446dd4755aac2406c21a93edf63f (diff) | |
| download | emacs-147c3915a5badb09cc7708fdac30fb57b90a538f.tar.gz emacs-147c3915a5badb09cc7708fdac30fb57b90a538f.zip | |
* lisp/version.el (emacs-repository-get-version):
Avoid calling external executable if possible. (Bug#20799)
| -rw-r--r-- | lisp/version.el | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/lisp/version.el b/lisp/version.el index 7b636f32976..5776e6d7b26 100644 --- a/lisp/version.el +++ b/lisp/version.el | |||
| @@ -100,7 +100,7 @@ or if we could not determine the revision.") | |||
| 100 | (define-obsolete-function-alias 'emacs-bzr-get-version | 100 | (define-obsolete-function-alias 'emacs-bzr-get-version |
| 101 | 'emacs-repository-get-version "24.4") | 101 | 'emacs-repository-get-version "24.4") |
| 102 | 102 | ||
| 103 | (defun emacs-repository-get-version (&optional dir external) | 103 | (defun emacs-repository-get-version (&optional dir _unused) |
| 104 | "Try to return as a string the repository revision of the Emacs sources. | 104 | "Try to return as a string the repository revision of the Emacs sources. |
| 105 | The format of the returned string is dependent on the VCS in use. | 105 | The format of the returned string is dependent on the VCS in use. |
| 106 | Value is nil if the sources do not seem to be under version | 106 | Value is nil if the sources do not seem to be under version |
| @@ -108,21 +108,35 @@ control, or if we could not determine the revision. Note that | |||
| 108 | this reports on the current state of the sources, which may not | 108 | this reports on the current state of the sources, which may not |
| 109 | correspond to the running Emacs. | 109 | correspond to the running Emacs. |
| 110 | 110 | ||
| 111 | Optional argument DIR is a directory to use instead of | 111 | Optional argument DIR is a directory to use instead of `source-directory'." |
| 112 | `source-directory'. Optional argument EXTERNAL is ignored and is | ||
| 113 | retained for compatibility." | ||
| 114 | (or dir (setq dir source-directory)) | 112 | (or dir (setq dir source-directory)) |
| 115 | (cond ((file-directory-p (expand-file-name ".git" dir)) | 113 | (let ((file (expand-file-name ".git/HEAD" dir))) |
| 116 | (message "Waiting for git...") | 114 | (or (if (file-readable-p file) |
| 117 | (with-temp-buffer | 115 | (with-temp-buffer |
| 118 | (let ((default-directory (file-name-as-directory dir))) | 116 | (insert-file-contents file) |
| 119 | (and (eq 0 | 117 | (cond ((looking-at "[0-9a-fA-F]\\{40\\}") |
| 120 | (condition-case nil | 118 | (match-string 0)) |
| 121 | (call-process "git" nil '(t nil) nil "rev-parse" | 119 | ((looking-at "ref: \\(.*\\)") |
| 122 | "HEAD") | 120 | (when (file-readable-p |
| 123 | (error nil))) | 121 | (setq file |
| 124 | (not (zerop (buffer-size))) | 122 | (expand-file-name (format ".git/%s" |
| 125 | (replace-regexp-in-string "\n" "" (buffer-string)))))))) | 123 | (match-string 1)) |
| 124 | dir))) | ||
| 125 | (erase-buffer) | ||
| 126 | (insert-file-contents file) | ||
| 127 | (if (looking-at "[0-9a-fA-F]\\{40\\}") | ||
| 128 | (match-string 0))))))) | ||
| 129 | (when (file-accessible-directory-p (expand-file-name ".git" dir)) | ||
| 130 | (message "Waiting for git...") | ||
| 131 | (with-temp-buffer | ||
| 132 | (let ((default-directory (file-name-as-directory dir))) | ||
| 133 | (and (eq 0 | ||
| 134 | (condition-case nil | ||
| 135 | (call-process "git" nil '(t nil) nil "rev-parse" | ||
| 136 | "HEAD") | ||
| 137 | (error nil))) | ||
| 138 | (not (zerop (buffer-size))) | ||
| 139 | (replace-regexp-in-string "\n" "" (buffer-string))))))))) | ||
| 126 | 140 | ||
| 127 | ;; We put version info into the executable in the form that `ident' uses. | 141 | ;; We put version info into the executable in the form that `ident' uses. |
| 128 | (purecopy (concat "\n$Id: " (subst-char-in-string ?\n ?\s (emacs-version)) | 142 | (purecopy (concat "\n$Id: " (subst-char-in-string ?\n ?\s (emacs-version)) |